php-cs-fixer update.
This commit is contained in:
parent
41bba407a9
commit
a3b9a49fec
56 changed files with 355 additions and 318 deletions
.php-cs-fixer.php
bin
src
Annotations
App.phpControllers
Exceptions
BenzineConfigurationException.phpBenzineException.phpDbConfigException.phpDbRuntimeException.phpFilterDecodeException.phpJsonErrorHandler.phpWorkerException.php
Guzzle
Middleware
Models/Traits
Redis
Router
Services
Twig/Extensions
ArrayUniqueTwigExtension.phpArrayValuesTwigExtension.phpFilterAlphanumericOnlyTwigExtension.phpInflectionExtension.phpInstanceOfExtension.phpTransformExtension.phpTransformExtensionException.php
Workers
tests
|
@ -41,17 +41,35 @@ return (new PhpCsFixer\Config)
|
|||
->setRiskyAllowed(true)
|
||||
->setHideProgress(false)
|
||||
->setRules([
|
||||
'@PSR2' => true,
|
||||
'strict_param' => true,
|
||||
'array_syntax' => ['syntax' => 'short'],
|
||||
'@PhpCsFixer' => true,
|
||||
'@PHP73Migration' => true,
|
||||
'no_php4_constructor' => true,
|
||||
'no_unused_imports' => true,
|
||||
'no_useless_else' => true,
|
||||
'no_superfluous_phpdoc_tags' => false,
|
||||
'void_return' => true,
|
||||
'yoda_style' => false,
|
||||
// '@PhpCsFixer:risky' => true,
|
||||
'@PHP82Migration' => true,
|
||||
'@PHP80Migration:risky' => true,
|
||||
'@PSR12' => true,
|
||||
'@PSR12:risky' => true,
|
||||
'@PHPUnit100Migration:risky' => true,
|
||||
|
||||
'binary_operator_spaces' => [
|
||||
'default' => 'align_single_space_minimal',
|
||||
'operators' => [
|
||||
'=' => 'align_single_space',
|
||||
'=>' => 'align_single_space',
|
||||
],
|
||||
],
|
||||
'types_spaces' => [
|
||||
'space' => 'single',
|
||||
'space_multiple_catch' => 'single',
|
||||
],
|
||||
|
||||
// Annoyance-fixers:
|
||||
'concat_space' => ['spacing' => 'one'], // This one is a matter of taste.
|
||||
'no_superfluous_phpdoc_tags' => [
|
||||
'allow_mixed' => false,
|
||||
'allow_unused_params' => false,
|
||||
'remove_inheritdoc' => true,
|
||||
],
|
||||
'yoda_style' => false, // Disabled as its annoying. Comes with @PhpCsFixer
|
||||
'native_function_invocation' => false, // Disabled as adding count($i) -> \count($i) is annoying, but supposedly more performant
|
||||
])
|
||||
->setFinder($finder)
|
||||
;
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
function detectAndLoadVendor($path = __DIR__): void
|
||||
{
|
||||
$path = realpath($path);
|
||||
|
|
|
@ -8,7 +8,6 @@ use Doctrine\Common\Annotations\Annotation\Required;
|
|||
|
||||
/**
|
||||
* @Annotation
|
||||
*
|
||||
* @Target("METHOD")
|
||||
*/
|
||||
class JsonSchema
|
||||
|
|
|
@ -8,12 +8,10 @@ use Doctrine\Common\Annotations\Annotation\Required;
|
|||
|
||||
/**
|
||||
* @Annotation
|
||||
*
|
||||
* @Target("METHOD")
|
||||
*/
|
||||
class Route
|
||||
{
|
||||
/** @var array */
|
||||
public array $methods = ['GET'];
|
||||
|
||||
/**
|
||||
|
@ -21,12 +19,9 @@ class Route
|
|||
*/
|
||||
public string $path;
|
||||
|
||||
/** @var string */
|
||||
public string $access = \Benzine\Router\Route::ACCESS_PUBLIC;
|
||||
|
||||
/** @var int */
|
||||
public int $weight = 100;
|
||||
|
||||
/** @var array */
|
||||
public array $domains = [];
|
||||
}
|
||||
|
|
47
src/App.php
47
src/App.php
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Benzine;
|
||||
|
||||
use Benzine\Middleware\JsonResponseExecTimeMiddleware;
|
||||
|
@ -31,7 +33,10 @@ use DebugBar\DebugBar;
|
|||
use DI\Container;
|
||||
use DI\ContainerBuilder;
|
||||
use Faker\Factory as FakerFactory;
|
||||
use Faker\Generator;
|
||||
use Faker\Provider;
|
||||
use Kint\Twig\TwigExtension;
|
||||
use Middlewares\ContentLength;
|
||||
use Middlewares\TrailingSlash;
|
||||
use Monolog\Formatter\LineFormatter;
|
||||
use Monolog\Handler\StreamHandler;
|
||||
|
@ -57,7 +62,7 @@ class App
|
|||
|
||||
protected EnvironmentService $environmentService;
|
||||
protected ConfigurationService $configurationService;
|
||||
protected \Slim\App $app;
|
||||
protected Slim\App $app;
|
||||
protected Logger $logger;
|
||||
protected DebugBar $debugBar;
|
||||
protected Router $router;
|
||||
|
@ -74,10 +79,6 @@ class App
|
|||
|
||||
public function __construct()
|
||||
{
|
||||
if (!ini_get('auto_detect_line_endings')) {
|
||||
ini_set('auto_detect_line_endings', '1');
|
||||
}
|
||||
|
||||
// Configure Dependency Injector
|
||||
$container = $this->setupContainer();
|
||||
$this->logger = $container->get(Logger::class);
|
||||
|
@ -132,19 +133,11 @@ class App
|
|||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getViewPaths(): array
|
||||
{
|
||||
return $this->viewPaths;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $viewPaths
|
||||
*
|
||||
* @return App
|
||||
*/
|
||||
public function setViewPaths(array $viewPaths): App
|
||||
{
|
||||
$this->viewPaths = $viewPaths;
|
||||
|
@ -152,19 +145,11 @@ class App
|
|||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getLogPath(): string
|
||||
{
|
||||
return $this->logPath;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $logPath
|
||||
*
|
||||
* @return App
|
||||
*/
|
||||
public function setLogPath(string $logPath): App
|
||||
{
|
||||
$this->logPath = $logPath;
|
||||
|
@ -215,7 +200,7 @@ class App
|
|||
|
||||
if (!(new Filesystem())->exists($twigCachePath)) {
|
||||
try {
|
||||
(new Filesystem())->mkdir($twigCachePath, 0777);
|
||||
(new Filesystem())->mkdir($twigCachePath, 0o777);
|
||||
} catch (IOException $IOException) {
|
||||
unset($twigSettings['cache']);
|
||||
if (!in_array(PHP_SAPI, ['cli', 'phpdbg'], true)) {
|
||||
|
@ -245,7 +230,7 @@ class App
|
|||
$twig->addExtension(new Twig\Extension\DebugExtension());
|
||||
|
||||
// Add Twig extension to integrate Kint
|
||||
$twig->addExtension(new \Kint\Twig\TwigExtension());
|
||||
$twig->addExtension(new TwigExtension());
|
||||
|
||||
// Add Twig extension to check if something is an instance of a known class or entity
|
||||
$twig->addExtension(new Extensions\InstanceOfExtension());
|
||||
|
@ -267,9 +252,7 @@ class App
|
|||
});
|
||||
|
||||
// This is required as some plugins for Slim expect there to be a twig available as "view"
|
||||
$container->set('view', function (Slim\Views\Twig $twig) {
|
||||
return $twig;
|
||||
});
|
||||
$container->set('view', fn (Slim\Views\Twig $twig) => $twig);
|
||||
|
||||
$container->set(Translation\Translator::class, function (SessionService $sessionService) {
|
||||
$selectedLanguage = $sessionService->has('Language') ? $sessionService->get('Language') : 'en_US';
|
||||
|
@ -298,7 +281,7 @@ class App
|
|||
);
|
||||
});
|
||||
|
||||
$container->set(\Faker\Generator::class, function () {
|
||||
$container->set(Generator::class, function () {
|
||||
$faker = FakerFactory::create();
|
||||
$faker->addProvider(new Provider\Base($faker));
|
||||
$faker->addProvider(new Provider\DateTime($faker));
|
||||
|
@ -392,9 +375,7 @@ class App
|
|||
);
|
||||
});
|
||||
|
||||
$container->set(TrailingSlash::class, function () {
|
||||
return (new TrailingSlash())->redirect();
|
||||
});
|
||||
$container->set(TrailingSlash::class, fn () => (new TrailingSlash())->redirect());
|
||||
|
||||
$container->set(DebugBar::class, function (Logger $logger) {
|
||||
return (new DebugBar())
|
||||
|
@ -414,7 +395,7 @@ class App
|
|||
);
|
||||
});
|
||||
|
||||
$this->environmentService = $container->get(Services\EnvironmentService::class);
|
||||
$this->environmentService = $container->get(EnvironmentService::class);
|
||||
if ($this->environmentService->has('TIMEZONE')) {
|
||||
date_default_timezone_set($this->environmentService->get('TIMEZONE'));
|
||||
} elseif ((new Filesystem())->exists('/etc/timezone')) {
|
||||
|
@ -434,11 +415,11 @@ class App
|
|||
// Middlewares
|
||||
$this->app->addBodyParsingMiddleware();
|
||||
// $this->app->add($container->get(\Middlewares\Geolocation::class));
|
||||
$this->app->add($container->get(\Middlewares\TrailingSlash::class));
|
||||
$this->app->add($container->get(TrailingSlash::class));
|
||||
// $this->app->add($container->get(\Middlewares\Whoops::class));
|
||||
// $this->app->add($container->get(\Middlewares\Minifier::class));
|
||||
// $this->app->add($container->get(\Middlewares\GzipEncoder::class));
|
||||
$this->app->add($container->get(\Middlewares\ContentLength::class));
|
||||
$this->app->add($container->get(ContentLength::class));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Benzine\Controllers;
|
||||
|
||||
use Benzine\Controllers\Filters\Filter;
|
||||
|
@ -17,8 +19,7 @@ abstract class AbstractController
|
|||
public function __construct(
|
||||
protected Logger $logger,
|
||||
protected CacheProvider $cacheProvider
|
||||
) {
|
||||
}
|
||||
) {}
|
||||
|
||||
public function xmlResponse(\SimpleXMLElement $root, Request $request, Response $response): Response
|
||||
{
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Benzine\Controllers;
|
||||
|
||||
use Benzine\ORM\Interfaces\ModelInterface;
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Benzine\Controllers;
|
||||
|
||||
use DebugBar\DebugBar;
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Benzine\Controllers\Filters;
|
||||
|
||||
use Benzine\Exceptions\FilterDecodeException;
|
||||
|
@ -20,8 +22,6 @@ class Filter
|
|||
|
||||
/**
|
||||
* @throws FilterDecodeException
|
||||
*
|
||||
* @return Filter
|
||||
*/
|
||||
public function setOrderDirection(string $orderDirection): self
|
||||
{
|
||||
|
@ -34,8 +34,6 @@ class Filter
|
|||
}
|
||||
|
||||
/**
|
||||
* @param $header
|
||||
*
|
||||
* @throws FilterDecodeException
|
||||
*/
|
||||
public function parseFromHeader($header): self
|
||||
|
@ -75,11 +73,6 @@ class Filter
|
|||
return $this->limit;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $limit
|
||||
*
|
||||
* @return Filter
|
||||
*/
|
||||
public function setLimit($limit): self
|
||||
{
|
||||
$this->limit = $limit;
|
||||
|
@ -92,11 +85,6 @@ class Filter
|
|||
return $this->offset;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $offset
|
||||
*
|
||||
* @return Filter
|
||||
*/
|
||||
public function setOffset($offset): self
|
||||
{
|
||||
$this->offset = $offset;
|
||||
|
@ -109,11 +97,6 @@ class Filter
|
|||
return $this->wheres;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $wheres
|
||||
*
|
||||
* @return Filter
|
||||
*/
|
||||
public function setWheres($wheres): self
|
||||
{
|
||||
$this->wheres = $wheres;
|
||||
|
@ -126,11 +109,6 @@ class Filter
|
|||
return $this->order;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $order
|
||||
*
|
||||
* @return Filter
|
||||
*/
|
||||
public function setOrder($order): self
|
||||
{
|
||||
$this->order = $order;
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Benzine\Controllers\Filters;
|
||||
|
||||
class FilterCondition
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Benzine\Exceptions;
|
||||
|
||||
class BenzineConfigurationException extends BenzineException
|
||||
{
|
||||
}
|
||||
class BenzineConfigurationException extends BenzineException {}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Benzine\Exceptions;
|
||||
|
||||
class BenzineException extends \Exception
|
||||
{
|
||||
}
|
||||
class BenzineException extends \Exception {}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Benzine\Exceptions;
|
||||
|
||||
class DbConfigException extends BenzineException
|
||||
{
|
||||
}
|
||||
class DbConfigException extends BenzineException {}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Benzine\Exceptions;
|
||||
|
||||
class DbRuntimeException extends BenzineException
|
||||
{
|
||||
}
|
||||
class DbRuntimeException extends BenzineException {}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Benzine\Exceptions;
|
||||
|
||||
class FilterDecodeException extends BenzineException
|
||||
{
|
||||
}
|
||||
class FilterDecodeException extends BenzineException {}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Benzine\Exceptions;
|
||||
|
||||
use Slim\Interfaces\ErrorRendererInterface;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Benzine\Exceptions;
|
||||
|
||||
class WorkerException extends BenzineException
|
||||
{
|
||||
}
|
||||
class WorkerException extends BenzineException {}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Benzine\Guzzle;
|
||||
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
|
@ -9,8 +11,7 @@ class JsonResponse implements ResponseInterface
|
|||
{
|
||||
public function __construct(
|
||||
protected ResponseInterface $response
|
||||
) {
|
||||
}
|
||||
) {}
|
||||
|
||||
public function json()
|
||||
{
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Benzine\Middleware;
|
||||
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Benzine\Middleware;
|
||||
|
||||
use Benzine\Annotations\JsonSchema;
|
||||
|
@ -49,6 +51,7 @@ class JsonValidationMiddleware implements MiddlewareInterface
|
|||
try {
|
||||
// Validate it...
|
||||
$schema->in(json_decode($request->getBody()->getContents()));
|
||||
|
||||
// And if we get here, we're golden.
|
||||
return $handler->handle($request);
|
||||
} catch (Exception $exception) {
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Benzine\Models\Traits;
|
||||
|
||||
use Carbon\Carbon;
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Benzine\Redis\Lua;
|
||||
|
||||
use Benzine\Redis\Redis;
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Benzine\Redis\Lua;
|
||||
|
||||
class SetIfHigher extends AbstractLuaExtension
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Benzine\Redis\Lua;
|
||||
|
||||
class SetIfLower extends AbstractLuaExtension
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Benzine\Redis\Lua;
|
||||
|
||||
class ZAddIfHigher extends AbstractLuaExtension
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Benzine\Redis\Lua;
|
||||
|
||||
class ZAddIfLower extends AbstractLuaExtension
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Benzine\Redis;
|
||||
|
||||
use Monolog\Logger;
|
||||
|
@ -230,7 +232,7 @@ class Redis
|
|||
/** @var Lua\AbstractLuaExtension[] */
|
||||
private array $scripts;
|
||||
|
||||
public function __construct(Logger $logger, string $host, int $port = 6379, string $password = null, float $timeout = 0.0)
|
||||
public function __construct(Logger $logger, string $host, int $port = 6379, ?string $password = null, float $timeout = 0.0)
|
||||
{
|
||||
$this->logger = $logger;
|
||||
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Benzine\Router;
|
||||
|
||||
use Slim\App;
|
||||
|
@ -49,7 +51,6 @@ class Route
|
|||
}
|
||||
|
||||
/**
|
||||
* @param $name
|
||||
* @param null $default
|
||||
*
|
||||
* @return $this
|
||||
|
@ -109,8 +110,6 @@ class Route
|
|||
}
|
||||
|
||||
/**
|
||||
* @param mixed $propertyOptions
|
||||
*
|
||||
* @return Route
|
||||
*/
|
||||
public function setPropertyOptions($propertyOptions)
|
||||
|
@ -322,8 +321,6 @@ class Route
|
|||
}
|
||||
|
||||
/**
|
||||
* @param mixed $exampleEntity
|
||||
*
|
||||
* @return Route
|
||||
*/
|
||||
public function setExampleEntity($exampleEntity)
|
||||
|
@ -339,8 +336,6 @@ class Route
|
|||
}
|
||||
|
||||
/**
|
||||
* @param mixed $exampleEntityFinderFunction
|
||||
*
|
||||
* @return Route
|
||||
*/
|
||||
public function setExampleEntityFinderFunction($exampleEntityFinderFunction)
|
||||
|
@ -389,7 +384,7 @@ class Route
|
|||
return count($this->validDomains) > 0;
|
||||
}
|
||||
|
||||
public function isInContainedInValidDomains(string $host = null): bool
|
||||
public function isInContainedInValidDomains(?string $host = null): bool
|
||||
{
|
||||
if (null === $host) {
|
||||
return false;
|
||||
|
@ -413,7 +408,7 @@ class Route
|
|||
|
||||
private function prefixArgumentKey(string $key)
|
||||
{
|
||||
if (0 !== strpos($key, '_')) {
|
||||
if (!str_starts_with($key, '_')) {
|
||||
$key = "_{$key}";
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Benzine\Router;
|
||||
|
||||
use Cache\Adapter\Chain\CachePoolChain;
|
||||
|
@ -28,7 +30,7 @@ class Router
|
|||
|
||||
public function loadRoutesFromAnnotations(
|
||||
array $controllerPaths,
|
||||
string $baseNamespace = null
|
||||
?string $baseNamespace = null
|
||||
): void {
|
||||
AnnotationRegistry::registerLoader('class_exists');
|
||||
|
||||
|
@ -101,7 +103,7 @@ class Router
|
|||
}
|
||||
}
|
||||
|
||||
public function populateRoutes(App $app, ServerRequestInterface $request = null): App
|
||||
public function populateRoutes(App $app, ?ServerRequestInterface $request = null): App
|
||||
{
|
||||
if ($this->routesArePopulated) {
|
||||
return $app;
|
||||
|
@ -174,7 +176,7 @@ class Router
|
|||
return $this;
|
||||
}
|
||||
|
||||
protected function weighRoutes(string $host = null): self
|
||||
protected function weighRoutes(?string $host = null): self
|
||||
{
|
||||
$allocatedRoutes = [];
|
||||
if (is_array($this->routes) && count($this->routes) > 0) {
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Benzine\Services;
|
||||
|
||||
use Benzine\App;
|
||||
|
@ -30,7 +32,7 @@ class ConfigurationService
|
|||
{
|
||||
$this->app = $app;
|
||||
$this->environmentService = $environmentService;
|
||||
$this->findConfig();
|
||||
$this->findConfig($this->environmentService->get('BENZINE_CONFIG_PATH', null));
|
||||
$this->setupDefines();
|
||||
}
|
||||
|
||||
|
@ -42,7 +44,7 @@ class ConfigurationService
|
|||
/**
|
||||
* @return null|array|string
|
||||
*/
|
||||
public function get(string $key, string $defaultValue = null)
|
||||
public function get(string $key, ?string $defaultValue = null)
|
||||
{
|
||||
$scope = $this->config;
|
||||
foreach (explode('/', strtolower($key)) as $keyBit) {
|
||||
|
@ -101,7 +103,7 @@ class ConfigurationService
|
|||
/**
|
||||
* Locate .benzine.yml.
|
||||
*/
|
||||
protected function findConfig(string $path = null): bool
|
||||
protected function findConfig(?string $path = null): bool
|
||||
{
|
||||
if (!$path) {
|
||||
$path = getcwd();
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Benzine\Services;
|
||||
|
||||
class EnvironmentService
|
||||
|
@ -24,7 +26,7 @@ class EnvironmentService
|
|||
return $this->environmentVariables;
|
||||
}
|
||||
|
||||
public function get(string $key, string $default = null)
|
||||
public function get(string $key, ?string $default = null)
|
||||
{
|
||||
if (isset($this->environmentVariables[$key])) {
|
||||
return $this->environmentVariables[$key];
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Benzine\Services;
|
||||
|
||||
use Benzine\Redis\Redis;
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Benzine\Services;
|
||||
|
||||
use Benzine\Redis\Redis;
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Benzine\Twig\Extensions;
|
||||
|
||||
use Twig\Extension\AbstractExtension;
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Benzine\Twig\Extensions;
|
||||
|
||||
use Twig\Extension\AbstractExtension;
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Benzine\Twig\Extensions;
|
||||
|
||||
use Twig\Extension\AbstractExtension;
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Benzine\Twig\Extensions;
|
||||
|
||||
use MatthewBaggett\Inflection\Inflect;
|
||||
|
@ -11,12 +13,8 @@ class InflectionExtension extends AbstractExtension
|
|||
public function getFilters()
|
||||
{
|
||||
$filters = [];
|
||||
$filters['pluralize'] = new TwigFilter('pluralize', function (string $word = null): string {
|
||||
return !empty($word) ? Inflect::pluralize($word) : '';
|
||||
});
|
||||
$filters['singularize'] = new TwigFilter('singularize', function (string $word = null): string {
|
||||
return !empty($word) ? Inflect::singularize($word) : '';
|
||||
});
|
||||
$filters['pluralize'] = new TwigFilter('pluralize', fn (?string $word = null): string => !empty($word) ? Inflect::pluralize($word) : '');
|
||||
$filters['singularize'] = new TwigFilter('singularize', fn (?string $word = null): string => !empty($word) ? Inflect::singularize($word) : '');
|
||||
|
||||
return $filters;
|
||||
}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Benzine\Twig\Extensions;
|
||||
|
||||
use Twig\Extension\AbstractExtension;
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Benzine\Twig\Extensions;
|
||||
|
||||
use Camel\CaseTransformer;
|
||||
|
@ -25,9 +27,7 @@ class TransformExtension extends AbstractExtension
|
|||
$name = 'transform_' . strtolower($fromTransformer) . '_to_' . strtolower($toTransformer);
|
||||
$context = $this;
|
||||
$filters[$name] =
|
||||
new TwigFilter($name, function (string $word) use ($context, $fromTransformer, $toTransformer): string {
|
||||
return $context->transform($word, $fromTransformer, $toTransformer);
|
||||
});
|
||||
new TwigFilter($name, fn (string $word): string => $context->transform($word, $fromTransformer, $toTransformer));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Benzine\Twig\Extensions;
|
||||
|
||||
final class TransformExtensionException extends \Exception
|
||||
{
|
||||
}
|
||||
final class TransformExtensionException extends \Exception {}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Benzine\Workers;
|
||||
|
||||
abstract class AbstractForeverLoopWorker extends AbstractWorker implements WorkerInterface
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Benzine\Workers;
|
||||
|
||||
use Benzine\Services\EnvironmentService;
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Benzine\Workers;
|
||||
|
||||
use Benzine\Services\EnvironmentService;
|
||||
|
@ -27,13 +29,8 @@ abstract class AbstractWorker implements WorkerInterface
|
|||
);
|
||||
}
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
}
|
||||
protected function setUp(): void {}
|
||||
|
||||
/**
|
||||
* @param bool $stopOnZero
|
||||
*/
|
||||
public function setStopOnZero(bool $stopOnZero): self
|
||||
{
|
||||
$this->stopOnZero = $stopOnZero;
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Benzine\Workers;
|
||||
|
||||
class ExampleQueueWorker extends AbstractQueueWorker
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Benzine\Workers;
|
||||
|
||||
use Benzine\Redis\Redis;
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Benzine\Workers;
|
||||
|
||||
interface WorkerInterface
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Benzine\Workers;
|
||||
|
||||
use Benzine\Exceptions\WorkerException;
|
||||
|
@ -40,7 +42,7 @@ class WorkerWorkItem implements \Serializable
|
|||
|
||||
public static function Factory(object $object)
|
||||
{
|
||||
$class = get_class($object);
|
||||
$class = $object::class;
|
||||
|
||||
return (new WorkerWorkItem())
|
||||
->setKey($class, $object)
|
||||
|
@ -52,9 +54,6 @@ class WorkerWorkItem implements \Serializable
|
|||
return $this->data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return WorkerWorkItem
|
||||
*/
|
||||
public function setData(array $data): self
|
||||
{
|
||||
$this->data = $data;
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Benzine\Tests;
|
||||
|
||||
use Faker\Factory as FakerFactory;
|
||||
|
@ -55,7 +57,7 @@ abstract class AbstractBaseTestCase extends AbstractTestCase
|
|||
*/
|
||||
public function invokeMethod(&$object, $methodName, array $parameters = [])
|
||||
{
|
||||
$reflection = new \ReflectionClass(get_class($object));
|
||||
$reflection = new \ReflectionClass($object::class);
|
||||
$method = $reflection->getMethod($methodName);
|
||||
$method->setAccessible(true);
|
||||
|
||||
|
@ -64,7 +66,7 @@ abstract class AbstractBaseTestCase extends AbstractTestCase
|
|||
|
||||
public function setProtectedProperty(&$object, $property, $value)
|
||||
{
|
||||
$reflection = new \ReflectionClass(get_class($object));
|
||||
$reflection = new \ReflectionClass($object::class);
|
||||
$prop = $reflection->getProperty($property);
|
||||
$prop->setAccessible(true);
|
||||
|
||||
|
@ -73,7 +75,7 @@ abstract class AbstractBaseTestCase extends AbstractTestCase
|
|||
|
||||
public function getProtectedProperty(&$object, $property)
|
||||
{
|
||||
$reflection = new \ReflectionClass(get_class($object));
|
||||
$reflection = new \ReflectionClass($object::class);
|
||||
$prop = $reflection->getProperty($property);
|
||||
$prop->setAccessible(true);
|
||||
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Benzine\Tests;
|
||||
|
||||
use Benzine\Tests\Traits\AppTestTrait;
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Benzine\Tests;
|
||||
|
||||
use Benzine\App;
|
||||
|
@ -68,7 +70,7 @@ abstract class AbstractSeleniumTestCase extends AbstractBaseTestCase
|
|||
protected function takeScreenshot($name): void
|
||||
{
|
||||
if (!(new Filesystem())->exists(self::$screenshotsDir)) {
|
||||
(new Filesystem())->mkdir(self::$screenshotsDir, 0777);
|
||||
(new Filesystem())->mkdir(self::$screenshotsDir, 0o777);
|
||||
}
|
||||
self::$webDriver->takeScreenshot(self::$screenshotsDir . self::$screenshotIndex . "_{$name}.jpg");
|
||||
++self::$screenshotIndex;
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Benzine\Tests;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Benzine\Tests\Traits;
|
||||
|
||||
use Benzine\App as BenzineApp;
|
||||
|
@ -98,7 +100,7 @@ trait AppTestTrait
|
|||
* @param string|UriInterface $uri The URI
|
||||
* @param null|array $data The json data
|
||||
*/
|
||||
protected function createJsonRequest(string $method, $uri, array $data = null): ServerRequestInterface
|
||||
protected function createJsonRequest(string $method, $uri, ?array $data = null): ServerRequestInterface
|
||||
{
|
||||
$request = $this->createRequest($method, $uri);
|
||||
|
||||
|
@ -116,7 +118,7 @@ trait AppTestTrait
|
|||
* @param string|UriInterface $uri The URI
|
||||
* @param null|array $data The form data
|
||||
*/
|
||||
protected function createFormRequest(string $method, $uri, array $data = null): ServerRequestInterface
|
||||
protected function createFormRequest(string $method, $uri, ?array $data = null): ServerRequestInterface
|
||||
{
|
||||
$request = $this->createRequest($method, $uri);
|
||||
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Benzine\Tests\Traits;
|
||||
|
||||
trait ArrayEquitabilityTrait
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Benzine\Tests\Traits;
|
||||
|
||||
use Slim\Container;
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Benzine\Tests\Traits;
|
||||
|
||||
use Faker\Factory as FakerFactory;
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Benzine\Tests\Traits;
|
||||
|
||||
trait OverrideProtectionTrait
|
||||
|
@ -15,7 +17,7 @@ trait OverrideProtectionTrait
|
|||
*/
|
||||
public function invokeMethod(&$object, $methodName, array $parameters = [])
|
||||
{
|
||||
$reflection = new \ReflectionClass(get_class($object));
|
||||
$reflection = new \ReflectionClass($object::class);
|
||||
$method = $reflection->getMethod($methodName);
|
||||
$method->setAccessible(true);
|
||||
|
||||
|
@ -24,7 +26,7 @@ trait OverrideProtectionTrait
|
|||
|
||||
public function setProtectedProperty(&$object, $property, $value)
|
||||
{
|
||||
$reflection = new \ReflectionClass(get_class($object));
|
||||
$reflection = new \ReflectionClass($object::class);
|
||||
$prop = $reflection->getProperty($property);
|
||||
$prop->setAccessible(true);
|
||||
|
||||
|
@ -33,7 +35,7 @@ trait OverrideProtectionTrait
|
|||
|
||||
public function getProtectedProperty(&$object, $property)
|
||||
{
|
||||
$reflection = new \ReflectionClass(get_class($object));
|
||||
$reflection = new \ReflectionClass($object::class);
|
||||
$prop = $reflection->getProperty($property);
|
||||
$prop->setAccessible(true);
|
||||
|
||||
|
|
Loading…
Reference in a new issue