From 2f4da233c348a5502dac63bd943facccfef9c6ab Mon Sep 17 00:00:00 2001 From: Maxime Elomari <764791+noglitchyo@users.noreply.github.com> Date: Fri, 19 Jul 2019 17:22:35 +0200 Subject: [PATCH] Added copyrights to every files, fixed tests --- composer.json | 4 +-- phpstan.neon | 3 ++ .../Compiler/AddCollectionPass.php | 26 ++++++++++++++- src/DependencyInjection/Configuration.php | 23 +++++++++++++ .../NoGlitchYoMiddlewareExtension.php | 32 ++++++++++++++++++- src/Entity/HandlerCondition.php | 23 +++++++++++++ src/Entity/HandlerConfiguration.php | 23 +++++++++++++ src/Entity/HandlerConfigurationInterface.php | 23 +++++++++++++ src/Entity/MiddlewareStackEntry.php | 23 +++++++++++++ .../MiddlewareStackInjectorListener.php | 24 ++++++++++++++ src/Exception/NotImplementedException.php | 23 +++++++++++++ ...UndefinedMiddlewareCollectionException.php | 23 +++++++++++++ src/Factory/MiddlewareCollectionFactory.php | 23 +++++++++++++ src/HttpKernel/MiddlewareStackKernel.php | 32 ++++++++++++++++--- .../Matcher/ControllerRequestMatcher.php | 23 +++++++++++++ src/Middleware/Matcher/RequestMatcher.php | 29 +++++++++++++++-- .../Matcher/RequestMatcherInterface.php | 23 +++++++++++++ src/Middleware/Stack/MiddlewareStack.php | 23 +++++++++++++ .../Stack/MiddlewareStackInterface.php | 27 ++++++++++++++-- src/MiddlewareStackConfigurator.php | 23 +++++++++++++ src/NoGlitchYoMiddlewareBundle.php | 23 +++++++++++++ 21 files changed, 461 insertions(+), 15 deletions(-) create mode 100644 phpstan.neon diff --git a/composer.json b/composer.json index ae7d285..dcf98d0 100644 --- a/composer.json +++ b/composer.json @@ -46,8 +46,8 @@ } }, "scripts": { - "phpstan": "phpstan analyse -l max ./", - "phpcs": "phpcs --standard=PSR2 ./", + "phpstan": "phpstan analyse -l max src", + "phpcs": "phpcs --standard=PSR2 ./src", "test": "phpunit -c phpunit.xml.dist" }, "require-dev": { diff --git a/phpstan.neon b/phpstan.neon new file mode 100644 index 0000000..5c8ba05 --- /dev/null +++ b/phpstan.neon @@ -0,0 +1,3 @@ +parameters: + excludes_analyse: + - %rootDir%/../../../src/DependencyInjection/Configuration.php diff --git a/src/DependencyInjection/Compiler/AddCollectionPass.php b/src/DependencyInjection/Compiler/AddCollectionPass.php index 8e4ee6b..cf0dd3f 100644 --- a/src/DependencyInjection/Compiler/AddCollectionPass.php +++ b/src/DependencyInjection/Compiler/AddCollectionPass.php @@ -1,4 +1,27 @@ findAndSortTaggedServices(static::COLLECTION_TAG, $container); if (!$collections) { throw new RuntimeException( - 'No middleware collections found. At least one collection is required to be tag with "middlewares.collection".' + 'No middleware collections found. At least one collection is required '. + 'to be tag with "middlewares.collection".' ); } diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php index bba962a..5352932 100644 --- a/src/DependencyInjection/Configuration.php +++ b/src/DependencyInjection/Configuration.php @@ -1,4 +1,27 @@ getConfiguration($configs, $container); + if ($mainConfig === null) { + return; + } + $configuration = $this->processConfiguration($mainConfig, $configs); $loader = new YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config')); @@ -26,7 +53,10 @@ public function load(array $configs, ContainerBuilder $container): void if (!isset($handlerConfiguration['collection'])) { throw new InvalidArgumentException('Please provide a collection for handler'); } - $container->setParameter(sprintf('middlewares.handlers.%s', $handlerName), $handlerConfiguration); + $container->setParameter( + sprintf('middlewares.handlers.%s', $handlerName), + $handlerConfiguration + ); } $container->setParameter('middlewares.handlers', $config); diff --git a/src/Entity/HandlerCondition.php b/src/Entity/HandlerCondition.php index c9d2cc4..e3af6f1 100644 --- a/src/Entity/HandlerCondition.php +++ b/src/Entity/HandlerCondition.php @@ -1,4 +1,27 @@ middlewareStackHandler ->withDefaultHandler($event->getController()) ->compile($event->getRequest()); diff --git a/src/Exception/NotImplementedException.php b/src/Exception/NotImplementedException.php index 45d543a..ff29664 100644 --- a/src/Exception/NotImplementedException.php +++ b/src/Exception/NotImplementedException.php @@ -1,4 +1,27 @@ httpKernel, $this->httpFoundationFactory, $this->psrHttpFactory) implements RequestHandlerInterface + return new class($this->httpKernel, $this->httpFoundationFactory, $this->psrHttpFactory) + implements RequestHandlerInterface { /** * @var HttpKernelInterface */ private $httpKernel; /** - * @var HttpFoundationFactory + * @var HttpFoundationFactoryInterface */ private $foundationFactory; /** - * @var PsrHttpFactory + * @var HttpMessageFactoryInterface */ private $psrHttpFactory; diff --git a/src/Middleware/Matcher/ControllerRequestMatcher.php b/src/Middleware/Matcher/ControllerRequestMatcher.php index 88bdaf2..ab678ac 100644 --- a/src/Middleware/Matcher/ControllerRequestMatcher.php +++ b/src/Middleware/Matcher/ControllerRequestMatcher.php @@ -1,4 +1,27 @@ getCondition()->getRouteName() !== null) { - $isTrue = $isTrue && $routeName === $middlewareStackEntry->getCondition()->getRouteName(); + $isTrue &= $routeName === $middlewareStackEntry->getCondition()->getRouteName(); } if ($middlewareStackEntry->getCondition()->getRoutePath() !== null) { - $isTrue = $isTrue && $routePath === $middlewareStackEntry->getCondition()->getRoutePath(); + $isTrue &= $routePath === $middlewareStackEntry->getCondition()->getRoutePath(); } - return $isTrue; + return (bool)$isTrue; } } diff --git a/src/Middleware/Matcher/RequestMatcherInterface.php b/src/Middleware/Matcher/RequestMatcherInterface.php index 8035dcc..7d0e358 100644 --- a/src/Middleware/Matcher/RequestMatcherInterface.php +++ b/src/Middleware/Matcher/RequestMatcherInterface.php @@ -1,4 +1,27 @@