From dd0146527f0f45e595a10bdefafa2be17b4ff598 Mon Sep 17 00:00:00 2001 From: Andreas Hennings Date: Sat, 11 Jan 2020 23:24:21 +0100 Subject: [PATCH 01/23] (CS) Change indentation from 4 to 2. --- src/Cache/DrupalCache.php | 124 ++--- src/Configuration/Cache.php | 452 ++++++++--------- src/Configuration/ConfigurationAnnotation.php | 16 +- src/Configuration/ConfigurationInterface.php | 24 +- src/Configuration/Method.php | 166 +++--- src/Configuration/ParamConverter.php | 336 ++++++------ src/Configuration/Route.php | 160 +++--- .../RouteModifierClassInterface.php | 12 +- .../RouteModifierMethodInterface.php | 12 +- src/Configuration/Security.php | 474 ++++++++--------- src/Configuration/Template.php | 270 +++++----- src/Configuration/Title.php | 384 +++++++------- .../ControllerEventSubscriber.php | 228 ++++----- .../HttpCacheEventSubscriber.php | 480 +++++++++--------- .../ParamConverterEventSubscriber.php | 224 ++++---- src/EventSubscriber/RouteEventSubscriber.php | 142 +++--- .../TemplateEventSubscriber.php | 334 ++++++------ .../ParamConverter/DateTimeParamConverter.php | 98 ++-- .../ParamConverter/EntityParamConverter.php | 166 +++--- .../ParamConverterInterface.php | 34 +- .../ParamConverter/ParamConverterManager.php | 242 ++++----- .../AnnotatedRouteControllerLoader.php | 144 +++--- src/Templating/TemplateResolver.php | 166 +++--- .../src/Controller/AdminController.php | 32 +- .../src/Controller/BasicController.php | 14 +- .../src/Controller/InvokeController.php | 8 +- .../src/Controller/MethodController.php | 54 +- .../Controller/ParamConverterController.php | 76 +-- .../Controller/PrefixedRouteController.php | 32 +- .../src/Controller/SecurityController.php | 128 ++--- .../src/Controller/ServiceController.php | 16 +- .../src/Controller/TemplateController.php | 114 ++--- .../src/Controller/TitleController.php | 94 ++-- .../src/Security/Custom.php | 16 +- .../src/Title/Custom.php | 14 +- tests/src/Kernel/AnnotationsTest.php | 278 +++++----- tests/src/Kernel/DrupalTestKernel.php | 34 +- tests/src/Kernel/KernelTestBase.php | 262 +++++----- tests/src/Kernel/TestUserSession.php | 30 +- tests/src/Unit/Cache/DrupalCacheTest.php | 184 +++---- tests/src/Unit/Configuration/CacheTest.php | 68 +-- tests/src/Unit/Configuration/MethodTest.php | 66 +-- tests/src/Unit/Configuration/RouteTest.php | 78 +-- tests/src/Unit/Configuration/SecurityTest.php | 86 ++-- tests/src/Unit/Configuration/TitleTest.php | 90 ++-- .../ControllerEventSubscriberTest.php | 202 ++++---- .../EventSubscriber/HttpCacheListenerTest.php | 478 ++++++++--------- .../ParamConverterEventSubscriberTest.php | 350 ++++++------- .../RouteEventSubscriberTest.php | 170 +++---- .../TemplateEventSubscriberTest.php | 240 ++++----- .../FooControllerNullableParameter.php | 18 +- ...ntrollerParamConverterAtClassAndMethod.php | 12 +- tests/src/Unit/Helper.php | 14 +- .../DateTimeParamConverterTest.php | 214 ++++---- .../EntityParamConverterTest.php | 350 ++++++------- .../ParamConverterManagerTest.php | 360 ++++++------- .../AnnotatedRouteControllerLoaderTest.php | 76 +-- .../Unit/Templating/TemplateResolverTest.php | 164 +++--- tests/src/polyfill.php | 20 +- 59 files changed, 4565 insertions(+), 4565 deletions(-) diff --git a/src/Cache/DrupalCache.php b/src/Cache/DrupalCache.php index ed99230..70961b7 100644 --- a/src/Cache/DrupalCache.php +++ b/src/Cache/DrupalCache.php @@ -7,78 +7,78 @@ class DrupalCache extends CacheProvider { - /** - * @var CacheBackendInterface - */ - private $cache; + /** + * @var CacheBackendInterface + */ + private $cache; - /** - * @param CacheBackendInterface $cache - */ - public function __construct(CacheBackendInterface $cache) - { - $this->cache = $cache; - } - - /** - * @inheritdoc - */ - protected function doFetch($id) - { - if ($cache = $this->cache->get($id)) { - return $cache->data; - } + /** + * @param CacheBackendInterface $cache + */ + public function __construct(CacheBackendInterface $cache) + { + $this->cache = $cache; + } - return false; + /** + * @inheritdoc + */ + protected function doFetch($id) + { + if ($cache = $this->cache->get($id)) { + return $cache->data; } - /** - * @inheritdoc - */ - protected function doContains($id) - { - return $this->doFetch($id) !== false; - } + return false; + } - /** - * @inheritdoc - */ - protected function doSave($id, $data, $lifeTime = 0) - { - if ($lifeTime === 0) { - $this->cache->set($id, $data); - } else { - $this->cache->set($id, $data, time() + $lifeTime); - } + /** + * @inheritdoc + */ + protected function doContains($id) + { + return $this->doFetch($id) !== false; + } - return true; + /** + * @inheritdoc + */ + protected function doSave($id, $data, $lifeTime = 0) + { + if ($lifeTime === 0) { + $this->cache->set($id, $data); + } else { + $this->cache->set($id, $data, time() + $lifeTime); } - /** - * @inheritdoc - */ - protected function doDelete($id) - { - $this->cache->delete($id); + return true; + } - return true; - } + /** + * @inheritdoc + */ + protected function doDelete($id) + { + $this->cache->delete($id); - /** - * @inheritdoc - */ - protected function doFlush() - { - $this->cache->deleteAll(); + return true; + } - return true; - } + /** + * @inheritdoc + */ + protected function doFlush() + { + $this->cache->deleteAll(); - /** - * @inheritdoc - */ - protected function doGetStats() - { - return; - } + return true; + } + + /** + * @inheritdoc + */ + protected function doGetStats() + { + return; + } } diff --git a/src/Configuration/Cache.php b/src/Configuration/Cache.php index f84a28e..9004311 100644 --- a/src/Configuration/Cache.php +++ b/src/Configuration/Cache.php @@ -7,230 +7,230 @@ */ class Cache extends ConfigurationAnnotation { - /** - * The expiration date as a valid date for the strtotime() function. - * - * @var string - */ - protected $expires; - - /** - * The number of seconds that the response is considered fresh by a private - * cache like a web browser. - * - * @var int - */ - protected $maxage; - - /** - * The number of seconds that the response is considered fresh by a public - * cache like a reverse proxy cache. - * - * @var int - */ - protected $smaxage; - - /** - * Whether the response is public or not. - * - * @var bool - */ - protected $public; - - /** - * Additional "Vary:"-headers. - * - * @var array - */ - protected $vary; - - /** - * An expression to compute the Last-Modified HTTP header. - * - * @var string - */ - protected $lastModified; - - /** - * An expression to compute the ETag HTTP header. - * - * @var string - */ - protected $etag; - - /** - * Returns the expiration date for the Expires header field. - * - * @return string - */ - public function getExpires() - { - return $this->expires; - } - - /** - * Sets the expiration date for the Expires header field. - * - * @param string $expires A valid php date - */ - public function setExpires($expires) - { - $this->expires = $expires; - } - - /** - * Sets the number of seconds for the max-age cache-control header field. - * - * @param int $maxage A number of seconds - */ - public function setMaxAge($maxage) - { - $this->maxage = $maxage; - } - - /** - * Returns the number of seconds the response is considered fresh by a - * private cache. - * - * @return int - */ - public function getMaxAge() - { - return $this->maxage; - } - - /** - * Sets the number of seconds for the s-maxage cache-control header field. - * - * @param int $smaxage A number of seconds - */ - public function setSMaxAge($smaxage) - { - $this->smaxage = $smaxage; - } - - /** - * Returns the number of seconds the response is considered fresh by a - * public cache. - * - * @return int - */ - public function getSMaxAge() - { - return $this->smaxage; - } - - /** - * Returns whether or not a response is public. - * - * @return bool - */ - public function isPublic() - { - return $this->public === true; - } - - /** - * Returns whether or not a response is private. - * - * @return bool - */ - public function isPrivate() - { - return $this->public === false; - } - - /** - * Sets a response public. - * - * @param bool $public A boolean value - */ - public function setPublic($public) - { - $this->public = (bool)$public; - } - - /** - * Returns the custom "Vary"-headers. - * - * @return array - */ - public function getVary() - { - return $this->vary; - } - - /** - * Add additional "Vary:"-headers. - * - * @param array $vary - */ - public function setVary($vary) - { - $this->vary = $vary; - } - - /** - * Sets the "Last-Modified"-header expression. - * - * @param string $expression - */ - public function setLastModified($expression) - { - $this->lastModified = $expression; - } - - /** - * Returns the "Last-Modified"-header expression. - * - * @return string - */ - public function getLastModified() - { - return $this->lastModified; - } - - /** - * Sets the "ETag"-header expression. - * - * @param string $expression - */ - public function setETag($expression) - { - $this->etag = $expression; - } - - /** - * Returns the "ETag"-header expression. - * - * @return string - */ - public function getETag() - { - return $this->etag; - } - - /** - * Returns the annotation alias name. - * - * @return string - * - * @see ConfigurationInterface - */ - public function getAliasName() - { - return 'cache'; - } - - /** - * Only one cache directive is allowed. - * - * @return bool - * - * @see ConfigurationInterface - */ - public function allowArray() - { - return false; - } + /** + * The expiration date as a valid date for the strtotime() function. + * + * @var string + */ + protected $expires; + + /** + * The number of seconds that the response is considered fresh by a private + * cache like a web browser. + * + * @var int + */ + protected $maxage; + + /** + * The number of seconds that the response is considered fresh by a public + * cache like a reverse proxy cache. + * + * @var int + */ + protected $smaxage; + + /** + * Whether the response is public or not. + * + * @var bool + */ + protected $public; + + /** + * Additional "Vary:"-headers. + * + * @var array + */ + protected $vary; + + /** + * An expression to compute the Last-Modified HTTP header. + * + * @var string + */ + protected $lastModified; + + /** + * An expression to compute the ETag HTTP header. + * + * @var string + */ + protected $etag; + + /** + * Returns the expiration date for the Expires header field. + * + * @return string + */ + public function getExpires() + { + return $this->expires; + } + + /** + * Sets the expiration date for the Expires header field. + * + * @param string $expires A valid php date + */ + public function setExpires($expires) + { + $this->expires = $expires; + } + + /** + * Sets the number of seconds for the max-age cache-control header field. + * + * @param int $maxage A number of seconds + */ + public function setMaxAge($maxage) + { + $this->maxage = $maxage; + } + + /** + * Returns the number of seconds the response is considered fresh by a + * private cache. + * + * @return int + */ + public function getMaxAge() + { + return $this->maxage; + } + + /** + * Sets the number of seconds for the s-maxage cache-control header field. + * + * @param int $smaxage A number of seconds + */ + public function setSMaxAge($smaxage) + { + $this->smaxage = $smaxage; + } + + /** + * Returns the number of seconds the response is considered fresh by a + * public cache. + * + * @return int + */ + public function getSMaxAge() + { + return $this->smaxage; + } + + /** + * Returns whether or not a response is public. + * + * @return bool + */ + public function isPublic() + { + return $this->public === true; + } + + /** + * Returns whether or not a response is private. + * + * @return bool + */ + public function isPrivate() + { + return $this->public === false; + } + + /** + * Sets a response public. + * + * @param bool $public A boolean value + */ + public function setPublic($public) + { + $this->public = (bool)$public; + } + + /** + * Returns the custom "Vary"-headers. + * + * @return array + */ + public function getVary() + { + return $this->vary; + } + + /** + * Add additional "Vary:"-headers. + * + * @param array $vary + */ + public function setVary($vary) + { + $this->vary = $vary; + } + + /** + * Sets the "Last-Modified"-header expression. + * + * @param string $expression + */ + public function setLastModified($expression) + { + $this->lastModified = $expression; + } + + /** + * Returns the "Last-Modified"-header expression. + * + * @return string + */ + public function getLastModified() + { + return $this->lastModified; + } + + /** + * Sets the "ETag"-header expression. + * + * @param string $expression + */ + public function setETag($expression) + { + $this->etag = $expression; + } + + /** + * Returns the "ETag"-header expression. + * + * @return string + */ + public function getETag() + { + return $this->etag; + } + + /** + * Returns the annotation alias name. + * + * @return string + * + * @see ConfigurationInterface + */ + public function getAliasName() + { + return 'cache'; + } + + /** + * Only one cache directive is allowed. + * + * @return bool + * + * @see ConfigurationInterface + */ + public function allowArray() + { + return false; + } } diff --git a/src/Configuration/ConfigurationAnnotation.php b/src/Configuration/ConfigurationAnnotation.php index 2301fb5..fb05f53 100644 --- a/src/Configuration/ConfigurationAnnotation.php +++ b/src/Configuration/ConfigurationAnnotation.php @@ -9,14 +9,14 @@ */ abstract class ConfigurationAnnotation implements ConfigurationInterface { - public function __construct(array $values) - { - foreach ($values as $k => $v) { - if (!method_exists($this, $name = 'set'.$k)) { - throw new \RuntimeException(sprintf('Unknown key "%s" for annotation "@%s".', $k, get_class($this))); - } + public function __construct(array $values) + { + foreach ($values as $k => $v) { + if (!method_exists($this, $name = 'set'.$k)) { + throw new \RuntimeException(sprintf('Unknown key "%s" for annotation "@%s".', $k, get_class($this))); + } - $this->$name($v); - } + $this->$name($v); } + } } diff --git a/src/Configuration/ConfigurationInterface.php b/src/Configuration/ConfigurationInterface.php index 710b5f0..9874cdb 100644 --- a/src/Configuration/ConfigurationInterface.php +++ b/src/Configuration/ConfigurationInterface.php @@ -9,17 +9,17 @@ */ interface ConfigurationInterface { - /** - * Returns the alias name for an annotated configuration. - * - * @return string - */ - public function getAliasName(); + /** + * Returns the alias name for an annotated configuration. + * + * @return string + */ + public function getAliasName(); - /** - * Returns whether multiple annotations of this type are allowed. - * - * @return bool - */ - public function allowArray(); + /** + * Returns whether multiple annotations of this type are allowed. + * + * @return bool + */ + public function allowArray(); } diff --git a/src/Configuration/Method.php b/src/Configuration/Method.php index 3d34704..d89c2be 100644 --- a/src/Configuration/Method.php +++ b/src/Configuration/Method.php @@ -9,95 +9,95 @@ */ class Method extends ConfigurationAnnotation implements RouteModifierMethodInterface, RouteModifierClassInterface { - /** - * An array of restricted HTTP methods. - * - * @var array - */ - protected $methods = array(); + /** + * An array of restricted HTTP methods. + * + * @var array + */ + protected $methods = array(); - /** - * Returns the array of HTTP methods. - * - * @return array - */ - public function getMethods() - { - return $this->methods; - } + /** + * Returns the array of HTTP methods. + * + * @return array + */ + public function getMethods() + { + return $this->methods; + } - /** - * Sets the HTTP methods. - * - * @param array|string $methods An HTTP method or an array of HTTP methods - */ - public function setMethods($methods) - { - $this->methods = is_array($methods) ? $methods : array($methods); - } + /** + * Sets the HTTP methods. + * + * @param array|string $methods An HTTP method or an array of HTTP methods + */ + public function setMethods($methods) + { + $this->methods = is_array($methods) ? $methods : array($methods); + } - /** - * Sets the HTTP methods. - * - * @param array|string $methods An HTTP method or an array of HTTP methods - */ - public function setValue($methods) - { - $this->setMethods($methods); - } + /** + * Sets the HTTP methods. + * + * @param array|string $methods An HTTP method or an array of HTTP methods + */ + public function setValue($methods) + { + $this->setMethods($methods); + } - /** - * Returns the annotation alias name. - * - * @return string - * - * @see ConfigurationInterface - */ - public function getAliasName() - { - return 'method'; - } + /** + * Returns the annotation alias name. + * + * @return string + * + * @see ConfigurationInterface + */ + public function getAliasName() + { + return 'method'; + } - /** - * Only one method directive is allowed. - * - * @return bool - * - * @see ConfigurationInterface - */ - public function allowArray() - { - return false; - } + /** + * Only one method directive is allowed. + * + * @return bool + * + * @see ConfigurationInterface + */ + public function allowArray() + { + return false; + } - /** - * @param RoutingRoute $route - * @param \ReflectionClass $class - * @param \ReflectionMethod $method - */ - public function modifyRouteClass(RoutingRoute $route, \ReflectionClass $class, \ReflectionMethod $method) - { - $this->modifyRoute($route); - } + /** + * @param RoutingRoute $route + * @param \ReflectionClass $class + * @param \ReflectionMethod $method + */ + public function modifyRouteClass(RoutingRoute $route, \ReflectionClass $class, \ReflectionMethod $method) + { + $this->modifyRoute($route); + } - /** - * @param RoutingRoute $route - * @param \ReflectionClass $class - * @param \ReflectionMethod $method - */ - public function modifyRouteMethod(RoutingRoute $route, \ReflectionClass $class, \ReflectionMethod $method) - { - $this->modifyRoute($route); - } + /** + * @param RoutingRoute $route + * @param \ReflectionClass $class + * @param \ReflectionMethod $method + */ + public function modifyRouteMethod(RoutingRoute $route, \ReflectionClass $class, \ReflectionMethod $method) + { + $this->modifyRoute($route); + } - /** - * we need to make sure this is an array instead of a string which is different in Symfony Framework - * otherwise the support for defining an array of methods will not work as expected - * - * @param RoutingRoute $route - */ - protected function modifyRoute(RoutingRoute $route) - { - $route->setMethods($this->getMethods()); - } + /** + * we need to make sure this is an array instead of a string which is different in Symfony Framework + * otherwise the support for defining an array of methods will not work as expected + * + * @param RoutingRoute $route + */ + protected function modifyRoute(RoutingRoute $route) + { + $route->setMethods($this->getMethods()); + } } diff --git a/src/Configuration/ParamConverter.php b/src/Configuration/ParamConverter.php index ae3f1ed..8642838 100644 --- a/src/Configuration/ParamConverter.php +++ b/src/Configuration/ParamConverter.php @@ -11,172 +11,172 @@ class ParamConverter extends ConfigurationAnnotation { - /** - * The parameter name. - * - * @var string - */ - protected $name; - - /** - * The parameter class. - * - * @var string - */ - protected $class; - - /** - * An array of options. - * - * @var array - */ - protected $options = []; - - /** - * Whether or not the parameter is optional. - * - * @var bool - */ - protected $optional = false; - - /** - * Use explicitly named converter instead of iterating by priorities. - * - * @var string - */ - protected $converter; - - /** - * Returns the parameter name. - * - * @return string - */ - public function getName() - { - return $this->name; - } - - /** - * Sets the parameter name. - * - * @param string $name The parameter name - */ - public function setValue($name) - { - $this->setName($name); - } - - /** - * Sets the parameter name. - * - * @param string $name The parameter name - */ - public function setName($name) - { - $this->name = $name; - } - - /** - * Returns the parameter class name. - * - * @return string $name - */ - public function getClass() - { - return $this->class; - } - - /** - * Sets the parameter class name. - * - * @param string $class The parameter class name - */ - public function setClass($class) - { - $this->class = $class; - } - - /** - * Returns an array of options. - * - * @return array - */ - public function getOptions() - { - return $this->options; - } - - /** - * Sets an array of options. - * - * @param array $options An array of options - */ - public function setOptions($options) - { - $this->options = $options; - } - - /** - * Sets whether or not the parameter is optional. - * - * @param bool $optional Whether the parameter is optional - */ - public function setIsOptional($optional) - { - $this->optional = (bool)$optional; - } - - /** - * Returns whether or not the parameter is optional. - * - * @return bool - */ - public function isOptional() - { - return $this->optional; - } - - /** - * Get explicit converter name. - * - * @return string - */ - public function getConverter() - { - return $this->converter; - } - - /** - * Set explicit converter name. - * - * @param string $converter - */ - public function setConverter($converter) - { - $this->converter = $converter; - } - - /** - * Returns the annotation alias name. - * - * @return string - * - * @see ConfigurationInterface - */ - public function getAliasName() - { - return 'converters'; - } - - /** - * Multiple ParamConverters are allowed. - * - * @return bool - * - * @see ConfigurationInterface - */ - public function allowArray() - { - return true; - } + /** + * The parameter name. + * + * @var string + */ + protected $name; + + /** + * The parameter class. + * + * @var string + */ + protected $class; + + /** + * An array of options. + * + * @var array + */ + protected $options = []; + + /** + * Whether or not the parameter is optional. + * + * @var bool + */ + protected $optional = false; + + /** + * Use explicitly named converter instead of iterating by priorities. + * + * @var string + */ + protected $converter; + + /** + * Returns the parameter name. + * + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * Sets the parameter name. + * + * @param string $name The parameter name + */ + public function setValue($name) + { + $this->setName($name); + } + + /** + * Sets the parameter name. + * + * @param string $name The parameter name + */ + public function setName($name) + { + $this->name = $name; + } + + /** + * Returns the parameter class name. + * + * @return string $name + */ + public function getClass() + { + return $this->class; + } + + /** + * Sets the parameter class name. + * + * @param string $class The parameter class name + */ + public function setClass($class) + { + $this->class = $class; + } + + /** + * Returns an array of options. + * + * @return array + */ + public function getOptions() + { + return $this->options; + } + + /** + * Sets an array of options. + * + * @param array $options An array of options + */ + public function setOptions($options) + { + $this->options = $options; + } + + /** + * Sets whether or not the parameter is optional. + * + * @param bool $optional Whether the parameter is optional + */ + public function setIsOptional($optional) + { + $this->optional = (bool)$optional; + } + + /** + * Returns whether or not the parameter is optional. + * + * @return bool + */ + public function isOptional() + { + return $this->optional; + } + + /** + * Get explicit converter name. + * + * @return string + */ + public function getConverter() + { + return $this->converter; + } + + /** + * Set explicit converter name. + * + * @param string $converter + */ + public function setConverter($converter) + { + $this->converter = $converter; + } + + /** + * Returns the annotation alias name. + * + * @return string + * + * @see ConfigurationInterface + */ + public function getAliasName() + { + return 'converters'; + } + + /** + * Multiple ParamConverters are allowed. + * + * @return bool + * + * @see ConfigurationInterface + */ + public function allowArray() + { + return true; + } } diff --git a/src/Configuration/Route.php b/src/Configuration/Route.php index 63359f4..22833f7 100644 --- a/src/Configuration/Route.php +++ b/src/Configuration/Route.php @@ -11,97 +11,97 @@ class Route extends BaseRoute implements RouteModifierMethodInterface, RouteModifierClassInterface { - /** - * @var string - */ - protected $service; + /** + * @var string + */ + protected $service; - /** - * @var bool - */ - protected $admin; + /** + * @var bool + */ + protected $admin; - /** - * @param $service - */ - public function setService($service) - { - // avoid a BC notice in case of @Route(service="") with sf ^2.7 - if (null === $this->getPath()) { - $this->setPath(''); - } - $this->service = $service; + /** + * @param $service + */ + public function setService($service) + { + // avoid a BC notice in case of @Route(service="") with sf ^2.7 + if (null === $this->getPath()) { + $this->setPath(''); } + $this->service = $service; + } - public function getService() - { - return $this->service; - } + public function getService() + { + return $this->service; + } - /** - * @return bool - */ - public function isAdmin() - { - return $this->admin; - } + /** + * @return bool + */ + public function isAdmin() + { + return $this->admin; + } - /** - * @param bool $admin - * @return Route - */ - public function setAdmin($admin) - { - $this->admin = $admin; + /** + * @param bool $admin + * @return Route + */ + public function setAdmin($admin) + { + $this->admin = $admin; - return $this; - } + return $this; + } - /** - * Multiple route annotations are allowed. - * - * @return bool - * - * @see ConfigurationInterface - */ - public function allowArray() - { - return true; - } + /** + * Multiple route annotations are allowed. + * + * @return bool + * + * @see ConfigurationInterface + */ + public function allowArray() + { + return true; + } - /** - * @param RoutingRoute $route - * @param \ReflectionClass $class - * @param \ReflectionMethod $method - */ - public function modifyRouteClass(RoutingRoute $route, \ReflectionClass $class, \ReflectionMethod $method) - { - $this->modifyRoute($route, $class, $method); - } - - /** - * @param RoutingRoute $route - * @param \ReflectionClass $class - * @param \ReflectionMethod $method - */ - public function modifyRouteMethod(RoutingRoute $route, \ReflectionClass $class, \ReflectionMethod $method) - { - if ($this->getService()) { - throw new \LogicException('The service option can only be specified at class level.'); - } + /** + * @param RoutingRoute $route + * @param \ReflectionClass $class + * @param \ReflectionMethod $method + */ + public function modifyRouteClass(RoutingRoute $route, \ReflectionClass $class, \ReflectionMethod $method) + { + $this->modifyRoute($route, $class, $method); + } - $this->modifyRoute($route, $class, $method); + /** + * @param RoutingRoute $route + * @param \ReflectionClass $class + * @param \ReflectionMethod $method + */ + public function modifyRouteMethod(RoutingRoute $route, \ReflectionClass $class, \ReflectionMethod $method) + { + if ($this->getService()) { + throw new \LogicException('The service option can only be specified at class level.'); } - /** - * @param RoutingRoute $route - * @param \ReflectionClass $class - * @param \ReflectionMethod $method - */ - protected function modifyRoute(RoutingRoute $route, \ReflectionClass $class, \ReflectionMethod $method) - { - if ($this->isAdmin()) { - $route->setOption('_admin_route', true); - } + $this->modifyRoute($route, $class, $method); + } + + /** + * @param RoutingRoute $route + * @param \ReflectionClass $class + * @param \ReflectionMethod $method + */ + protected function modifyRoute(RoutingRoute $route, \ReflectionClass $class, \ReflectionMethod $method) + { + if ($this->isAdmin()) { + $route->setOption('_admin_route', true); } + } } diff --git a/src/Configuration/RouteModifierClassInterface.php b/src/Configuration/RouteModifierClassInterface.php index 3414189..6f5861d 100644 --- a/src/Configuration/RouteModifierClassInterface.php +++ b/src/Configuration/RouteModifierClassInterface.php @@ -6,10 +6,10 @@ interface RouteModifierClassInterface extends RouteModifierInterface { - /** - * @param RoutingRoute $route - * @param \ReflectionClass $class - * @param \ReflectionMethod $method - */ - public function modifyRouteClass(RoutingRoute $route, \ReflectionClass $class, \ReflectionMethod $method); + /** + * @param RoutingRoute $route + * @param \ReflectionClass $class + * @param \ReflectionMethod $method + */ + public function modifyRouteClass(RoutingRoute $route, \ReflectionClass $class, \ReflectionMethod $method); } diff --git a/src/Configuration/RouteModifierMethodInterface.php b/src/Configuration/RouteModifierMethodInterface.php index ab8d569..31d4197 100644 --- a/src/Configuration/RouteModifierMethodInterface.php +++ b/src/Configuration/RouteModifierMethodInterface.php @@ -6,10 +6,10 @@ interface RouteModifierMethodInterface extends RouteModifierInterface { - /** - * @param RoutingRoute $route - * @param \ReflectionClass $class - * @param \ReflectionMethod $method - */ - public function modifyRouteMethod(RoutingRoute $route, \ReflectionClass $class, \ReflectionMethod $method); + /** + * @param RoutingRoute $route + * @param \ReflectionClass $class + * @param \ReflectionMethod $method + */ + public function modifyRouteMethod(RoutingRoute $route, \ReflectionClass $class, \ReflectionMethod $method); } diff --git a/src/Configuration/Security.php b/src/Configuration/Security.php index 8b6b342..fd78661 100644 --- a/src/Configuration/Security.php +++ b/src/Configuration/Security.php @@ -9,248 +9,248 @@ */ class Security extends ConfigurationAnnotation implements RouteModifierMethodInterface, RouteModifierClassInterface { - /** - * @var string - */ - protected $permission; - - /** - * @var string - */ - protected $role; - - /** - * @var bool - */ - protected $access; - - /** - * @var string - */ - protected $entity; - - /** - * @var bool - */ - protected $csrf; - - /** - * @var string - */ - protected $custom; - - /** - * @return bool - */ - public function hasPermission() - { - return !empty($this->permission); + /** + * @var string + */ + protected $permission; + + /** + * @var string + */ + protected $role; + + /** + * @var bool + */ + protected $access; + + /** + * @var string + */ + protected $entity; + + /** + * @var bool + */ + protected $csrf; + + /** + * @var string + */ + protected $custom; + + /** + * @return bool + */ + public function hasPermission() + { + return !empty($this->permission); + } + + /** + * @return string + */ + public function getPermission() + { + return $this->permission; + } + + /** + * @param string $permission + * @return Security + */ + public function setPermission($permission) + { + $this->permission = $permission; + + return $this; + } + + /** + * @return bool + */ + public function hasRole() + { + return !empty($this->role); + } + + /** + * @return string + */ + public function getRole() + { + return $this->role; + } + + /** + * @param string $role + * @return Security + */ + public function setRole($role) + { + $this->role = $role; + + return $this; + } + + /** + * @return bool + */ + public function isAccess() + { + return $this->access; + } + + /** + * @param bool $access + * @return Security + */ + public function setAccess($access) + { + $this->access = $access; + + return $this; + } + + /** + * @return bool + */ + public function hasEntity() + { + return !empty($this->entity); + } + + /** + * @return string + */ + public function getEntity() + { + return $this->entity; + } + + /** + * @param string $entity + * @return Security + */ + public function setEntity($entity) + { + $this->entity = $entity; + + return $this; + } + + /** + * @return bool + */ + public function hasCustom() + { + return !empty($this->custom); + } + + /** + * @return string + */ + public function getCustom() + { + return $this->custom; + } + + /** + * @param string $custom + * @return Security + */ + public function setCustom($custom) + { + $this->custom = $custom; + + return $this; + } + + /** + * @return bool + */ + public function hasCsrf() + { + return !empty($this->csrf); + } + + /** + * @param bool $csrf + * @return Security + */ + public function setCsrf($csrf) + { + $this->csrf = $csrf; + + return $this; + } + + public function getAliasName() + { + return 'security'; + } + + public function allowArray() + { + return false; + } + + /** + * @param RoutingRoute $route + * @param \ReflectionClass $class + * @param \ReflectionMethod $method + */ + public function modifyRouteClass(RoutingRoute $route, \ReflectionClass $class, \ReflectionMethod $method) + { + $this->modifyRoute($route, $class); + } + + /** + * @param RoutingRoute $route + * @param \ReflectionClass $class + * @param \ReflectionMethod $method + */ + public function modifyRouteMethod(RoutingRoute $route, \ReflectionClass $class, \ReflectionMethod $method) + { + $this->modifyRoute($route, $class); + } + + /** + * @param RoutingRoute $route + * @param \ReflectionClass $class + */ + protected function modifyRoute(RoutingRoute $route, \ReflectionClass $class) + { + if ($this->isAccess()) { + $route->setRequirement('_access', 'TRUE'); } - - /** - * @return string - */ - public function getPermission() - { - return $this->permission; - } - - /** - * @param string $permission - * @return Security - */ - public function setPermission($permission) - { - $this->permission = $permission; - - return $this; - } - - /** - * @return bool - */ - public function hasRole() - { - return !empty($this->role); - } - - /** - * @return string - */ - public function getRole() - { - return $this->role; - } - - /** - * @param string $role - * @return Security - */ - public function setRole($role) - { - $this->role = $role; - - return $this; - } - - /** - * @return bool - */ - public function isAccess() - { - return $this->access; - } - - /** - * @param bool $access - * @return Security - */ - public function setAccess($access) - { - $this->access = $access; - - return $this; - } - - /** - * @return bool - */ - public function hasEntity() - { - return !empty($this->entity); - } - - /** - * @return string - */ - public function getEntity() - { - return $this->entity; - } - - /** - * @param string $entity - * @return Security - */ - public function setEntity($entity) - { - $this->entity = $entity; - - return $this; + if ($this->hasPermission()) { + $route->setRequirement('_permission', $this->getPermission()); } - - /** - * @return bool - */ - public function hasCustom() - { - return !empty($this->custom); + if ($this->hasRole()) { + $route->setRequirement('_role', $this->getRole()); } - - /** - * @return string - */ - public function getCustom() - { - return $this->custom; + if ($this->hasEntity()) { + $route->setRequirement('_entity_access', $this->getEntity()); } - - /** - * @param string $custom - * @return Security - */ - public function setCustom($custom) - { - $this->custom = $custom; - - return $this; - } - - /** - * @return bool - */ - public function hasCsrf() - { - return !empty($this->csrf); - } - - /** - * @param bool $csrf - * @return Security - */ - public function setCsrf($csrf) - { - $this->csrf = $csrf; - - return $this; - } - - public function getAliasName() - { - return 'security'; - } - - public function allowArray() - { - return false; - } - - /** - * @param RoutingRoute $route - * @param \ReflectionClass $class - * @param \ReflectionMethod $method - */ - public function modifyRouteClass(RoutingRoute $route, \ReflectionClass $class, \ReflectionMethod $method) - { - $this->modifyRoute($route, $class); - } - - /** - * @param RoutingRoute $route - * @param \ReflectionClass $class - * @param \ReflectionMethod $method - */ - public function modifyRouteMethod(RoutingRoute $route, \ReflectionClass $class, \ReflectionMethod $method) - { - $this->modifyRoute($route, $class); - } - - /** - * @param RoutingRoute $route - * @param \ReflectionClass $class - */ - protected function modifyRoute(RoutingRoute $route, \ReflectionClass $class) - { - if ($this->isAccess()) { - $route->setRequirement('_access', 'TRUE'); - } - if ($this->hasPermission()) { - $route->setRequirement('_permission', $this->getPermission()); - } - if ($this->hasRole()) { - $route->setRequirement('_role', $this->getRole()); - } - if ($this->hasEntity()) { - $route->setRequirement('_entity_access', $this->getEntity()); - } - if ($this->hasCsrf()) { - $route->setRequirement('_csrf_token', 'TRUE'); - } - - $this->setCustomSecurity($route, $class); + if ($this->hasCsrf()) { + $route->setRequirement('_csrf_token', 'TRUE'); } - /** - * @param RoutingRoute $route - * @param \ReflectionClass $class - */ - protected function setCustomSecurity(RoutingRoute $route, \ReflectionClass $class) - { - if ($this->hasCustom()) { - if (strpos($this->getCustom(), '::') === false && $class->hasMethod($this->getCustom())) { - $this->setCustom(sprintf('%s::%s', $class->getName(), $this->getCustom())); - } - $route->setRequirement('_custom_access', $this->getCustom()); - } + $this->setCustomSecurity($route, $class); + } + + /** + * @param RoutingRoute $route + * @param \ReflectionClass $class + */ + protected function setCustomSecurity(RoutingRoute $route, \ReflectionClass $class) + { + if ($this->hasCustom()) { + if (strpos($this->getCustom(), '::') === false && $class->hasMethod($this->getCustom())) { + $this->setCustom(sprintf('%s::%s', $class->getName(), $this->getCustom())); + } + $route->setRequirement('_custom_access', $this->getCustom()); } + } } diff --git a/src/Configuration/Template.php b/src/Configuration/Template.php index 377e392..f48e64c 100644 --- a/src/Configuration/Template.php +++ b/src/Configuration/Template.php @@ -8,139 +8,139 @@ class Template extends ConfigurationAnnotation { - /** - * The template reference. - * - * @var string - */ - protected $template; - - /** - * The associative array of template variables. - * - * @var array - */ - protected $vars = []; - - /** - * Should the template be streamed? - * - * @var bool - */ - protected $streamable = false; - - /** - * The controller (+action) this annotation is set to. - * - * @var array - */ - private $owner; - - /** - * Returns the array of templates variables. - * - * @return array - */ - public function getVars() - { - return $this->vars; - } - - /** - * @param bool $streamable - */ - public function setIsStreamable($streamable) - { - $this->streamable = $streamable; - } - - /** - * @return bool - */ - public function isStreamable() - { - return (bool)$this->streamable; - } - - /** - * Sets the template variables. - * - * @param array $vars The template variables - */ - public function setVars($vars) - { - $this->vars = $vars; - } - - /** - * Sets the template logic name. - * - * @param string $template The template logic name - */ - public function setValue($template) - { - $this->setTemplate($template); - } - - /** - * Returns the template reference. - * - * @return string - */ - public function getTemplate() - { - return $this->template; - } - - /** - * Sets the template reference. - * - * @param string $template The template reference - */ - public function setTemplate($template) - { - $this->template = $template; - } - - /** - * Returns the annotation alias name. - * - * @return string - * - * @see ConfigurationInterface - */ - public function getAliasName() - { - return 'template'; - } - - /** - * Only one template directive is allowed. - * - * @return bool - * - * @see ConfigurationInterface - */ - public function allowArray() - { - return false; - } - - /** - * @param array $owner - */ - public function setOwner(array $owner) - { - $this->owner = $owner; - } - - /** - * The controller (+action) this annotation is attached to. - * - * @return array - */ - public function getOwner() - { - return $this->owner; - } + /** + * The template reference. + * + * @var string + */ + protected $template; + + /** + * The associative array of template variables. + * + * @var array + */ + protected $vars = []; + + /** + * Should the template be streamed? + * + * @var bool + */ + protected $streamable = false; + + /** + * The controller (+action) this annotation is set to. + * + * @var array + */ + private $owner; + + /** + * Returns the array of templates variables. + * + * @return array + */ + public function getVars() + { + return $this->vars; + } + + /** + * @param bool $streamable + */ + public function setIsStreamable($streamable) + { + $this->streamable = $streamable; + } + + /** + * @return bool + */ + public function isStreamable() + { + return (bool)$this->streamable; + } + + /** + * Sets the template variables. + * + * @param array $vars The template variables + */ + public function setVars($vars) + { + $this->vars = $vars; + } + + /** + * Sets the template logic name. + * + * @param string $template The template logic name + */ + public function setValue($template) + { + $this->setTemplate($template); + } + + /** + * Returns the template reference. + * + * @return string + */ + public function getTemplate() + { + return $this->template; + } + + /** + * Sets the template reference. + * + * @param string $template The template reference + */ + public function setTemplate($template) + { + $this->template = $template; + } + + /** + * Returns the annotation alias name. + * + * @return string + * + * @see ConfigurationInterface + */ + public function getAliasName() + { + return 'template'; + } + + /** + * Only one template directive is allowed. + * + * @return bool + * + * @see ConfigurationInterface + */ + public function allowArray() + { + return false; + } + + /** + * @param array $owner + */ + public function setOwner(array $owner) + { + $this->owner = $owner; + } + + /** + * The controller (+action) this annotation is attached to. + * + * @return array + */ + public function getOwner() + { + return $this->owner; + } } diff --git a/src/Configuration/Title.php b/src/Configuration/Title.php index dde4c6b..50ba4bb 100644 --- a/src/Configuration/Title.php +++ b/src/Configuration/Title.php @@ -9,196 +9,196 @@ */ class Title extends ConfigurationAnnotation implements RouteModifierMethodInterface, RouteModifierClassInterface { - /** - * @var string - */ - protected $value; - - /** - * @var array - */ - protected $arguments; - - /** - * @var array - */ - protected $context; - - /** - * @var string - */ - protected $callback; - - /** - * @param $title - */ - public function setValue($title) - { - $this->setTitle($title); - } - - /** - * @return bool - */ - public function hasTitle() - { - return !empty($this->value); - } - - /** - * @return string - */ - public function getTitle() - { - return $this->value; - } - - /** - * @param string $title - */ - public function setTitle($title) - { - $this->value = $title; - } - - /** - * @return bool - */ - public function hasArguments() - { - return !empty($this->arguments); - } - - /** - * @return array - */ - public function getArguments() - { - return $this->arguments; - } - - /** - * @param array $arguments - */ - public function setArguments(array $arguments) - { - $this->arguments = $arguments; - } - - /** - * @return bool - */ - public function hasContext() - { - return !empty($this->context); - } - - /** - * @return array - */ - public function getContext() - { - return $this->context; - } - - /** - * @param array $context - */ - public function setContext(array $context) - { - $this->context = $context; - } - - /** - * @return bool - */ - public function hasCallback() - { - return !empty($this->callback); - } - - /** - * @return string - */ - public function getCallback() - { - return $this->callback; - } - - /** - * @param string $callback - */ - public function setCallback($callback) - { - $this->callback = $callback; - } - - /** - * @return string - */ - public function getAliasName() - { - return 'title'; - } - - /** - * @return bool - */ - public function allowArray() - { - return false; - } - - /** - * @param RoutingRoute $route - * @param \ReflectionClass $class - * @param \ReflectionMethod $method - */ - public function modifyRouteClass(RoutingRoute $route, \ReflectionClass $class, \ReflectionMethod $method) - { - $this->modifyRoute($route, $class); - } - - /** - * @param RoutingRoute $route - * @param \ReflectionClass $class - * @param \ReflectionMethod $method - */ - public function modifyRouteMethod(RoutingRoute $route, \ReflectionClass $class, \ReflectionMethod $method) - { - $this->modifyRoute($route, $class); - } - - /** - * @param RoutingRoute $route - * @param \ReflectionClass $class - */ - protected function modifyRoute(RoutingRoute $route, \ReflectionClass $class) - { - if ($this->hasTitle()) { - $route->setDefault('_title', $this->getTitle()); - } - if ($this->hasArguments()) { - $route->setDefault('_title_arguments', $this->getArguments()); - } - if ($this->hasContext()) { - $route->setDefault('_title_context', $this->getContext()); - } - - $this->registerCallback($route, $class); - } - - /** - * @param RoutingRoute $route - * @param \ReflectionClass $class - */ - protected function registerCallback(RoutingRoute $route, \ReflectionClass $class) - { - if ($this->hasCallback()) { - if (strpos($this->getCallback(), '::') === false && $class->hasMethod($this->getCallback())) { - $this->setCallback(sprintf('%s::%s', $class->getName(), $this->getCallback())); - } - $route->setDefault('_title_callback', $this->getCallback()); - } - } + /** + * @var string + */ + protected $value; + + /** + * @var array + */ + protected $arguments; + + /** + * @var array + */ + protected $context; + + /** + * @var string + */ + protected $callback; + + /** + * @param $title + */ + public function setValue($title) + { + $this->setTitle($title); + } + + /** + * @return bool + */ + public function hasTitle() + { + return !empty($this->value); + } + + /** + * @return string + */ + public function getTitle() + { + return $this->value; + } + + /** + * @param string $title + */ + public function setTitle($title) + { + $this->value = $title; + } + + /** + * @return bool + */ + public function hasArguments() + { + return !empty($this->arguments); + } + + /** + * @return array + */ + public function getArguments() + { + return $this->arguments; + } + + /** + * @param array $arguments + */ + public function setArguments(array $arguments) + { + $this->arguments = $arguments; + } + + /** + * @return bool + */ + public function hasContext() + { + return !empty($this->context); + } + + /** + * @return array + */ + public function getContext() + { + return $this->context; + } + + /** + * @param array $context + */ + public function setContext(array $context) + { + $this->context = $context; + } + + /** + * @return bool + */ + public function hasCallback() + { + return !empty($this->callback); + } + + /** + * @return string + */ + public function getCallback() + { + return $this->callback; + } + + /** + * @param string $callback + */ + public function setCallback($callback) + { + $this->callback = $callback; + } + + /** + * @return string + */ + public function getAliasName() + { + return 'title'; + } + + /** + * @return bool + */ + public function allowArray() + { + return false; + } + + /** + * @param RoutingRoute $route + * @param \ReflectionClass $class + * @param \ReflectionMethod $method + */ + public function modifyRouteClass(RoutingRoute $route, \ReflectionClass $class, \ReflectionMethod $method) + { + $this->modifyRoute($route, $class); + } + + /** + * @param RoutingRoute $route + * @param \ReflectionClass $class + * @param \ReflectionMethod $method + */ + public function modifyRouteMethod(RoutingRoute $route, \ReflectionClass $class, \ReflectionMethod $method) + { + $this->modifyRoute($route, $class); + } + + /** + * @param RoutingRoute $route + * @param \ReflectionClass $class + */ + protected function modifyRoute(RoutingRoute $route, \ReflectionClass $class) + { + if ($this->hasTitle()) { + $route->setDefault('_title', $this->getTitle()); + } + if ($this->hasArguments()) { + $route->setDefault('_title_arguments', $this->getArguments()); + } + if ($this->hasContext()) { + $route->setDefault('_title_context', $this->getContext()); + } + + $this->registerCallback($route, $class); + } + + /** + * @param RoutingRoute $route + * @param \ReflectionClass $class + */ + protected function registerCallback(RoutingRoute $route, \ReflectionClass $class) + { + if ($this->hasCallback()) { + if (strpos($this->getCallback(), '::') === false && $class->hasMethod($this->getCallback())) { + $this->setCallback(sprintf('%s::%s', $class->getName(), $this->getCallback())); + } + $route->setDefault('_title_callback', $this->getCallback()); + } + } } diff --git a/src/EventSubscriber/ControllerEventSubscriber.php b/src/EventSubscriber/ControllerEventSubscriber.php index 7523bc8..9b8dc2f 100644 --- a/src/EventSubscriber/ControllerEventSubscriber.php +++ b/src/EventSubscriber/ControllerEventSubscriber.php @@ -12,129 +12,129 @@ class ControllerEventSubscriber implements EventSubscriberInterface { - /** - * @var Reader - */ - protected $reader; - - /** - * @param Reader $reader - */ - public function __construct(Reader $reader) - { - $this->reader = $reader; + /** + * @var Reader + */ + protected $reader; + + /** + * @param Reader $reader + */ + public function __construct(Reader $reader) + { + $this->reader = $reader; + } + + /** + * Modifies the Request object to apply configuration information found in + * controllers annotations like the template to render or HTTP caching + * configuration. + * + * @param FilterControllerEvent $event + * @throws \ReflectionException + */ + public function onKernelController(FilterControllerEvent $event) + { + $controller = $event->getController(); + + if (!is_array($controller) && method_exists($controller, '__invoke')) { + $controller = array($controller, '__invoke'); } - /** - * Modifies the Request object to apply configuration information found in - * controllers annotations like the template to render or HTTP caching - * configuration. - * - * @param FilterControllerEvent $event - * @throws \ReflectionException - */ - public function onKernelController(FilterControllerEvent $event) - { - $controller = $event->getController(); - - if (!is_array($controller) && method_exists($controller, '__invoke')) { - $controller = array($controller, '__invoke'); - } - - if (!is_array($controller)) { - return; - } - - $className = ClassUtils::getClass($controller[0]); - $object = new \ReflectionClass($className); - $method = $object->getMethod($controller[1]); - - $classConfigurations = $this->getConfigurations($this->reader->getClassAnnotations($object)); - $methodConfigurations = $this->getConfigurations($this->reader->getMethodAnnotations($method)); - - $this->setRequestAttributes( - $event->getRequest(), - $this->mergeConfigurations($classConfigurations, $methodConfigurations) - ); + if (!is_array($controller)) { + return; } - /** - * @param Request $request - * @param array $configurations - */ - protected function setRequestAttributes(Request $request, array $configurations) - { - foreach ($configurations as $key => $attributes) { - $request->attributes->set($key, $attributes); - } + $className = ClassUtils::getClass($controller[0]); + $object = new \ReflectionClass($className); + $method = $object->getMethod($controller[1]); + + $classConfigurations = $this->getConfigurations($this->reader->getClassAnnotations($object)); + $methodConfigurations = $this->getConfigurations($this->reader->getMethodAnnotations($method)); + + $this->setRequestAttributes( + $event->getRequest(), + $this->mergeConfigurations($classConfigurations, $methodConfigurations) + ); + } + + /** + * @param Request $request + * @param array $configurations + */ + protected function setRequestAttributes(Request $request, array $configurations) + { + foreach ($configurations as $key => $attributes) { + $request->attributes->set($key, $attributes); } - - /** - * @param array $classConfigurations - * @param array $methodConfigurations - * - * @return array - */ - protected function mergeConfigurations(array $classConfigurations, array $methodConfigurations) - { - $configurations = []; - foreach (array_merge(array_keys($classConfigurations), array_keys($methodConfigurations)) as $key) { - if (!array_key_exists($key, $classConfigurations)) { - $configurations[$key] = $methodConfigurations[$key]; - } elseif (!array_key_exists($key, $methodConfigurations)) { - $configurations[$key] = $classConfigurations[$key]; - } else { - if (is_array($classConfigurations[$key])) { - if (!is_array($methodConfigurations[$key])) { - throw new \UnexpectedValueException( - 'Configurations should both be an array or both not be an array' - ); - } - $configurations[$key] = array_merge($classConfigurations[$key], $methodConfigurations[$key]); - } else { - // method configuration overrides class configuration - $configurations[$key] = $methodConfigurations[$key]; - } - } + } + + /** + * @param array $classConfigurations + * @param array $methodConfigurations + * + * @return array + */ + protected function mergeConfigurations(array $classConfigurations, array $methodConfigurations) + { + $configurations = []; + foreach (array_merge(array_keys($classConfigurations), array_keys($methodConfigurations)) as $key) { + if (!array_key_exists($key, $classConfigurations)) { + $configurations[$key] = $methodConfigurations[$key]; + } elseif (!array_key_exists($key, $methodConfigurations)) { + $configurations[$key] = $classConfigurations[$key]; + } else { + if (is_array($classConfigurations[$key])) { + if (!is_array($methodConfigurations[$key])) { + throw new \UnexpectedValueException( + 'Configurations should both be an array or both not be an array' + ); + } + $configurations[$key] = array_merge($classConfigurations[$key], $methodConfigurations[$key]); + } else { + // method configuration overrides class configuration + $configurations[$key] = $methodConfigurations[$key]; } - - return $configurations; + } } - /** - * @param array $annotations - * - * @return array - */ - protected function getConfigurations(array $annotations) - { - $configurations = []; - foreach ($annotations as $configuration) { - if ($configuration instanceof ConfigurationInterface) { - if ($configuration->allowArray()) { - $configurations['_'.$configuration->getAliasName()][] = $configuration; - } elseif (!isset($configurations['_'.$configuration->getAliasName()])) { - $configurations['_'.$configuration->getAliasName()] = $configuration; - } else { - throw new \LogicException( - sprintf('Multiple "%s" annotations are not allowed.', $configuration->getAliasName()) - ); - } - } + return $configurations; + } + + /** + * @param array $annotations + * + * @return array + */ + protected function getConfigurations(array $annotations) + { + $configurations = []; + foreach ($annotations as $configuration) { + if ($configuration instanceof ConfigurationInterface) { + if ($configuration->allowArray()) { + $configurations['_'.$configuration->getAliasName()][] = $configuration; + } elseif (!isset($configurations['_'.$configuration->getAliasName()])) { + $configurations['_'.$configuration->getAliasName()] = $configuration; + } else { + throw new \LogicException( + sprintf('Multiple "%s" annotations are not allowed.', $configuration->getAliasName()) + ); } - - return $configurations; + } } - /** - * @return array - */ - public static function getSubscribedEvents() - { - return [ - KernelEvents::CONTROLLER => [ - ['onKernelController', 200], - ], - ]; - } + return $configurations; + } + + /** + * @return array + */ + public static function getSubscribedEvents() + { + return [ + KernelEvents::CONTROLLER => [ + ['onKernelController', 200], + ], + ]; + } } diff --git a/src/EventSubscriber/HttpCacheEventSubscriber.php b/src/EventSubscriber/HttpCacheEventSubscriber.php index fedc79d..dace62e 100644 --- a/src/EventSubscriber/HttpCacheEventSubscriber.php +++ b/src/EventSubscriber/HttpCacheEventSubscriber.php @@ -14,274 +14,274 @@ class HttpCacheEventSubscriber implements EventSubscriberInterface { - /** - * @var \SplObjectStorage - */ - private $lastModifiedDates; - - /** - * @var \SplObjectStorage - */ - private $eTags; - - /** - * @var ExpressionLanguage - */ - private $expressionLanguage; - - /** - */ - public function __construct() - { - $this->lastModifiedDates = new \SplObjectStorage(); - $this->eTags = new \SplObjectStorage(); + /** + * @var \SplObjectStorage + */ + private $lastModifiedDates; + + /** + * @var \SplObjectStorage + */ + private $eTags; + + /** + * @var ExpressionLanguage + */ + private $expressionLanguage; + + /** + */ + public function __construct() + { + $this->lastModifiedDates = new \SplObjectStorage(); + $this->eTags = new \SplObjectStorage(); + } + + /** + * Handles HTTP validation headers. + * + * @param FilterControllerEvent $event + */ + public function onKernelController(FilterControllerEvent $event) + { + $request = $event->getRequest(); + if (!$configuration = $this->getConfiguration($request)) { + return; } - /** - * Handles HTTP validation headers. - * - * @param FilterControllerEvent $event - */ - public function onKernelController(FilterControllerEvent $event) - { - $request = $event->getRequest(); - if (!$configuration = $this->getConfiguration($request)) { - return; - } - - $response = new Response(); + $response = new Response(); - if ($configuration->getLastModified()) { - $this->setLastModified($request, $response, $configuration); - } - if ($configuration->getETag()) { - $this->setETag($request, $response, $configuration); - } - if ($response->isNotModified($request)) { - $event->setController( - function () use ($response) { - return $response; - } - ); - $event->stopPropagation(); - } + if ($configuration->getLastModified()) { + $this->setLastModified($request, $response, $configuration); } - - /** - * Modifies the response to apply HTTP cache headers when needed. - * - * @param FilterResponseEvent $event - */ - public function onKernelResponse(FilterResponseEvent $event) - { - $request = $event->getRequest(); - if (!$configuration = $this->getConfiguration($request)) { - return; - } - - $response = $event->getResponse(); - if ($this->hasUncachableStatusCode($response)) { - return; + if ($configuration->getETag()) { + $this->setETag($request, $response, $configuration); + } + if ($response->isNotModified($request)) { + $event->setController( + function () use ($response) { + return $response; } - - $this->setCacheProperties($request, $response, $configuration); + ); + $event->stopPropagation(); } - - /** - * @param Request $request - * @param Response $response - * @param Cache $configuration - */ - protected function setLastModified( - Request $request, - Response $response, - Cache $configuration - ) { - $lastModifiedDate = $this->getExpressionLanguage()->evaluate( - $configuration->getLastModified(), - $request->attributes->all() - ); - $response->setLastModified($lastModifiedDate); - $this->lastModifiedDates[$request] = $lastModifiedDate; + } + + /** + * Modifies the response to apply HTTP cache headers when needed. + * + * @param FilterResponseEvent $event + */ + public function onKernelResponse(FilterResponseEvent $event) + { + $request = $event->getRequest(); + if (!$configuration = $this->getConfiguration($request)) { + return; } - /** - * @param Request $request - * @param Response $response - * @param Cache $configuration - */ - protected function setETag( - Request $request, - Response $response, - Cache $configuration - ) { - $eTag = $this->createETag($request, $configuration); - $response->setETag($eTag); - $this->eTags[$request] = $eTag; + $response = $event->getResponse(); + if ($this->hasUncachableStatusCode($response)) { + return; } - /** - * @param Request $request - * @param Cache $configuration - * - * @return string - */ - protected function createETag(Request $request, Cache $configuration) - { - return hash( - 'sha256', - $this->getExpressionLanguage()->evaluate( - $configuration->getETag(), - $request->attributes->all() - ) - ); + $this->setCacheProperties($request, $response, $configuration); + } + + /** + * @param Request $request + * @param Response $response + * @param Cache $configuration + */ + protected function setLastModified( + Request $request, + Response $response, + Cache $configuration + ) { + $lastModifiedDate = $this->getExpressionLanguage()->evaluate( + $configuration->getLastModified(), + $request->attributes->all() + ); + $response->setLastModified($lastModifiedDate); + $this->lastModifiedDates[$request] = $lastModifiedDate; + } + + /** + * @param Request $request + * @param Response $response + * @param Cache $configuration + */ + protected function setETag( + Request $request, + Response $response, + Cache $configuration + ) { + $eTag = $this->createETag($request, $configuration); + $response->setETag($eTag); + $this->eTags[$request] = $eTag; + } + + /** + * @param Request $request + * @param Cache $configuration + * + * @return string + */ + protected function createETag(Request $request, Cache $configuration) + { + return hash( + 'sha256', + $this->getExpressionLanguage()->evaluate( + $configuration->getETag(), + $request->attributes->all() + ) + ); + } + + /** + * @param $age + * + * @return float + */ + protected function calculateAge($age) + { + $now = microtime(true); + + return ceil(strtotime($age, $now) - $now); + } + + /** + * @param Request $request + * + * @return Cache|false + */ + protected function getConfiguration(Request $request) + { + $configuration = $request->attributes->get('_cache'); + if (empty($configuration) || !$configuration instanceof Cache) { + return false; } - /** - * @param $age - * - * @return float - */ - protected function calculateAge($age) - { - $now = microtime(true); - - return ceil(strtotime($age, $now) - $now); + return $configuration; + } + + /** + * @param Request $request + * @param Response $response + * @param Cache $configuration + */ + protected function setCacheProperties( + Request $request, + Response $response, + Cache $configuration + ) { + if (null !== $age = $configuration->getSMaxAge()) { + if (!is_numeric($age)) { + $age = $this->calculateAge($configuration->getSMaxAge()); + } + + $response->setSharedMaxAge($age); } - /** - * @param Request $request - * - * @return Cache|false - */ - protected function getConfiguration(Request $request) - { - $configuration = $request->attributes->get('_cache'); - if (empty($configuration) || !$configuration instanceof Cache) { - return false; - } + if (null !== $age = $configuration->getMaxAge()) { + if (!is_numeric($age)) { + $age = $this->calculateAge($configuration->getMaxAge()); + } - return $configuration; + $response->setMaxAge($age); } - /** - * @param Request $request - * @param Response $response - * @param Cache $configuration - */ - protected function setCacheProperties( - Request $request, - Response $response, - Cache $configuration - ) { - if (null !== $age = $configuration->getSMaxAge()) { - if (!is_numeric($age)) { - $age = $this->calculateAge($configuration->getSMaxAge()); - } - - $response->setSharedMaxAge($age); - } - - if (null !== $age = $configuration->getMaxAge()) { - if (!is_numeric($age)) { - $age = $this->calculateAge($configuration->getMaxAge()); - } - - $response->setMaxAge($age); - } - - if (null !== $configuration->getExpires()) { - $response->setExpires($this->calculateExpires($configuration)); - } - - if (null !== $configuration->getVary()) { - $response->setVary($configuration->getVary()); - } - - if ($configuration->isPublic()) { - $response->setPublic(); - } - - if ($configuration->isPrivate()) { - $response->setPrivate(); - } - - if (isset($this->lastModifiedDates[$request])) { - $response->setLastModified($this->lastModifiedDates[$request]); - - unset($this->lastModifiedDates[$request]); - } + if (null !== $configuration->getExpires()) { + $response->setExpires($this->calculateExpires($configuration)); + } - if (isset($this->eTags[$request])) { - $response->setETag($this->eTags[$request]); + if (null !== $configuration->getVary()) { + $response->setVary($configuration->getVary()); + } - unset($this->eTags[$request]); - } + if ($configuration->isPublic()) { + $response->setPublic(); } - /** - * @param Cache $configuration - * - * @return bool|\DateTime - */ - protected function calculateExpires(Cache $configuration) - { - return \DateTime::createFromFormat( - 'U', - strtotime($configuration->getExpires()), - new \DateTimeZone('UTC') - ); + if ($configuration->isPrivate()) { + $response->setPrivate(); } - /** - * http://tools.ietf.org/html/draft-ietf-httpbis-p4-conditional-12#section-3.1 - * - * @param Response $response - * - * @return bool - */ - protected function hasUncachableStatusCode(Response $response) - { - if (!in_array( - $response->getStatusCode(), - [200, 203, 300, 301, 302, 304, 404, 410] - )) { - return true; - } + if (isset($this->lastModifiedDates[$request])) { + $response->setLastModified($this->lastModifiedDates[$request]); - return false; + unset($this->lastModifiedDates[$request]); } - /** - * @codeCoverageIgnore - * @return ExpressionLanguage - */ - private function getExpressionLanguage() - { - if (null === $this->expressionLanguage) { - if (!class_exists(ExpressionLanguage::class)) { - throw new \RuntimeException( - 'Unable to use expressions as the Symfony ExpressionLanguage component is not installed.' - ); - } - $this->expressionLanguage = new ExpressionLanguage(); - } + if (isset($this->eTags[$request])) { + $response->setETag($this->eTags[$request]); - return $this->expressionLanguage; + unset($this->eTags[$request]); + } + } + + /** + * @param Cache $configuration + * + * @return bool|\DateTime + */ + protected function calculateExpires(Cache $configuration) + { + return \DateTime::createFromFormat( + 'U', + strtotime($configuration->getExpires()), + new \DateTimeZone('UTC') + ); + } + + /** + * http://tools.ietf.org/html/draft-ietf-httpbis-p4-conditional-12#section-3.1 + * + * @param Response $response + * + * @return bool + */ + protected function hasUncachableStatusCode(Response $response) + { + if (!in_array( + $response->getStatusCode(), + [200, 203, 300, 301, 302, 304, 404, 410] + )) { + return true; } - /** - * @return array - */ - public static function getSubscribedEvents() - { - return [ - KernelEvents::CONTROLLER => [ - ['onKernelController', 0], - ], - KernelEvents::RESPONSE => [ - ['onKernelResponse', 100], - ], - ]; + return false; + } + + /** + * @codeCoverageIgnore + * @return ExpressionLanguage + */ + private function getExpressionLanguage() + { + if (null === $this->expressionLanguage) { + if (!class_exists(ExpressionLanguage::class)) { + throw new \RuntimeException( + 'Unable to use expressions as the Symfony ExpressionLanguage component is not installed.' + ); + } + $this->expressionLanguage = new ExpressionLanguage(); } + + return $this->expressionLanguage; + } + + /** + * @return array + */ + public static function getSubscribedEvents() + { + return [ + KernelEvents::CONTROLLER => [ + ['onKernelController', 0], + ], + KernelEvents::RESPONSE => [ + ['onKernelResponse', 100], + ], + ]; + } } diff --git a/src/EventSubscriber/ParamConverterEventSubscriber.php b/src/EventSubscriber/ParamConverterEventSubscriber.php index 5d3bfff..0b9188c 100644 --- a/src/EventSubscriber/ParamConverterEventSubscriber.php +++ b/src/EventSubscriber/ParamConverterEventSubscriber.php @@ -11,126 +11,126 @@ class ParamConverterEventSubscriber implements EventSubscriberInterface { - /** - * @var ParamConverterManager - */ - protected $manager; - - /** - * @var bool - */ - protected $autoConvert; - - /** - * @var bool - */ - private $isParameterTypeSupported; - - /** - * @param ParamConverterManager $manager A ParamConverterManager instance - * @param bool $autoConvert Auto convert non-configured objects - */ - public function __construct(ParamConverterManager $manager, $autoConvert = true) - { - $this->manager = $manager; - $this->autoConvert = $autoConvert; - $this->isParameterTypeSupported = method_exists('ReflectionParameter', 'getType'); + /** + * @var ParamConverterManager + */ + protected $manager; + + /** + * @var bool + */ + protected $autoConvert; + + /** + * @var bool + */ + private $isParameterTypeSupported; + + /** + * @param ParamConverterManager $manager A ParamConverterManager instance + * @param bool $autoConvert Auto convert non-configured objects + */ + public function __construct(ParamConverterManager $manager, $autoConvert = true) + { + $this->manager = $manager; + $this->autoConvert = $autoConvert; + $this->isParameterTypeSupported = method_exists('ReflectionParameter', 'getType'); + } + + /** + * Modifies the ParamConverterManager instance. + * + * @param FilterControllerEvent $event A FilterControllerEvent instance + */ + public function onKernelController(FilterControllerEvent $event) + { + $controller = $event->getController(); + $request = $event->getRequest(); + $configurations = []; + + if ($configuration = $request->attributes->get('_converters')) { + foreach (is_array($configuration) ? $configuration : [$configuration] as $configuration) { + $configurations[$configuration->getName()] = $configuration; + } } - /** - * Modifies the ParamConverterManager instance. - * - * @param FilterControllerEvent $event A FilterControllerEvent instance - */ - public function onKernelController(FilterControllerEvent $event) - { - $controller = $event->getController(); - $request = $event->getRequest(); - $configurations = []; - - if ($configuration = $request->attributes->get('_converters')) { - foreach (is_array($configuration) ? $configuration : [$configuration] as $configuration) { - $configurations[$configuration->getName()] = $configuration; - } - } - - // automatically apply conversion for non-configured objects - if ($this->autoConvert) { - $configurations = $this->autoConfigure($this->resolveMethod($controller), $request, $configurations); - } - - $this->manager->apply($request, $configurations); + // automatically apply conversion for non-configured objects + if ($this->autoConvert) { + $configurations = $this->autoConfigure($this->resolveMethod($controller), $request, $configurations); } - /** - * @param $controller - * - * @return \ReflectionFunction|\ReflectionMethod - */ - protected function resolveMethod($controller) - { - if (is_array($controller)) { - return new \ReflectionMethod($controller[0], $controller[1]); - } - if (is_object($controller) && is_callable($controller, '__invoke')) { - return new \ReflectionMethod($controller, '__invoke'); - } - - return new \ReflectionFunction($controller); + $this->manager->apply($request, $configurations); + } + + /** + * @param $controller + * + * @return \ReflectionFunction|\ReflectionMethod + */ + protected function resolveMethod($controller) + { + if (is_array($controller)) { + return new \ReflectionMethod($controller[0], $controller[1]); + } + if (is_object($controller) && is_callable($controller, '__invoke')) { + return new \ReflectionMethod($controller, '__invoke'); } - /** - * @param \ReflectionFunctionAbstract $r - * @param \Symfony\Component\HttpFoundation\Request $request - * @param array $configurations - * - * @return array - */ - private function autoConfigure(\ReflectionFunctionAbstract $r, Request $request, $configurations) - { - foreach ($r->getParameters() as $param) { - if ($param->getClass() && $param->getClass()->isInstance($request)) { - continue; - } - - $name = $param->getName(); - $class = $param->getClass(); - $hasType = $this->isParameterTypeSupported && $param->hasType(); - - if ($class || $hasType) { - if (!isset($configurations[$name])) { - $configuration = new ParamConverter([]); - $configuration->setName($name); - - $configurations[$name] = $configuration; - } - - if ($class && null === $configurations[$name]->getClass()) { - $configurations[$name]->setClass($class->getName()); - } - } - - if (isset($configurations[$name])) { - $configurations[$name]->setIsOptional( - $param->isOptional() - || $param->isDefaultValueAvailable() - || $hasType && $param->getType()->allowsNull() - ); - } + return new \ReflectionFunction($controller); + } + + /** + * @param \ReflectionFunctionAbstract $r + * @param \Symfony\Component\HttpFoundation\Request $request + * @param array $configurations + * + * @return array + */ + private function autoConfigure(\ReflectionFunctionAbstract $r, Request $request, $configurations) + { + foreach ($r->getParameters() as $param) { + if ($param->getClass() && $param->getClass()->isInstance($request)) { + continue; + } + + $name = $param->getName(); + $class = $param->getClass(); + $hasType = $this->isParameterTypeSupported && $param->hasType(); + + if ($class || $hasType) { + if (!isset($configurations[$name])) { + $configuration = new ParamConverter([]); + $configuration->setName($name); + + $configurations[$name] = $configuration; } - return $configurations; + if ($class && null === $configurations[$name]->getClass()) { + $configurations[$name]->setClass($class->getName()); + } + } + + if (isset($configurations[$name])) { + $configurations[$name]->setIsOptional( + $param->isOptional() + || $param->isDefaultValueAvailable() + || $hasType && $param->getType()->allowsNull() + ); + } } - /** - * @return array - */ - public static function getSubscribedEvents() - { - return [ - KernelEvents::CONTROLLER => [ - ['onKernelController', 100], - ], - ]; - } + return $configurations; + } + + /** + * @return array + */ + public static function getSubscribedEvents() + { + return [ + KernelEvents::CONTROLLER => [ + ['onKernelController', 100], + ], + ]; + } } diff --git a/src/EventSubscriber/RouteEventSubscriber.php b/src/EventSubscriber/RouteEventSubscriber.php index 506dc24..cc4af84 100644 --- a/src/EventSubscriber/RouteEventSubscriber.php +++ b/src/EventSubscriber/RouteEventSubscriber.php @@ -11,86 +11,86 @@ class RouteEventSubscriber implements EventSubscriberInterface { - /** - * @var AnnotationDirectoryLoader - */ - private $annotationDirectoryLoader; + /** + * @var AnnotationDirectoryLoader + */ + private $annotationDirectoryLoader; - /** - * @var string - */ - private $rootPath; + /** + * @var string + */ + private $rootPath; - /** - * @param AnnotationDirectoryLoader $annotationDirectoryLoader - * @param string $rootPath - */ - public function __construct(AnnotationDirectoryLoader $annotationDirectoryLoader, string $rootPath) - { - $this->registerAnnotations(); - $this->annotationDirectoryLoader = $annotationDirectoryLoader; - $this->rootPath = $rootPath; - } + /** + * @param AnnotationDirectoryLoader $annotationDirectoryLoader + * @param string $rootPath + */ + public function __construct(AnnotationDirectoryLoader $annotationDirectoryLoader, string $rootPath) + { + $this->registerAnnotations(); + $this->annotationDirectoryLoader = $annotationDirectoryLoader; + $this->rootPath = $rootPath; + } - /** - * Configure the annotation registry to make routing annotations available - */ - private function registerAnnotations() - { - AnnotationRegistry::registerLoader('class_exists'); - } + /** + * Configure the annotation registry to make routing annotations available + */ + private function registerAnnotations() + { + AnnotationRegistry::registerLoader('class_exists'); + } + /** + * @param RouteBuildEvent $event + * @throws \Exception + */ + public function onRoutes(RouteBuildEvent $event) + { /** - * @param RouteBuildEvent $event - * @throws \Exception + * @var $route Route */ - public function onRoutes(RouteBuildEvent $event) - { - /** - * @var $route Route - */ - foreach ($event->getRouteCollection() as $name => $route) { - if ($route->hasOption('type') - && $route->getOption('type') === 'annotation' - ) { - $routeCollection = $this->annotationDirectoryLoader->load($this->rootPath.$this->getRoutePath($route)); - $routeCollection->addPrefix($route->getPath()); - - $event->getRouteCollection()->addCollection($routeCollection); - $event->getRouteCollection()->remove($name); - } - } - } + foreach ($event->getRouteCollection() as $name => $route) { + if ($route->hasOption('type') + && $route->getOption('type') === 'annotation' + ) { + $routeCollection = $this->annotationDirectoryLoader->load($this->rootPath.$this->getRoutePath($route)); + $routeCollection->addPrefix($route->getPath()); - /** - * @return array - */ - public static function getSubscribedEvents() - { - return [ - RoutingEvents::DYNAMIC => [ - ['onRoutes', 0], - ], - ]; + $event->getRouteCollection()->addCollection($routeCollection); + $event->getRouteCollection()->remove($name); + } } + } - /** - * @param Route $route - * @return string - * @throws \Exception - */ - protected function getRoutePath(Route $route) - { - if ($route->hasOption('path')) { - $path = $route->getOption('path'); - } elseif ($route->hasOption('module')) { - $path = sprintf('/%s/src/Controller', drupal_get_path('module', $route->getOption('module'))); - } else { - throw new \Exception( - 'Either the "resource" or "module" option is required to load from annotations' - ); - } + /** + * @return array + */ + public static function getSubscribedEvents() + { + return [ + RoutingEvents::DYNAMIC => [ + ['onRoutes', 0], + ], + ]; + } - return $path; + /** + * @param Route $route + * @return string + * @throws \Exception + */ + protected function getRoutePath(Route $route) + { + if ($route->hasOption('path')) { + $path = $route->getOption('path'); + } elseif ($route->hasOption('module')) { + $path = sprintf('/%s/src/Controller', drupal_get_path('module', $route->getOption('module'))); + } else { + throw new \Exception( + 'Either the "resource" or "module" option is required to load from annotations' + ); } + + return $path; + } } diff --git a/src/EventSubscriber/TemplateEventSubscriber.php b/src/EventSubscriber/TemplateEventSubscriber.php index 3c08796..9b672c8 100644 --- a/src/EventSubscriber/TemplateEventSubscriber.php +++ b/src/EventSubscriber/TemplateEventSubscriber.php @@ -15,184 +15,184 @@ class TemplateEventSubscriber implements EventSubscriberInterface { - /** - * @var \Twig_Environment - */ - private $twig; - - /** - * @var TemplateResolver - */ - private $resolver; - - /** - * @param \Twig_Environment $twig - * @param TemplateResolver $resolver - */ - public function __construct(\Twig_Environment $twig, TemplateResolver $resolver) - { - $this->twig = $twig; - $this->resolver = $resolver; + /** + * @var \Twig_Environment + */ + private $twig; + + /** + * @var TemplateResolver + */ + private $resolver; + + /** + * @param \Twig_Environment $twig + * @param TemplateResolver $resolver + */ + public function __construct(\Twig_Environment $twig, TemplateResolver $resolver) + { + $this->twig = $twig; + $this->resolver = $resolver; + } + + /** + * Guesses the template name to render and its variables and adds them to + * the request object. + * + * @param FilterControllerEvent $event A FilterControllerEvent instance + */ + public function onKernelController(FilterControllerEvent $event) + { + $template = $this->getTemplateFromRequest($event); + if (!$template instanceof Template) { + return; } - /** - * Guesses the template name to render and its variables and adds them to - * the request object. - * - * @param FilterControllerEvent $event A FilterControllerEvent instance - */ - public function onKernelController(FilterControllerEvent $event) - { - $template = $this->getTemplateFromRequest($event); - if (!$template instanceof Template) { - return; - } - - $template->setOwner($event->getController()); - $this->normalizeTemplate($template); + $template->setOwner($event->getController()); + $this->normalizeTemplate($template); + } + + /** + * Renders the template and initializes a new response object with the + * rendered template content. + * + * @param GetResponseForControllerResultEvent $event + */ + public function onKernelView(GetResponseForControllerResultEvent $event) + { + $template = $this->getTemplateFromRequest($event); + if (!$template instanceof Template) { + return; } - /** - * Renders the template and initializes a new response object with the - * rendered template content. - * - * @param GetResponseForControllerResultEvent $event - */ - public function onKernelView(GetResponseForControllerResultEvent $event) - { - $template = $this->getTemplateFromRequest($event); - if (!$template instanceof Template) { - return; - } - - $this->setResponse($event, $template, $this->getParameters($event, $template)); + $this->setResponse($event, $template, $this->getParameters($event, $template)); + } + + /** + * @param KernelEvent $event + * @return mixed + */ + private function getTemplateFromRequest(KernelEvent $event) + { + return $event->getRequest()->attributes->get('_template'); + } + + /** + * @param Template $template + */ + private function normalizeTemplate(Template $template) + { + if (is_null($template->getTemplate())) { + $templateFile = $this->resolver->resolveByControllerAndAction( + get_class($template->getOwner()[0]), + $template->getOwner()[1] + ); + } else { + $templateFile = $this->resolver->normalize($template->getTemplate()); } - /** - * @param KernelEvent $event - * @return mixed - */ - private function getTemplateFromRequest(KernelEvent $event) - { - return $event->getRequest()->attributes->get('_template'); + $template->setTemplate($templateFile); + } + + /** + * @param GetResponseForControllerResultEvent $event + * @param Template $template + * @param $parameters + */ + private function setResponse(GetResponseForControllerResultEvent $event, Template $template, $parameters) + { + // make sure the owner (controller+dependencies) is not cached or stored elsewhere + $template->setOwner([]); + + if ($template->isStreamable()) { + $callback = function () use ($template, $parameters) { + $this->twig->display($template->getTemplate(), $parameters); + }; + + $event->setResponse(new StreamedResponse($callback)); + } else { + $event->setResponse(new Response($this->twig->render($template->getTemplate(), $parameters))); } - - /** - * @param Template $template - */ - private function normalizeTemplate(Template $template) - { - if (is_null($template->getTemplate())) { - $templateFile = $this->resolver->resolveByControllerAndAction( - get_class($template->getOwner()[0]), - $template->getOwner()[1] - ); - } else { - $templateFile = $this->resolver->normalize($template->getTemplate()); - } - - $template->setTemplate($templateFile); - } - - /** - * @param GetResponseForControllerResultEvent $event - * @param Template $template - * @param $parameters - */ - private function setResponse(GetResponseForControllerResultEvent $event, Template $template, $parameters) - { - // make sure the owner (controller+dependencies) is not cached or stored elsewhere - $template->setOwner([]); - - if ($template->isStreamable()) { - $callback = function () use ($template, $parameters) { - $this->twig->display($template->getTemplate(), $parameters); - }; - - $event->setResponse(new StreamedResponse($callback)); - } else { - $event->setResponse(new Response($this->twig->render($template->getTemplate(), $parameters))); - } + } + + /** + * @param GetResponseForControllerResultEvent $event + * @param Template $template + * @return array|mixed + */ + private function getParameters(GetResponseForControllerResultEvent $event, Template $template) + { + $parameters = $event->getControllerResult(); + + $owner = $template->getOwner(); + list($controller, $action) = $owner; + + // when the annotation declares no default vars and the action returns + // null, all action method arguments are used as default vars + if (null === $parameters) { + $parameters = $this->resolveDefaultParameters($event->getRequest(), $template, $controller, $action); } - /** - * @param GetResponseForControllerResultEvent $event - * @param Template $template - * @return array|mixed - */ - private function getParameters(GetResponseForControllerResultEvent $event, Template $template) - { - $parameters = $event->getControllerResult(); - - $owner = $template->getOwner(); - list($controller, $action) = $owner; - - // when the annotation declares no default vars and the action returns - // null, all action method arguments are used as default vars - if (null === $parameters) { - $parameters = $this->resolveDefaultParameters($event->getRequest(), $template, $controller, $action); - } - - return $parameters; + return $parameters; + } + + /** + * @param Request $request + * @param Template $template + * @param object $controller + * @param string $action + * @return array + */ + private function resolveDefaultParameters(Request $request, Template $template, $controller, $action) + { + $arguments = $template->getVars(); + + if (0 === count($arguments)) { + $r = new \ReflectionObject($controller); + + $arguments = []; + foreach ($r->getMethod($action)->getParameters() as $param) { + $arguments[] = $param; + } } - /** - * @param Request $request - * @param Template $template - * @param object $controller - * @param string $action - * @return array - */ - private function resolveDefaultParameters(Request $request, Template $template, $controller, $action) - { - $arguments = $template->getVars(); - - if (0 === count($arguments)) { - $r = new \ReflectionObject($controller); - - $arguments = []; - foreach ($r->getMethod($action)->getParameters() as $param) { - $arguments[] = $param; - } - } - - return $this->resolveParametersWithReflection($request, $arguments); + return $this->resolveParametersWithReflection($request, $arguments); + } + + /** + * fetch the arguments of @Template.vars or everything if desired + * and assign them to the designated template + * + * @param Request $request + * @param array $arguments + * @return array + */ + private function resolveParametersWithReflection(Request $request, array $arguments) + { + $parameters = []; + foreach ($arguments as $argument) { + if ($argument instanceof \ReflectionParameter) { + $name = $argument->getName(); + $parameters[$name] = !$request->attributes->has($name) + && $argument->isDefaultValueAvailable() + ? $argument->getDefaultValue() + : $request->attributes->get($name); + } else { + $parameters[$argument] = $request->attributes->get($argument); + } } - /** - * fetch the arguments of @Template.vars or everything if desired - * and assign them to the designated template - * - * @param Request $request - * @param array $arguments - * @return array - */ - private function resolveParametersWithReflection(Request $request, array $arguments) - { - $parameters = []; - foreach ($arguments as $argument) { - if ($argument instanceof \ReflectionParameter) { - $name = $argument->getName(); - $parameters[$name] = !$request->attributes->has($name) - && $argument->isDefaultValueAvailable() - ? $argument->getDefaultValue() - : $request->attributes->get($name); - } else { - $parameters[$argument] = $request->attributes->get($argument); - } - } - - return $parameters; - } - - /** - * @return array - */ - public static function getSubscribedEvents() - { - return [ - KernelEvents::CONTROLLER => ['onKernelController', 100], - KernelEvents::VIEW => ['onKernelView', 10], - ]; - } + return $parameters; + } + + /** + * @return array + */ + public static function getSubscribedEvents() + { + return [ + KernelEvents::CONTROLLER => ['onKernelController', 100], + KernelEvents::VIEW => ['onKernelView', 10], + ]; + } } diff --git a/src/Request/ParamConverter/DateTimeParamConverter.php b/src/Request/ParamConverter/DateTimeParamConverter.php index b38b3c2..7db9f90 100644 --- a/src/Request/ParamConverter/DateTimeParamConverter.php +++ b/src/Request/ParamConverter/DateTimeParamConverter.php @@ -14,62 +14,62 @@ */ class DateTimeParamConverter implements ParamConverterInterface { - /** - * {@inheritdoc} - * - * @throws NotFoundHttpException When invalid date given - */ - public function apply(Request $request, ParamConverter $configuration) - { - $param = $configuration->getName(); - if (!$request->attributes->has($param)) { - return false; - } - - $value = $request->attributes->get($param); - if (!$value && $configuration->isOptional()) { - return false; - } - - $request->attributes->set( - $param, - $this->getDateTime($configuration, $value, $param) - ); + /** + * {@inheritdoc} + * + * @throws NotFoundHttpException When invalid date given + */ + public function apply(Request $request, ParamConverter $configuration) + { + $param = $configuration->getName(); + if (!$request->attributes->has($param)) { + return false; + } - return true; + $value = $request->attributes->get($param); + if (!$value && $configuration->isOptional()) { + return false; } - /** - * @param ParamConverter $configuration - * @param $value - * @param $param - * @return bool|DateTime - * @throws \Exception - */ - protected function getDateTime(ParamConverter $configuration, $value, $param) - { - $options = $configuration->getOptions(); + $request->attributes->set( + $param, + $this->getDateTime($configuration, $value, $param) + ); - if (isset($options['format'])) { - $date = DateTime::createFromFormat($options['format'], $value); - } elseif (false !== strtotime($value)) { - $date = new DateTime($value); - } + return true; + } - if (empty($date)) { - throw new NotFoundHttpException( - sprintf('Invalid date given for parameter "%s".', $param) - ); - } + /** + * @param ParamConverter $configuration + * @param $value + * @param $param + * @return bool|DateTime + * @throws \Exception + */ + protected function getDateTime(ParamConverter $configuration, $value, $param) + { + $options = $configuration->getOptions(); - return $date; + if (isset($options['format'])) { + $date = DateTime::createFromFormat($options['format'], $value); + } elseif (false !== strtotime($value)) { + $date = new DateTime($value); } - /** - * {@inheritdoc} - */ - public function supports(ParamConverter $configuration) - { - return \DateTime::class === $configuration->getClass(); + if (empty($date)) { + throw new NotFoundHttpException( + sprintf('Invalid date given for parameter "%s".', $param) + ); } + + return $date; + } + + /** + * {@inheritdoc} + */ + public function supports(ParamConverter $configuration) + { + return \DateTime::class === $configuration->getClass(); + } } diff --git a/src/Request/ParamConverter/EntityParamConverter.php b/src/Request/ParamConverter/EntityParamConverter.php index 4b1e2fa..bb2dfce 100644 --- a/src/Request/ParamConverter/EntityParamConverter.php +++ b/src/Request/ParamConverter/EntityParamConverter.php @@ -16,98 +16,98 @@ class EntityParamConverter implements ParamConverterInterface { - /** - * @var EntityTypeManagerInterface - */ - private $entityTypeManager; + /** + * @var EntityTypeManagerInterface + */ + private $entityTypeManager; - /** - * @param EntityTypeManagerInterface $entityTypeManager - */ - public function __construct(EntityTypeManagerInterface $entityTypeManager) - { - $this->entityTypeManager = $entityTypeManager; + /** + * @param EntityTypeManagerInterface $entityTypeManager + */ + public function __construct(EntityTypeManagerInterface $entityTypeManager) + { + $this->entityTypeManager = $entityTypeManager; + } + + /** + * @param Request $request + * @param ParamConverter $configuration + * + * @return bool + */ + public function apply(Request $request, ParamConverter $configuration) + { + $param = $configuration->getName(); + if (!$request->attributes->has($param)) { + return false; } - /** - * @param Request $request - * @param ParamConverter $configuration - * - * @return bool - */ - public function apply(Request $request, ParamConverter $configuration) - { - $param = $configuration->getName(); - if (!$request->attributes->has($param)) { - return false; - } + $value = $request->attributes->get($param); + if (!$value && $configuration->isOptional()) { + return false; + } - $value = $request->attributes->get($param); - if (!$value && $configuration->isOptional()) { - return false; - } + $request->attributes->set( + $param, + $this->getNode($value, $configuration) + ); - $request->attributes->set( - $param, - $this->getNode($value, $configuration) - ); + return true; + } - return true; - } + /** + * @param string $value + * @param ParamConverter $configuration + * + * @return EntityInterface|null + */ + protected function getNode($value, ParamConverter $configuration) + { + $node = $this->entityTypeManager->getStorage('node')->load($value); + $this->assertValidNode($configuration, $node); - /** - * @param string $value - * @param ParamConverter $configuration - * - * @return EntityInterface|null - */ - protected function getNode($value, ParamConverter $configuration) - { - $node = $this->entityTypeManager->getStorage('node')->load($value); - $this->assertValidNode($configuration, $node); + return $node; + } - return $node; + /** + * @param ParamConverter $configuration + * @param EntityInterface $node + */ + protected function assertValidNode( + ParamConverter $configuration, + EntityInterface $node = null + ) { + if (is_null($node) && $configuration->isOptional()) { + return; } - - /** - * @param ParamConverter $configuration - * @param EntityInterface $node - */ - protected function assertValidNode( - ParamConverter $configuration, - EntityInterface $node = null - ) { - if (is_null($node) && $configuration->isOptional()) { - return; - } - if (is_null($node)) { - throw new NotFoundHttpException('entity not found.'); - } - $options = $configuration->getOptions(); - if (isset($options['bundle']) && $node->bundle() !== $options['bundle']) { - throw new NotFoundHttpException( - sprintf('%s not found.', $options['bundle']) - ); - } + if (is_null($node)) { + throw new NotFoundHttpException('entity not found.'); } - - /** - * @param ParamConverter $configuration - * - * @return bool - */ - public function supports(ParamConverter $configuration) - { - return in_array( - $configuration->getClass(), - [ - NodeInterface::class, - Node::class, - EntityInterface::class, - Entity::class, - ContentEntityInterface::class, - ContentEntityBase::class, - ] - ); + $options = $configuration->getOptions(); + if (isset($options['bundle']) && $node->bundle() !== $options['bundle']) { + throw new NotFoundHttpException( + sprintf('%s not found.', $options['bundle']) + ); } + } + + /** + * @param ParamConverter $configuration + * + * @return bool + */ + public function supports(ParamConverter $configuration) + { + return in_array( + $configuration->getClass(), + [ + NodeInterface::class, + Node::class, + EntityInterface::class, + Entity::class, + ContentEntityInterface::class, + ContentEntityBase::class, + ] + ); + } } diff --git a/src/Request/ParamConverter/ParamConverterInterface.php b/src/Request/ParamConverter/ParamConverterInterface.php index 14fb4a9..d138b07 100644 --- a/src/Request/ParamConverter/ParamConverterInterface.php +++ b/src/Request/ParamConverter/ParamConverterInterface.php @@ -13,22 +13,22 @@ */ interface ParamConverterInterface { - /** - * Stores the object in the request. - * - * @param Request $request The request - * @param ParamConverter $configuration Contains the name, class and options of the object - * - * @return bool True if the object has been successfully set, else false - */ - public function apply(Request $request, ParamConverter $configuration); + /** + * Stores the object in the request. + * + * @param Request $request The request + * @param ParamConverter $configuration Contains the name, class and options of the object + * + * @return bool True if the object has been successfully set, else false + */ + public function apply(Request $request, ParamConverter $configuration); - /** - * Checks if the object is supported. - * - * @param ParamConverter $configuration Should be an instance of ParamConverter - * - * @return bool True if the object is supported, else false - */ - public function supports(ParamConverter $configuration); + /** + * Checks if the object is supported. + * + * @param ParamConverter $configuration Should be an instance of ParamConverter + * + * @return bool True if the object is supported, else false + */ + public function supports(ParamConverter $configuration); } diff --git a/src/Request/ParamConverter/ParamConverterManager.php b/src/Request/ParamConverter/ParamConverterManager.php index 07826e3..d95f094 100644 --- a/src/Request/ParamConverter/ParamConverterManager.php +++ b/src/Request/ParamConverter/ParamConverterManager.php @@ -12,139 +12,139 @@ */ class ParamConverterManager { - /** - * @var array - */ - protected $converters = []; - - /** - * @var array - */ - protected $namedConverters = []; - - /** - * Applies all converters to the passed configurations and stops when a - * converter is applied it will move on to the next configuration and so on. - * - * @param Request $request - * @param array|object $configurations - */ - public function apply(Request $request, $configurations) - { - if (is_object($configurations)) { - $configurations = [$configurations]; - } - - foreach ($configurations as $configuration) { - $this->applyConverter($request, $configuration); - } + /** + * @var array + */ + protected $converters = []; + + /** + * @var array + */ + protected $namedConverters = []; + + /** + * Applies all converters to the passed configurations and stops when a + * converter is applied it will move on to the next configuration and so on. + * + * @param Request $request + * @param array|object $configurations + */ + public function apply(Request $request, $configurations) + { + if (is_object($configurations)) { + $configurations = [$configurations]; } - /** - * Apply converter on request based on the given configuration. - * - * @param Request $request - * @param ParamConverter $configuration - */ - protected function applyConverter(Request $request, ParamConverter $configuration) - { - $value = $request->attributes->get($configuration->getName()); - $className = $configuration->getClass(); - - // If the value is already an instance of the class we are trying to - // convert it into we should continue as no conversion is required - if (is_object($value) && $value instanceof $className) { - return; - } - - if ($configuration->getConverter()) { - $this->applyNamedConverter($request, $configuration); - - return; - } - - foreach ($this->all() as $converter) { - if ($converter->supports($configuration)) { - if ($converter->apply($request, $configuration)) { - return; - } - } - } + foreach ($configurations as $configuration) { + $this->applyConverter($request, $configuration); + } + } + + /** + * Apply converter on request based on the given configuration. + * + * @param Request $request + * @param ParamConverter $configuration + */ + protected function applyConverter(Request $request, ParamConverter $configuration) + { + $value = $request->attributes->get($configuration->getName()); + $className = $configuration->getClass(); + + // If the value is already an instance of the class we are trying to + // convert it into we should continue as no conversion is required + if (is_object($value) && $value instanceof $className) { + return; } - /** - * @param Request $request - * @param ParamConverter $configuration - */ - protected function applyNamedConverter(Request $request, ParamConverter $configuration) - { - $converterName = $configuration->getConverter(); - if (!isset($this->namedConverters[$converterName])) { - throw new \RuntimeException( - sprintf( - "No converter named '%s' found for conversion of parameter '%s'.", - $converterName, - $configuration->getName() - ) - ); - } + if ($configuration->getConverter()) { + $this->applyNamedConverter($request, $configuration); - $converter = $this->namedConverters[$converterName]; + return; + } - if (!$converter->supports($configuration)) { - throw new \RuntimeException( - sprintf( - "Converter '%s' does not support conversion of parameter '%s'.", - $converterName, - $configuration->getName() - ) - ); + foreach ($this->all() as $converter) { + if ($converter->supports($configuration)) { + if ($converter->apply($request, $configuration)) { + return; } - - $converter->apply($request, $configuration); + } + } + } + + /** + * @param Request $request + * @param ParamConverter $configuration + */ + protected function applyNamedConverter(Request $request, ParamConverter $configuration) + { + $converterName = $configuration->getConverter(); + if (!isset($this->namedConverters[$converterName])) { + throw new \RuntimeException( + sprintf( + "No converter named '%s' found for conversion of parameter '%s'.", + $converterName, + $configuration->getName() + ) + ); } - /** - * Adds a parameter converter. - * - * Converters match either explicitly via $name or by iteration over all - * converters with a $priority. If you pass a $priority = null then the - * added converter will not be part of the iteration chain and can only - * be invoked explicitly. - * - * @param ParamConverterInterface $converter A ParamConverterInterface instance - * @param int $priority The priority (between -10 and 10). - * @param string $name Name of the converter. - */ - public function add(ParamConverterInterface $converter, $priority = 0, $name = null) - { - if ($priority !== null) { - if (!isset($this->converters[$priority])) { - $this->converters[$priority] = []; - } - - $this->converters[$priority][] = $converter; - } + $converter = $this->namedConverters[$converterName]; - if (null !== $name) { - $this->namedConverters[$name] = $converter; - } + if (!$converter->supports($configuration)) { + throw new \RuntimeException( + sprintf( + "Converter '%s' does not support conversion of parameter '%s'.", + $converterName, + $configuration->getName() + ) + ); } - /** - * Returns all registered param converters. - * - * @return array An array of param converters - */ - public function all() - { - krsort($this->converters); - - $converters = array(); - foreach ($this->converters as $all) { - $converters = array_merge($converters, $all); - } + $converter->apply($request, $configuration); + } + + /** + * Adds a parameter converter. + * + * Converters match either explicitly via $name or by iteration over all + * converters with a $priority. If you pass a $priority = null then the + * added converter will not be part of the iteration chain and can only + * be invoked explicitly. + * + * @param ParamConverterInterface $converter A ParamConverterInterface instance + * @param int $priority The priority (between -10 and 10). + * @param string $name Name of the converter. + */ + public function add(ParamConverterInterface $converter, $priority = 0, $name = null) + { + if ($priority !== null) { + if (!isset($this->converters[$priority])) { + $this->converters[$priority] = []; + } + + $this->converters[$priority][] = $converter; + } - return $converters; + if (null !== $name) { + $this->namedConverters[$name] = $converter; } + } + + /** + * Returns all registered param converters. + * + * @return array An array of param converters + */ + public function all() + { + krsort($this->converters); + + $converters = array(); + foreach ($this->converters as $all) { + $converters = array_merge($converters, $all); + } + + return $converters; + } } diff --git a/src/Routing/AnnotatedRouteControllerLoader.php b/src/Routing/AnnotatedRouteControllerLoader.php index e3ed0d9..4c1aaba 100644 --- a/src/Routing/AnnotatedRouteControllerLoader.php +++ b/src/Routing/AnnotatedRouteControllerLoader.php @@ -10,87 +10,87 @@ class AnnotatedRouteControllerLoader extends AnnotationClassLoader { - /** - * @param Route $route - * @param \ReflectionClass $class - * @param \ReflectionMethod $method - * @param mixed $annotation - */ - protected function configureRoute(Route $route, \ReflectionClass $class, \ReflectionMethod $method, $annotation) - { - $this->setController($route, $class, $method); - $this->configureClassAnnotations($route, $class, $method); - $this->configureMethodAnnotations($route, $class, $method); - } - - /** - * @param \ReflectionClass $class - * @return array - */ - protected function getGlobals(\ReflectionClass $class): array - { - $globals = parent::getGlobals($class); + /** + * @param Route $route + * @param \ReflectionClass $class + * @param \ReflectionMethod $method + * @param mixed $annotation + */ + protected function configureRoute(Route $route, \ReflectionClass $class, \ReflectionMethod $method, $annotation) + { + $this->setController($route, $class, $method); + $this->configureClassAnnotations($route, $class, $method); + $this->configureMethodAnnotations($route, $class, $method); + } - foreach ($this->reader->getClassAnnotations($class) as $configuration) { - if ($configuration instanceof Method) { - $globals['methods'] = array_merge($globals['methods'], $configuration->getMethods()); - } - } + /** + * @param \ReflectionClass $class + * @return array + */ + protected function getGlobals(\ReflectionClass $class): array + { + $globals = parent::getGlobals($class); - return $globals; + foreach ($this->reader->getClassAnnotations($class) as $configuration) { + if ($configuration instanceof Method) { + $globals['methods'] = array_merge($globals['methods'], $configuration->getMethods()); + } } - /** - * @param Route $route - * @param \ReflectionClass $class - * @param \ReflectionMethod $method - */ - protected function configureClassAnnotations(Route $route, \ReflectionClass $class, \ReflectionMethod $method) - { - foreach ($this->reader->getClassAnnotations($class) as $configuration) { - if ($configuration instanceof RouteModifierClassInterface) { - $configuration->modifyRouteClass($route, $class, $method); - } - } - } + return $globals; + } - /** - * @param Route $route - * @param \ReflectionClass $class - * @param \ReflectionMethod $method - */ - protected function configureMethodAnnotations(Route $route, \ReflectionClass $class, \ReflectionMethod $method) - { - foreach ($this->reader->getMethodAnnotations($method) as $configuration) { - if ($configuration instanceof RouteModifierMethodInterface) { - $configuration->modifyRouteMethod($route, $class, $method); - } - } + /** + * @param Route $route + * @param \ReflectionClass $class + * @param \ReflectionMethod $method + */ + protected function configureClassAnnotations(Route $route, \ReflectionClass $class, \ReflectionMethod $method) + { + foreach ($this->reader->getClassAnnotations($class) as $configuration) { + if ($configuration instanceof RouteModifierClassInterface) { + $configuration->modifyRouteClass($route, $class, $method); + } } + } - /** - * @param Route $route - * @param \ReflectionClass $class - * @param \ReflectionMethod $method - */ - protected function setController(Route $route, \ReflectionClass $class, \ReflectionMethod $method) - { - $route->setDefault('_controller', $this->getControllerName($class, $method)); + /** + * @param Route $route + * @param \ReflectionClass $class + * @param \ReflectionMethod $method + */ + protected function configureMethodAnnotations(Route $route, \ReflectionClass $class, \ReflectionMethod $method) + { + foreach ($this->reader->getMethodAnnotations($method) as $configuration) { + if ($configuration instanceof RouteModifierMethodInterface) { + $configuration->modifyRouteMethod($route, $class, $method); + } } + } - /** - * @param \ReflectionClass $class - * @param \ReflectionMethod $method - * @return string - */ - protected function getControllerName(\ReflectionClass $class, \ReflectionMethod $method) - { - $annotation = $this->reader->getClassAnnotation($class, $this->routeAnnotationClass); - if ($annotation instanceof \Drupal\controller_annotations\Configuration\Route && $service = $annotation->getService( - )) { - return sprintf('%s:%s', $service, $method->getName()); - } + /** + * @param Route $route + * @param \ReflectionClass $class + * @param \ReflectionMethod $method + */ + protected function setController(Route $route, \ReflectionClass $class, \ReflectionMethod $method) + { + $route->setDefault('_controller', $this->getControllerName($class, $method)); + } - return sprintf('%s::%s', $class->getName(), $method->getName()); + /** + * @param \ReflectionClass $class + * @param \ReflectionMethod $method + * @return string + */ + protected function getControllerName(\ReflectionClass $class, \ReflectionMethod $method) + { + $annotation = $this->reader->getClassAnnotation($class, $this->routeAnnotationClass); + if ($annotation instanceof \Drupal\controller_annotations\Configuration\Route && $service = $annotation->getService( + )) { + return sprintf('%s:%s', $service, $method->getName()); } + + return sprintf('%s::%s', $class->getName(), $method->getName()); + } } diff --git a/src/Templating/TemplateResolver.php b/src/Templating/TemplateResolver.php index 19173ab..4c9fd79 100644 --- a/src/Templating/TemplateResolver.php +++ b/src/Templating/TemplateResolver.php @@ -4,97 +4,97 @@ class TemplateResolver { - /** - * Convert controller class - * "Drupal\\Controller\Controller" - * and controller action - * "Action" - * into template file path: - * "modules//templates/--.html.twig" - * - * @param string $controllerClass - * @param string $action - * @return string - */ - public function resolveByControllerAndAction(string $controllerClass, string $action): string - { - preg_match('/^Drupal\\\(.*)\\\Controller\\\(.*)/', $controllerClass, $data); - if (!empty($data)) { - $module = $data[1]; - $controller = $data[2]; - } else { - throw new \InvalidArgumentException( - sprintf('Controller class "%s" not supported', $controllerClass) - ); - } - - if (preg_match('/^(.+)Controller$/', $controller, $matchController)) { - $controller = $matchController[1]; - } - if (preg_match('/^(.+)Action$/', $action, $matchAction)) { - $action = $matchAction[1]; - } + /** + * Convert controller class + * "Drupal\\Controller\Controller" + * and controller action + * "Action" + * into template file path: + * "modules//templates/--.html.twig" + * + * @param string $controllerClass + * @param string $action + * @return string + */ + public function resolveByControllerAndAction(string $controllerClass, string $action): string + { + preg_match('/^Drupal\\\(.*)\\\Controller\\\(.*)/', $controllerClass, $data); + if (!empty($data)) { + $module = $data[1]; + $controller = $data[2]; + } else { + throw new \InvalidArgumentException( + sprintf('Controller class "%s" not supported', $controllerClass) + ); + } - return $this->format($module, $controller, $action); + if (preg_match('/^(.+)Controller$/', $controller, $matchController)) { + $controller = $matchController[1]; + } + if (preg_match('/^(.+)Action$/', $action, $matchAction)) { + $action = $matchAction[1]; } - /** - * Convert - * ":" - * and - * "::" - * into - * "modules//templates/-(-).html.twig" - * - * @param string $template - * @return string - */ - public function normalize(string $template): string - { - if (preg_match('/^(.+):(.+):(.+)$/', $template, $matches)) { - return $this->format($matches[1], $matches[2], $matches[3]); - } - if (preg_match('/^(.+):(.+)$/', $template, $matches)) { - return $this->format($matches[1], $matches[2]); - } + return $this->format($module, $controller, $action); + } - throw new \InvalidArgumentException( - sprintf('Template pattern "%s" not supported', $template) - ); + /** + * Convert + * ":" + * and + * "::" + * into + * "modules//templates/-(-).html.twig" + * + * @param string $template + * @return string + */ + public function normalize(string $template): string + { + if (preg_match('/^(.+):(.+):(.+)$/', $template, $matches)) { + return $this->format($matches[1], $matches[2], $matches[3]); + } + if (preg_match('/^(.+):(.+)$/', $template, $matches)) { + return $this->format($matches[1], $matches[2]); } - /** - * @param string $module - * @param string $controller - * @param string $action - * @return string - */ - private function format(string $module, string $controller, string $action = null): string - { - $controller = $this->normalizeString($controller); + throw new \InvalidArgumentException( + sprintf('Template pattern "%s" not supported', $template) + ); + } - $templateName = sprintf('%s-%s', $module, $controller); - if (!empty($action)) { - $templateName = sprintf( - '%s-%s', - $templateName, - $this->normalizeString($action) - ); - } + /** + * @param string $module + * @param string $controller + * @param string $action + * @return string + */ + private function format(string $module, string $controller, string $action = null): string + { + $controller = $this->normalizeString($controller); - return sprintf( - '%s/templates/%s.html.twig', - drupal_get_path('module', $module), - $templateName - ); + $templateName = sprintf('%s-%s', $module, $controller); + if (!empty($action)) { + $templateName = sprintf( + '%s-%s', + $templateName, + $this->normalizeString($action) + ); } - /** - * @param string $value - * @return string - */ - private function normalizeString(string $value): string - { - return str_replace('\\', '-', mb_strtolower($value)); - } + return sprintf( + '%s/templates/%s.html.twig', + drupal_get_path('module', $module), + $templateName + ); + } + + /** + * @param string $value + * @return string + */ + private function normalizeString(string $value): string + { + return str_replace('\\', '-', mb_strtolower($value)); + } } diff --git a/tests/modules/controller_annotations_test/src/Controller/AdminController.php b/tests/modules/controller_annotations_test/src/Controller/AdminController.php index efbeb98..1480571 100644 --- a/tests/modules/controller_annotations_test/src/Controller/AdminController.php +++ b/tests/modules/controller_annotations_test/src/Controller/AdminController.php @@ -11,21 +11,21 @@ */ class AdminController extends ControllerBase { - /** - * @Route("admin", admin=true) - * @Security(role="administrator") - */ - public function adminAction() - { - return []; - } + /** + * @Route("admin", admin=true) + * @Security(role="administrator") + */ + public function adminAction() + { + return []; + } - /** - * @Route("normal") - * @Security(role="administrator") - */ - public function normalAction() - { - return []; - } + /** + * @Route("normal") + * @Security(role="administrator") + */ + public function normalAction() + { + return []; + } } diff --git a/tests/modules/controller_annotations_test/src/Controller/BasicController.php b/tests/modules/controller_annotations_test/src/Controller/BasicController.php index 5819085..d5a6365 100644 --- a/tests/modules/controller_annotations_test/src/Controller/BasicController.php +++ b/tests/modules/controller_annotations_test/src/Controller/BasicController.php @@ -12,11 +12,11 @@ */ class BasicController extends ControllerBase { - /** - * @Route("test/basic") - */ - public function basicAction() - { - return new Response('BasicController::basicAction'); - } + /** + * @Route("test/basic") + */ + public function basicAction() + { + return new Response('BasicController::basicAction'); + } } diff --git a/tests/modules/controller_annotations_test/src/Controller/InvokeController.php b/tests/modules/controller_annotations_test/src/Controller/InvokeController.php index da7a6bc..a07bdf2 100644 --- a/tests/modules/controller_annotations_test/src/Controller/InvokeController.php +++ b/tests/modules/controller_annotations_test/src/Controller/InvokeController.php @@ -12,8 +12,8 @@ */ class InvokeController { - public function __invoke() - { - return new Response('InvokeController::__invoke'); - } + public function __invoke() + { + return new Response('InvokeController::__invoke'); + } } diff --git a/tests/modules/controller_annotations_test/src/Controller/MethodController.php b/tests/modules/controller_annotations_test/src/Controller/MethodController.php index d1905d3..b53eabc 100644 --- a/tests/modules/controller_annotations_test/src/Controller/MethodController.php +++ b/tests/modules/controller_annotations_test/src/Controller/MethodController.php @@ -10,33 +10,33 @@ class MethodController extends ControllerBase { - /** - * @Route("test/method") - * @Method("GET") - * @Security(access=true) - */ - public function getAction() - { - return new Response('ClassRouteController::getAction'); - } + /** + * @Route("test/method") + * @Method("GET") + * @Security(access=true) + */ + public function getAction() + { + return new Response('ClassRouteController::getAction'); + } - /** - * @Route("test/method") - * @Method("POST") - * @Security(access=true) - */ - public function postAction() - { - return new Response('ClassRouteController::postAction'); - } + /** + * @Route("test/method") + * @Method("POST") + * @Security(access=true) + */ + public function postAction() + { + return new Response('ClassRouteController::postAction'); + } - /** - * @Route("test/method/multiple") - * @Method({"GET", "POST"}) - * @Security(access=true) - */ - public function getAndPostAction() - { - return new Response('ClassRouteController::getAndPostAction'); - } + /** + * @Route("test/method/multiple") + * @Method({"GET", "POST"}) + * @Security(access=true) + */ + public function getAndPostAction() + { + return new Response('ClassRouteController::getAndPostAction'); + } } diff --git a/tests/modules/controller_annotations_test/src/Controller/ParamConverterController.php b/tests/modules/controller_annotations_test/src/Controller/ParamConverterController.php index ce3cfd6..3b454f6 100644 --- a/tests/modules/controller_annotations_test/src/Controller/ParamConverterController.php +++ b/tests/modules/controller_annotations_test/src/Controller/ParamConverterController.php @@ -14,46 +14,46 @@ class ParamConverterController extends ControllerBase { - /** - * @Route("date/{start}") - * @Security(access=true) - * @ParamConverter() - */ - public function dateAction(\DateTime $start) - { - return new Response($start->format('Y-m-d')); - } + /** + * @Route("date/{start}") + * @Security(access=true) + * @ParamConverter() + */ + public function dateAction(\DateTime $start) + { + return new Response($start->format('Y-m-d')); + } - /** - * @Route("date-format/{start}") - * @Security(access=true) - * @ParamConverter("start", options={"format": "d-m-Y"}) - */ - public function dateFormatAction(\DateTime $start) - { - return new Response($start->format('Y-m-d')); - } + /** + * @Route("date-format/{start}") + * @Security(access=true) + * @ParamConverter("start", options={"format": "d-m-Y"}) + */ + public function dateFormatAction(\DateTime $start) + { + return new Response($start->format('Y-m-d')); + } - /** - * @Route("date-multiple/{start}/{end}") - * @Security(access=true) - * @ParamConverter - */ - public function dateMultipleAction(\DateTime $start, \DateTime $end) - { - return new Response($start->format('Y-m-d').'-'.$end->format('Y-m-d')); - } + /** + * @Route("date-multiple/{start}/{end}") + * @Security(access=true) + * @ParamConverter + */ + public function dateMultipleAction(\DateTime $start, \DateTime $end) + { + return new Response($start->format('Y-m-d').'-'.$end->format('Y-m-d')); + } - /** - * @Route("date-optional/{start}") - * @Security(access=true) - * @ParamConverter() - */ - public function optionalDateAction(\DateTime $start = null) - { - if (empty($start)) { - return new Response('empty'); - } - return new Response($start->format('Y-m-d')); + /** + * @Route("date-optional/{start}") + * @Security(access=true) + * @ParamConverter() + */ + public function optionalDateAction(\DateTime $start = null) + { + if (empty($start)) { + return new Response('empty'); } + return new Response($start->format('Y-m-d')); + } } diff --git a/tests/modules/controller_annotations_test/src/Controller/PrefixedRouteController.php b/tests/modules/controller_annotations_test/src/Controller/PrefixedRouteController.php index 0f1931e..bfbbb63 100644 --- a/tests/modules/controller_annotations_test/src/Controller/PrefixedRouteController.php +++ b/tests/modules/controller_annotations_test/src/Controller/PrefixedRouteController.php @@ -12,21 +12,21 @@ */ class PrefixedRouteController extends ControllerBase { - /** - * @Route - * @Security(access=true) - */ - public function emptyRouteAction() - { - return new Response('PrefixedBasicController::emptyRouteAction'); - } + /** + * @Route + * @Security(access=true) + */ + public function emptyRouteAction() + { + return new Response('PrefixedBasicController::emptyRouteAction'); + } - /** - * @Route("/named", name="named_route") - * @Security(access=true) - */ - public function namedRouteAction() - { - return new Response('PrefixedBasicController::namedRouteAction'); - } + /** + * @Route("/named", name="named_route") + * @Security(access=true) + */ + public function namedRouteAction() + { + return new Response('PrefixedBasicController::namedRouteAction'); + } } diff --git a/tests/modules/controller_annotations_test/src/Controller/SecurityController.php b/tests/modules/controller_annotations_test/src/Controller/SecurityController.php index 831bee0..db34b12 100644 --- a/tests/modules/controller_annotations_test/src/Controller/SecurityController.php +++ b/tests/modules/controller_annotations_test/src/Controller/SecurityController.php @@ -17,75 +17,75 @@ */ class SecurityController extends ControllerBase { - /** - * @Route("access") - * @Security(access=true) - */ - public function accessAction() - { - return new Response('OK'); - } + /** + * @Route("access") + * @Security(access=true) + */ + public function accessAction() + { + return new Response('OK'); + } - /** - * @Route("permission") - * @Security(permission="access content") - */ - public function permissionAction() - { - return new Response('OK'); - } + /** + * @Route("permission") + * @Security(permission="access content") + */ + public function permissionAction() + { + return new Response('OK'); + } - /** - * @Route("role") - * @Security(role="administrator") - */ - public function roleAction() - { - return new Response('OK'); - } + /** + * @Route("role") + * @Security(role="administrator") + */ + public function roleAction() + { + return new Response('OK'); + } - /** - * @Route("entity/{node}") - * @Security(entity="node.view") - */ - public function entityAction(Node $node) - { - return new Response('OK'); - } + /** + * @Route("entity/{node}") + * @Security(entity="node.view") + */ + public function entityAction(Node $node) + { + return new Response('OK'); + } - /** - * @Route("custom") - * @Security(custom="\Drupal\controller_annotations_test\Security\Custom::access") - */ - public function customAction() - { - return new Response('OK'); - } + /** + * @Route("custom") + * @Security(custom="\Drupal\controller_annotations_test\Security\Custom::access") + */ + public function customAction() + { + return new Response('OK'); + } - /** - * @Route("custom-inline") - * @Security(custom="access") - */ - public function customInlineAction() - { - return new Response('OK'); - } + /** + * @Route("custom-inline") + * @Security(custom="access") + */ + public function customInlineAction() + { + return new Response('OK'); + } - /** - * @Route("csrf") - * @Security(access=true, csrf=true) - */ - public function csrfAction() - { - return new Response('OK'); - } + /** + * @Route("csrf") + * @Security(access=true, csrf=true) + */ + public function csrfAction() + { + return new Response('OK'); + } - /** - * @param AccountInterface $account - * @return AccessResult - */ - public function access(AccountInterface $account) - { - return AccessResult::allowedIf($account->id() === 1337); - } + /** + * @param AccountInterface $account + * @return AccessResult + */ + public function access(AccountInterface $account) + { + return AccessResult::allowedIf($account->id() === 1337); + } } diff --git a/tests/modules/controller_annotations_test/src/Controller/ServiceController.php b/tests/modules/controller_annotations_test/src/Controller/ServiceController.php index 61d41a2..16c5e2d 100644 --- a/tests/modules/controller_annotations_test/src/Controller/ServiceController.php +++ b/tests/modules/controller_annotations_test/src/Controller/ServiceController.php @@ -11,12 +11,12 @@ */ class ServiceController { - /** - * @Route("test/service") - * @Security(access=true) - */ - public function getAction() - { - return new Response('ServiceController::getAction'); - } + /** + * @Route("test/service") + * @Security(access=true) + */ + public function getAction() + { + return new Response('ServiceController::getAction'); + } } diff --git a/tests/modules/controller_annotations_test/src/Controller/TemplateController.php b/tests/modules/controller_annotations_test/src/Controller/TemplateController.php index ac76999..a1e0cee 100644 --- a/tests/modules/controller_annotations_test/src/Controller/TemplateController.php +++ b/tests/modules/controller_annotations_test/src/Controller/TemplateController.php @@ -12,67 +12,67 @@ */ class TemplateController extends ControllerBase { - /** - * @Route("empty") - * @Security(access=true) - * @Template - */ - public function emptyAction() - { - } + /** + * @Route("empty") + * @Security(access=true) + * @Template + */ + public function emptyAction() + { + } - /** - * @Route("module-controller") - * @Security(access=true) - * @Template("controller_annotations_test:template") - */ - public function moduleControllerAction() - { - } + /** + * @Route("module-controller") + * @Security(access=true) + * @Template("controller_annotations_test:template") + */ + public function moduleControllerAction() + { + } - /** - * @Route("module-controller-action") - * @Security(access=true) - * @Template("controller_annotations_test:template:action") - */ - public function moduleControllerActionAction() - { - } + /** + * @Route("module-controller-action") + * @Security(access=true) + * @Template("controller_annotations_test:template:action") + */ + public function moduleControllerActionAction() + { + } - /** - * @Route("parameter") - * @Security(access=true) - * @Template - */ - public function parameterAction() - { - return ['parameter' => 'value']; - } + /** + * @Route("parameter") + * @Security(access=true) + * @Template + */ + public function parameterAction() + { + return ['parameter' => 'value']; + } - /** - * @Route("parameter-url/{parameter}") - * @Security(access=true) - * @Template - */ - public function parameterUrlAction($parameter, $default = 'default') - { - } + /** + * @Route("parameter-url/{parameter}") + * @Security(access=true) + * @Template + */ + public function parameterUrlAction($parameter, $default = 'default') + { + } - /** - * @Route("streamable") - * @Security(access=true) - * @Template(isStreamable=true) - */ - public function streamableAction() - { - } + /** + * @Route("streamable") + * @Security(access=true) + * @Template(isStreamable=true) + */ + public function streamableAction() + { + } - /** - * @Route("vars/{name}") - * @Security(access=true) - * @Template() - */ - public function varsAction($name = 'World') - { - } + /** + * @Route("vars/{name}") + * @Security(access=true) + * @Template() + */ + public function varsAction($name = 'World') + { + } } diff --git a/tests/modules/controller_annotations_test/src/Controller/TitleController.php b/tests/modules/controller_annotations_test/src/Controller/TitleController.php index cef3a2c..5022ccd 100644 --- a/tests/modules/controller_annotations_test/src/Controller/TitleController.php +++ b/tests/modules/controller_annotations_test/src/Controller/TitleController.php @@ -13,51 +13,51 @@ class TitleController extends ControllerBase { - /** - * @Route("normal") - * @Security(access=true) - * @Title("Hello World") - */ - public function normalAction() - { - return []; - } - - /** - * @Route("arguments") - * @Security(access=true) - * @Title("Hello @name", arguments={"@name":"MediaMonks"}) - */ - public function argumentsAction() - { - return []; - } - - /** - * @Route("callback") - * @Security(access=true) - * @Title(callback="\Drupal\controller_annotations_test\Title\Custom::title") - */ - public function callbackAction() - { - return []; - } - - /** - * @Route("callback-inline") - * @Security(access=true) - * @Title(callback="title") - */ - public function callbackInlineAction() - { - return []; - } - - /** - * @return string - */ - public function title() - { - return 'Hello Callback Inline'; - } + /** + * @Route("normal") + * @Security(access=true) + * @Title("Hello World") + */ + public function normalAction() + { + return []; + } + + /** + * @Route("arguments") + * @Security(access=true) + * @Title("Hello @name", arguments={"@name":"MediaMonks"}) + */ + public function argumentsAction() + { + return []; + } + + /** + * @Route("callback") + * @Security(access=true) + * @Title(callback="\Drupal\controller_annotations_test\Title\Custom::title") + */ + public function callbackAction() + { + return []; + } + + /** + * @Route("callback-inline") + * @Security(access=true) + * @Title(callback="title") + */ + public function callbackInlineAction() + { + return []; + } + + /** + * @return string + */ + public function title() + { + return 'Hello Callback Inline'; + } } diff --git a/tests/modules/controller_annotations_test/src/Security/Custom.php b/tests/modules/controller_annotations_test/src/Security/Custom.php index 70615da..9de09f5 100644 --- a/tests/modules/controller_annotations_test/src/Security/Custom.php +++ b/tests/modules/controller_annotations_test/src/Security/Custom.php @@ -7,12 +7,12 @@ class Custom { - /** - * @param AccountInterface $account - * @return AccessResult - */ - public function access(AccountInterface $account) - { - return AccessResult::allowedIf($account->id() === 1337); - } + /** + * @param AccountInterface $account + * @return AccessResult + */ + public function access(AccountInterface $account) + { + return AccessResult::allowedIf($account->id() === 1337); + } } diff --git a/tests/modules/controller_annotations_test/src/Title/Custom.php b/tests/modules/controller_annotations_test/src/Title/Custom.php index 48e1912..61f1942 100644 --- a/tests/modules/controller_annotations_test/src/Title/Custom.php +++ b/tests/modules/controller_annotations_test/src/Title/Custom.php @@ -5,11 +5,11 @@ class Custom { - /** - * @return string - */ - public function title() - { - return 'Hello Callback'; - } + /** + * @return string + */ + public function title() + { + return 'Hello Callback'; + } } diff --git a/tests/src/Kernel/AnnotationsTest.php b/tests/src/Kernel/AnnotationsTest.php index 3eabd2b..dc5f72f 100644 --- a/tests/src/Kernel/AnnotationsTest.php +++ b/tests/src/Kernel/AnnotationsTest.php @@ -10,148 +10,148 @@ */ class AnnotationsTest extends KernelTestBase { - public function testRouting() - { - $response = $this->request(Request::create('/test/basic')); - $this->assertEquals('BasicController::basicAction', $response->getContent()); - - $this->assertResponseContents(Request::create('/test/method', 'GET'), 'ClassRouteController::getAction'); - $this->assertResponseContents(Request::create('/test/method', 'POST'), 'ClassRouteController::postAction'); - $this->assertMethodNotAllowed(Request::create('/test/method', 'DELETE')); - - $path = '/test/method/multiple'; - $contents = 'ClassRouteController::getAndPostAction'; - $this->assertResponseContents(Request::create($path, 'GET'), $contents); - $this->assertResponseContents(Request::create($path, 'POST'), $contents); - $this->assertMethodNotAllowed(Request::create($path, 'DELETE')); - - $this->assertResponseContents(Request::create('/test/prefix'), 'PrefixedBasicController::emptyRouteAction'); - $this->assertResponseContents(Request::create('/test/prefix/named'), 'PrefixedBasicController::namedRouteAction'); - - $this->assertResponseContents(Request::create('/test/service'), 'ServiceController::getAction'); - } - - public function testAdmin() - { - $this->assertForbidden(Request::create('/test/admin/admin')); - $this->setAdministratorAccount(); - $this->assertResponseContains(Request::create('/test/admin/admin'), 'currentPathIsAdmin":true'); - } - - public function testNotAdmin() - { - $this->assertForbidden(Request::create('/test/admin/normal')); - $this->setAdministratorAccount(); - $this->assertResponseContains(Request::create('/test/admin/normal'), 'currentPathIsAdmin":false'); - } - - public function testTemplate() - { - $this->setUpTemplate(); - $this->assertResponseContents(Request::create('/test/template/empty'), 'empty'); - $this->assertResponseContents(Request::create('/test/template/module-controller'), 'module-controller'); - $this->assertResponseContents(Request::create('/test/template/module-controller-action'), 'module-controller-action'); - $this->assertResponseContents(Request::create('/test/template/parameter'), 'value'); - $this->assertResponseContents(Request::create('/test/template/parameter-url/foo'), 'foo default'); - $this->assertResponseContents(Request::create('/test/template/streamable'), 'streamed'); - $this->assertResponseContents(Request::create('/test/template/vars/Monk'), 'Hello Monk'); + public function testRouting() + { + $response = $this->request(Request::create('/test/basic')); + $this->assertEquals('BasicController::basicAction', $response->getContent()); + + $this->assertResponseContents(Request::create('/test/method', 'GET'), 'ClassRouteController::getAction'); + $this->assertResponseContents(Request::create('/test/method', 'POST'), 'ClassRouteController::postAction'); + $this->assertMethodNotAllowed(Request::create('/test/method', 'DELETE')); + + $path = '/test/method/multiple'; + $contents = 'ClassRouteController::getAndPostAction'; + $this->assertResponseContents(Request::create($path, 'GET'), $contents); + $this->assertResponseContents(Request::create($path, 'POST'), $contents); + $this->assertMethodNotAllowed(Request::create($path, 'DELETE')); + + $this->assertResponseContents(Request::create('/test/prefix'), 'PrefixedBasicController::emptyRouteAction'); + $this->assertResponseContents(Request::create('/test/prefix/named'), 'PrefixedBasicController::namedRouteAction'); + + $this->assertResponseContents(Request::create('/test/service'), 'ServiceController::getAction'); + } + + public function testAdmin() + { + $this->assertForbidden(Request::create('/test/admin/admin')); + $this->setAdministratorAccount(); + $this->assertResponseContains(Request::create('/test/admin/admin'), 'currentPathIsAdmin":true'); + } + + public function testNotAdmin() + { + $this->assertForbidden(Request::create('/test/admin/normal')); + $this->setAdministratorAccount(); + $this->assertResponseContains(Request::create('/test/admin/normal'), 'currentPathIsAdmin":false'); + } + + public function testTemplate() + { + $this->setUpTemplate(); + $this->assertResponseContents(Request::create('/test/template/empty'), 'empty'); + $this->assertResponseContents(Request::create('/test/template/module-controller'), 'module-controller'); + $this->assertResponseContents(Request::create('/test/template/module-controller-action'), 'module-controller-action'); + $this->assertResponseContents(Request::create('/test/template/parameter'), 'value'); + $this->assertResponseContents(Request::create('/test/template/parameter-url/foo'), 'foo default'); + $this->assertResponseContents(Request::create('/test/template/streamable'), 'streamed'); + $this->assertResponseContents(Request::create('/test/template/vars/Monk'), 'Hello Monk'); + } + + private function setUpTemplate() + { + $sourceModule = $this->getDrupalRoot() . '/modules/controller_annotations/tests/modules/controller_annotations_test/templates/'; + + if (!file_exists($sourceModule)) { + $this->markTestSkipped('Test module can not be located'); } - private function setUpTemplate() - { - $sourceModule = $this->getDrupalRoot() . '/modules/controller_annotations/tests/modules/controller_annotations_test/templates/'; - - if (!file_exists($sourceModule)) { - $this->markTestSkipped('Test module can not be located'); - } - - $destinationModule = $this->getDrupalRoot() . '/modules/controller_annotations_test/templates/'; - - if (!file_exists($destinationModule)) { - mkdir($destinationModule, 0777, true); - } - foreach (new \DirectoryIterator($sourceModule) as $fileInfo) { - if (!$fileInfo->isFile()) { - continue; - } - copy($sourceModule . $fileInfo->getFilename(), $destinationModule . $fileInfo->getFilename()); - } - } + $destinationModule = $this->getDrupalRoot() . '/modules/controller_annotations_test/templates/'; - public function testSecurity() - { - // all access - $this->assertResponseContents(Request::create('/test/security/access'), 'OK'); - - // only access with "access content" permission - $this->assertForbidden(Request::create('/test/security/permission')); - $this->setAccount(new UserSession([ - 'uid' => 2, - 'permissions' => ['foo'] - ])); - $this->assertForbidden(Request::create('/test/security/permission')); - $this->setAccount(new UserSession([ - 'uid' => 2, - 'permissions' => ['access content'] - ])); - - $this->assertResponseContents(Request::create('/test/security/permission'), 'OK'); - $this->setAdministratorAccount(); - $this->assertResponseContents(Request::create('/test/security/permission'), 'OK'); - - // only access with "administrator" role - $this->setAnonymousAccount(); - $this->assertForbidden(Request::create('/test/security/role')); - $this->setAuthenticatedAccount(); - $this->assertForbidden(Request::create('/test/security/role')); - $this->setAdministratorAccount(); - $this->assertResponseContents(Request::create('/test/security/role'), 'OK'); - - // custom - $this->setAnonymousAccount(); - $this->assertForbidden(Request::create('/test/security/custom')); - $this->setAuthenticatedAccount(); - $this->assertForbidden(Request::create('/test/security/custom')); - $this->setAdministratorAccount(); - $this->assertForbidden(Request::create('/test/security/custom')); - $this->setAccount(new UserSession([ - 'uid' => 1337 - ])); - $this->assertResponseContents(Request::create('/test/security/custom'), 'OK'); - - // custom inline - $this->setAnonymousAccount(); - $this->assertForbidden(Request::create('/test/security/custom-inline')); - $this->setAuthenticatedAccount(); - $this->assertForbidden(Request::create('/test/security/custom-inline')); - $this->setAdministratorAccount(); - $this->assertForbidden(Request::create('/test/security/custom-inline')); - $this->setAccount(new UserSession([ - 'uid' => 1337 - ])); - $this->assertResponseContents(Request::create('/test/security/custom-inline'), 'OK'); - - // csrf - $this->assertForbidden(Request::create('/test/security/csrf')); - $this->assertResponseContents(Request::create('/test/security/csrf', 'GET', [ - 'token' => $this->kernel->getContainer()->get('csrf_token')->get('test/security/csrf') - ]), 'OK'); + if (!file_exists($destinationModule)) { + mkdir($destinationModule, 0777, true); } - - public function testTitle() - { - $this->assertTitleStartsWith(Request::create('/test/title/normal'), 'Hello World'); - $this->assertTitleStartsWith(Request::create('/test/title/arguments'), 'Hello MediaMonks'); - $this->assertTitleStartsWith(Request::create('/test/title/callback'), 'Hello Callback'); - $this->assertTitleStartsWith(Request::create('/test/title/callback-inline'), 'Hello Callback Inline'); - } - - public function testParamConverter() - { - $this->assertResponseContents(Request::create('/test/param-converter/date/2017-08-15'), '2017-08-15'); - $this->assertResponseContents(Request::create('/test/param-converter/date-format/15-08-2017'), '2017-08-15'); - $this->assertResponseContents(Request::create('/test/param-converter/date-multiple/14-08-2017/15-08-2017'), '2017-08-14-2017-08-15'); - $this->assertResponseContents(Request::create('/test/param-converter/date-optional/03-04-1985'), '1985-04-03'); - $this->assertResponseContents(Request::create('/test/param-converter/date-optional'), 'empty'); + foreach (new \DirectoryIterator($sourceModule) as $fileInfo) { + if (!$fileInfo->isFile()) { + continue; + } + copy($sourceModule . $fileInfo->getFilename(), $destinationModule . $fileInfo->getFilename()); } + } + + public function testSecurity() + { + // all access + $this->assertResponseContents(Request::create('/test/security/access'), 'OK'); + + // only access with "access content" permission + $this->assertForbidden(Request::create('/test/security/permission')); + $this->setAccount(new UserSession([ + 'uid' => 2, + 'permissions' => ['foo'] + ])); + $this->assertForbidden(Request::create('/test/security/permission')); + $this->setAccount(new UserSession([ + 'uid' => 2, + 'permissions' => ['access content'] + ])); + + $this->assertResponseContents(Request::create('/test/security/permission'), 'OK'); + $this->setAdministratorAccount(); + $this->assertResponseContents(Request::create('/test/security/permission'), 'OK'); + + // only access with "administrator" role + $this->setAnonymousAccount(); + $this->assertForbidden(Request::create('/test/security/role')); + $this->setAuthenticatedAccount(); + $this->assertForbidden(Request::create('/test/security/role')); + $this->setAdministratorAccount(); + $this->assertResponseContents(Request::create('/test/security/role'), 'OK'); + + // custom + $this->setAnonymousAccount(); + $this->assertForbidden(Request::create('/test/security/custom')); + $this->setAuthenticatedAccount(); + $this->assertForbidden(Request::create('/test/security/custom')); + $this->setAdministratorAccount(); + $this->assertForbidden(Request::create('/test/security/custom')); + $this->setAccount(new UserSession([ + 'uid' => 1337 + ])); + $this->assertResponseContents(Request::create('/test/security/custom'), 'OK'); + + // custom inline + $this->setAnonymousAccount(); + $this->assertForbidden(Request::create('/test/security/custom-inline')); + $this->setAuthenticatedAccount(); + $this->assertForbidden(Request::create('/test/security/custom-inline')); + $this->setAdministratorAccount(); + $this->assertForbidden(Request::create('/test/security/custom-inline')); + $this->setAccount(new UserSession([ + 'uid' => 1337 + ])); + $this->assertResponseContents(Request::create('/test/security/custom-inline'), 'OK'); + + // csrf + $this->assertForbidden(Request::create('/test/security/csrf')); + $this->assertResponseContents(Request::create('/test/security/csrf', 'GET', [ + 'token' => $this->kernel->getContainer()->get('csrf_token')->get('test/security/csrf') + ]), 'OK'); + } + + public function testTitle() + { + $this->assertTitleStartsWith(Request::create('/test/title/normal'), 'Hello World'); + $this->assertTitleStartsWith(Request::create('/test/title/arguments'), 'Hello MediaMonks'); + $this->assertTitleStartsWith(Request::create('/test/title/callback'), 'Hello Callback'); + $this->assertTitleStartsWith(Request::create('/test/title/callback-inline'), 'Hello Callback Inline'); + } + + public function testParamConverter() + { + $this->assertResponseContents(Request::create('/test/param-converter/date/2017-08-15'), '2017-08-15'); + $this->assertResponseContents(Request::create('/test/param-converter/date-format/15-08-2017'), '2017-08-15'); + $this->assertResponseContents(Request::create('/test/param-converter/date-multiple/14-08-2017/15-08-2017'), '2017-08-14-2017-08-15'); + $this->assertResponseContents(Request::create('/test/param-converter/date-optional/03-04-1985'), '1985-04-03'); + $this->assertResponseContents(Request::create('/test/param-converter/date-optional'), 'empty'); + } } diff --git a/tests/src/Kernel/DrupalTestKernel.php b/tests/src/Kernel/DrupalTestKernel.php index 1a9c4e7..1f86632 100644 --- a/tests/src/Kernel/DrupalTestKernel.php +++ b/tests/src/Kernel/DrupalTestKernel.php @@ -8,23 +8,23 @@ class DrupalTestKernel extends DrupalKernel { - /** - * {@inheritdoc} - */ - public function setSitePath($path) - { - if (empty($this->sitePath)) { - parent::setSitePath($path); - } + /** + * {@inheritdoc} + */ + public function setSitePath($path) + { + if (empty($this->sitePath)) { + parent::setSitePath($path); } + } - /** - * @param Request $request - */ - protected function initializeSettings(Request $request) - { - $settings = Settings::getAll(); - parent::initializeSettings($request); - new Settings($settings); - } + /** + * @param Request $request + */ + protected function initializeSettings(Request $request) + { + $settings = Settings::getAll(); + parent::initializeSettings($request); + new Settings($settings); + } } diff --git a/tests/src/Kernel/KernelTestBase.php b/tests/src/Kernel/KernelTestBase.php index dd643f4..ff2b5c6 100644 --- a/tests/src/Kernel/KernelTestBase.php +++ b/tests/src/Kernel/KernelTestBase.php @@ -13,140 +13,140 @@ abstract class KernelTestBase extends BaseKernelTestBase { - /** - * @var DrupalKernel - */ - protected $kernel; - - /** - * @var array - */ - public static $modules = ['controller_annotations', 'controller_annotations_test', 'user', 'system', 'node']; - - /** - * @param Request $request - * @param $contents - */ - protected function assertResponseContents(Request $request, $contents) - { - $response = $this->request($request); - if ($response instanceof StreamedResponse) { - ob_start(); - $response->sendContent(); - $actual = ob_get_contents(); - ob_end_clean(); - } - else { - $actual = $response->getContent(); - } - - $this->assertEquals($contents, trim($actual)); + /** + * @var DrupalKernel + */ + protected $kernel; + + /** + * @var array + */ + public static $modules = ['controller_annotations', 'controller_annotations_test', 'user', 'system', 'node']; + + /** + * @param Request $request + * @param $contents + */ + protected function assertResponseContents(Request $request, $contents) + { + $response = $this->request($request); + if ($response instanceof StreamedResponse) { + ob_start(); + $response->sendContent(); + $actual = ob_get_contents(); + ob_end_clean(); } - - /** - * @param Request $request - * @param $contents - */ - protected function assertResponseContains(Request $request, $contents) - { - $response = $this->request($request); - //echo $response->getContent(); - $this->assertTrue(strpos($response->getContent(), $contents) !== false); - } - - /** - * @param Request $request - * @param $contents - */ - protected function assertResponseNotContains(Request $request, $contents) - { - $response = $this->request($request); - $this->assertTrue(strpos($response->getContent(), $contents) === false); - } - - /** - * @param Request $request - */ - protected function assertNotFound(Request $request) - { - $response = $this->request($request); - $this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode()); - } - - /** - * @param Request $request - */ - protected function assertMethodNotAllowed(Request $request) - { - $response = $this->request($request); - $this->assertEquals(Response::HTTP_METHOD_NOT_ALLOWED, $response->getStatusCode()); - } - - /** - * @param Request $request - */ - protected function assertForbidden(Request $request) - { - $response = $this->request($request); - $this->assertEquals(Response::HTTP_FORBIDDEN, $response->getStatusCode()); + else { + $actual = $response->getContent(); } - /** - * @param Request $request - */ - protected function assertTitleStartsWith(Request $request, $title) - { - $this->assertResponseContains($request, ''.$title); + $this->assertEquals($contents, trim($actual)); + } + + /** + * @param Request $request + * @param $contents + */ + protected function assertResponseContains(Request $request, $contents) + { + $response = $this->request($request); + //echo $response->getContent(); + $this->assertTrue(strpos($response->getContent(), $contents) !== false); + } + + /** + * @param Request $request + * @param $contents + */ + protected function assertResponseNotContains(Request $request, $contents) + { + $response = $this->request($request); + $this->assertTrue(strpos($response->getContent(), $contents) === false); + } + + /** + * @param Request $request + */ + protected function assertNotFound(Request $request) + { + $response = $this->request($request); + $this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode()); + } + + /** + * @param Request $request + */ + protected function assertMethodNotAllowed(Request $request) + { + $response = $this->request($request); + $this->assertEquals(Response::HTTP_METHOD_NOT_ALLOWED, $response->getStatusCode()); + } + + /** + * @param Request $request + */ + protected function assertForbidden(Request $request) + { + $response = $this->request($request); + $this->assertEquals(Response::HTTP_FORBIDDEN, $response->getStatusCode()); + } + + /** + * @param Request $request + */ + protected function assertTitleStartsWith(Request $request, $title) + { + $this->assertResponseContains($request, '<title>'.$title); + } + + /** + * @param Request $request + * @return Response + */ + protected function request(Request $request) + { + if (empty($this->kernel)) { + $this->kernel = DrupalTestKernel::createFromRequest($request, $this->classLoader, 'prod'); } - /** - * @param Request $request - * @return Response - */ - protected function request(Request $request) - { - if (empty($this->kernel)) { - $this->kernel = DrupalTestKernel::createFromRequest($request, $this->classLoader, 'prod'); - } - - return $this->kernel->handle($request); - } - - /** - * - */ - protected function setAnonymousAccount() - { - $this->setAccount(new AnonymousUserSession()); - } - - /** - * - */ - protected function setAuthenticatedAccount() - { - $this->setAccount(new UserSession([ - 'uid' => 2, - 'roles' => ['authenticated'] - ])); - } - - /** - * - */ - protected function setAdministratorAccount() - { - $this->setAccount(new UserSession([ - 'uid' => 1, - 'roles' => ['administrator', 'authenticated'] - ])); - } - - /** - * @param AccountInterface $account - */ - protected function setAccount(AccountInterface $account) - { - $this->kernel->getContainer()->get('current_user')->setAccount($account); - } + return $this->kernel->handle($request); + } + + /** + * + */ + protected function setAnonymousAccount() + { + $this->setAccount(new AnonymousUserSession()); + } + + /** + * + */ + protected function setAuthenticatedAccount() + { + $this->setAccount(new UserSession([ + 'uid' => 2, + 'roles' => ['authenticated'] + ])); + } + + /** + * + */ + protected function setAdministratorAccount() + { + $this->setAccount(new UserSession([ + 'uid' => 1, + 'roles' => ['administrator', 'authenticated'] + ])); + } + + /** + * @param AccountInterface $account + */ + protected function setAccount(AccountInterface $account) + { + $this->kernel->getContainer()->get('current_user')->setAccount($account); + } } diff --git a/tests/src/Kernel/TestUserSession.php b/tests/src/Kernel/TestUserSession.php index 947eb18..078ea64 100644 --- a/tests/src/Kernel/TestUserSession.php +++ b/tests/src/Kernel/TestUserSession.php @@ -6,21 +6,21 @@ class TestUserSession extends UserSession { - /** - * @var array - */ - protected $permissions = []; + /** + * @var array + */ + protected $permissions = []; - /** - * {@inheritdoc} - */ - public function hasPermission($permission) - { - // User #1 has all privileges. - if ((int) $this->id() === 1) { - return true; - } - - return in_array($permission, $this->permissions); + /** + * {@inheritdoc} + */ + public function hasPermission($permission) + { + // User #1 has all privileges. + if ((int) $this->id() === 1) { + return true; } + + return in_array($permission, $this->permissions); + } } diff --git a/tests/src/Unit/Cache/DrupalCacheTest.php b/tests/src/Unit/Cache/DrupalCacheTest.php index 0b16279..ebfde33 100644 --- a/tests/src/Unit/Cache/DrupalCacheTest.php +++ b/tests/src/Unit/Cache/DrupalCacheTest.php @@ -10,96 +10,96 @@ class DrupalCacheTest extends UnitTestCase { - public function testDoFetch() - { - $drupalCache = $this->getDrupalCacheMock(); - $drupalCache->shouldReceive('get')->once()->withArgs(['[foo][1]'])->andReturn($this->getCacheData('bar')); - - $cache = new DrupalCache($drupalCache); - - $this->assertEquals('bar', $cache->fetch('foo')); - } - - public function testDoContains() - { - $drupalCache = $this->getDrupalCacheMock(); - $drupalCache->shouldReceive('get')->once()->withArgs(['[foo][1]'])->andReturn($this->getCacheData('bar')); - $drupalCache->shouldReceive('get')->once()->withArgs(['[bar][1]'])->andReturn(false); - - $cache = new DrupalCache($drupalCache); - $this->assertTrue($cache->contains('foo')); - $this->assertFalse($cache->contains('bar')); - } - - public function testSave() - { - $drupalCache = $this->getDrupalCacheMock(); - $drupalCache->shouldReceive('set')->once()->withArgs(['[foo][1]', 'bar'])->andReturnNull(); - $drupalCache->shouldReceive('set')->once()->withArgs(['[foo][1]', 'bar', m::any()])->andReturnNull(); - - $cache = new DrupalCache($drupalCache); - $this->assertTrue($cache->save('foo', 'bar')); - $this->assertTrue($cache->save('foo', 'bar', 1)); - - m::close(); - } - - public function testDelete() - { - $drupalCache = $this->getDrupalCacheMock(); - $drupalCache->shouldReceive('delete')->once()->withArgs(['[foo][1]'])->andReturnNull(); - - $cache = new DrupalCache($drupalCache); - - $this->assertTrue($cache->delete('foo')); - } - - public function testFlushAll() - { - $drupalCache = $this->getDrupalCacheMock(); - $drupalCache->shouldReceive('deleteAll')->once()->withNoArgs()->andReturnNull(); - - $cache = new DrupalCache($drupalCache); - - $this->assertTrue($cache->flushAll()); - } - - public function testGetStats() - { - $drupalCache = $this->getDrupalCacheMock(); - $cache = new DrupalCache($drupalCache); - - $this->assertNull($cache->getStats()); - } - - /** - * @return CacheBackendInterface - */ - protected function getDrupalCacheMock() - { - $drupalCache = m::mock(CacheBackendInterface::class); - $drupalCache->shouldReceive('get')->withArgs(['DoctrineNamespaceCacheKey[]'])->andReturnNull(); - - return $drupalCache; - } - - /** - * @param $data - * - * @return StdClass - */ - protected function getCacheData($data) - { - $cacheData = new StdClass(); - $cacheData->data = $data; - - return $cacheData; - } - - protected function tearDown() - { - m::close(); - - parent::tearDown(); - } + public function testDoFetch() + { + $drupalCache = $this->getDrupalCacheMock(); + $drupalCache->shouldReceive('get')->once()->withArgs(['[foo][1]'])->andReturn($this->getCacheData('bar')); + + $cache = new DrupalCache($drupalCache); + + $this->assertEquals('bar', $cache->fetch('foo')); + } + + public function testDoContains() + { + $drupalCache = $this->getDrupalCacheMock(); + $drupalCache->shouldReceive('get')->once()->withArgs(['[foo][1]'])->andReturn($this->getCacheData('bar')); + $drupalCache->shouldReceive('get')->once()->withArgs(['[bar][1]'])->andReturn(false); + + $cache = new DrupalCache($drupalCache); + $this->assertTrue($cache->contains('foo')); + $this->assertFalse($cache->contains('bar')); + } + + public function testSave() + { + $drupalCache = $this->getDrupalCacheMock(); + $drupalCache->shouldReceive('set')->once()->withArgs(['[foo][1]', 'bar'])->andReturnNull(); + $drupalCache->shouldReceive('set')->once()->withArgs(['[foo][1]', 'bar', m::any()])->andReturnNull(); + + $cache = new DrupalCache($drupalCache); + $this->assertTrue($cache->save('foo', 'bar')); + $this->assertTrue($cache->save('foo', 'bar', 1)); + + m::close(); + } + + public function testDelete() + { + $drupalCache = $this->getDrupalCacheMock(); + $drupalCache->shouldReceive('delete')->once()->withArgs(['[foo][1]'])->andReturnNull(); + + $cache = new DrupalCache($drupalCache); + + $this->assertTrue($cache->delete('foo')); + } + + public function testFlushAll() + { + $drupalCache = $this->getDrupalCacheMock(); + $drupalCache->shouldReceive('deleteAll')->once()->withNoArgs()->andReturnNull(); + + $cache = new DrupalCache($drupalCache); + + $this->assertTrue($cache->flushAll()); + } + + public function testGetStats() + { + $drupalCache = $this->getDrupalCacheMock(); + $cache = new DrupalCache($drupalCache); + + $this->assertNull($cache->getStats()); + } + + /** + * @return CacheBackendInterface + */ + protected function getDrupalCacheMock() + { + $drupalCache = m::mock(CacheBackendInterface::class); + $drupalCache->shouldReceive('get')->withArgs(['DoctrineNamespaceCacheKey[]'])->andReturnNull(); + + return $drupalCache; + } + + /** + * @param $data + * + * @return StdClass + */ + protected function getCacheData($data) + { + $cacheData = new StdClass(); + $cacheData->data = $data; + + return $cacheData; + } + + protected function tearDown() + { + m::close(); + + parent::tearDown(); + } } diff --git a/tests/src/Unit/Configuration/CacheTest.php b/tests/src/Unit/Configuration/CacheTest.php index 7f73d74..2d3abf0 100644 --- a/tests/src/Unit/Configuration/CacheTest.php +++ b/tests/src/Unit/Configuration/CacheTest.php @@ -7,51 +7,51 @@ class CacheTest extends UnitTestCase { - public function testProperties() - { - $cache = new Cache([]); + public function testProperties() + { + $cache = new Cache([]); - $cache->setExpires('tomorrow'); - $this->assertEquals('tomorrow', $cache->getExpires()); + $cache->setExpires('tomorrow'); + $this->assertEquals('tomorrow', $cache->getExpires()); - $cache->setMaxAge(60); - $this->assertEquals(60, $cache->getMaxAge()); + $cache->setMaxAge(60); + $this->assertEquals(60, $cache->getMaxAge()); - $cache->setSMaxAge(120); - $this->assertEquals(120, $cache->getSMaxAge()); + $cache->setSMaxAge(120); + $this->assertEquals(120, $cache->getSMaxAge()); - $this->assertFalse($cache->isPublic()); - $this->assertFalse($cache->isPrivate()); + $this->assertFalse($cache->isPublic()); + $this->assertFalse($cache->isPrivate()); - $cache->setPublic(true); - $this->assertTrue($cache->isPublic()); - $this->assertFalse($cache->isPrivate()); + $cache->setPublic(true); + $this->assertTrue($cache->isPublic()); + $this->assertFalse($cache->isPrivate()); - $cache->setPublic(false); - $this->assertFalse($cache->isPublic()); - $this->assertTrue($cache->isPrivate()); + $cache->setPublic(false); + $this->assertFalse($cache->isPublic()); + $this->assertTrue($cache->isPrivate()); - $cache->setVary('vary'); - $this->assertEquals('vary', $cache->getVary()); + $cache->setVary('vary'); + $this->assertEquals('vary', $cache->getVary()); - $cache->setETag('foobar'); - $this->assertEquals('foobar', $cache->getETag()); + $cache->setETag('foobar'); + $this->assertEquals('foobar', $cache->getETag()); - $cache->setLastModified('yesterday'); - $this->assertEquals('yesterday', $cache->getLastModified()); - } + $cache->setLastModified('yesterday'); + $this->assertEquals('yesterday', $cache->getLastModified()); + } - public function testGetAliasName() - { - $cache = new Cache([]); + public function testGetAliasName() + { + $cache = new Cache([]); - $this->assertEquals('cache', $cache->getAliasName()); - } + $this->assertEquals('cache', $cache->getAliasName()); + } - public function testAllowArray() - { - $cache = new Cache([]); + public function testAllowArray() + { + $cache = new Cache([]); - $this->assertFalse($cache->allowArray()); - } + $this->assertFalse($cache->allowArray()); + } } diff --git a/tests/src/Unit/Configuration/MethodTest.php b/tests/src/Unit/Configuration/MethodTest.php index 8a532fe..e62ce35 100644 --- a/tests/src/Unit/Configuration/MethodTest.php +++ b/tests/src/Unit/Configuration/MethodTest.php @@ -9,49 +9,49 @@ class MethodTest extends UnitTestCase { - public function testModifyRouteClass() - { - $route = m::mock(Route::class); - $route->shouldReceive('setMethods')->once()->withArgs([['GET', 'POST']]); + public function testModifyRouteClass() + { + $route = m::mock(Route::class); + $route->shouldReceive('setMethods')->once()->withArgs([['GET', 'POST']]); - $class = m::mock(\ReflectionClass::class); - $method = m::mock(\ReflectionMethod::class); + $class = m::mock(\ReflectionClass::class); + $method = m::mock(\ReflectionMethod::class); - $methodConfig = new Method(['methods' => ['GET', 'POST']]); - $this->assertNull($methodConfig->modifyRouteClass($route, $class, $method)); + $methodConfig = new Method(['methods' => ['GET', 'POST']]); + $this->assertNull($methodConfig->modifyRouteClass($route, $class, $method)); - m::close(); - } + m::close(); + } - public function testModifyRouteMethod() - { - $route = m::mock(Route::class); - $route->shouldReceive('setMethods')->once()->withArgs([['GET', 'POST']]); + public function testModifyRouteMethod() + { + $route = m::mock(Route::class); + $route->shouldReceive('setMethods')->once()->withArgs([['GET', 'POST']]); - $class = m::mock(\ReflectionClass::class); - $method = m::mock(\ReflectionMethod::class); + $class = m::mock(\ReflectionClass::class); + $method = m::mock(\ReflectionMethod::class); - $methodConfig = new Method(['methods' => ['GET', 'POST']]); - $this->assertNull($methodConfig->modifyRouteMethod($route, $class, $method)); + $methodConfig = new Method(['methods' => ['GET', 'POST']]); + $this->assertNull($methodConfig->modifyRouteMethod($route, $class, $method)); - m::close(); - } + m::close(); + } - public function testModify() - { - $route = m::mock(Route::class); - $route->shouldReceive('setMethods')->once()->withArgs([['GET']]); - $route->shouldReceive('setMethods')->once()->withArgs([['POST']]); + public function testModify() + { + $route = m::mock(Route::class); + $route->shouldReceive('setMethods')->once()->withArgs([['GET']]); + $route->shouldReceive('setMethods')->once()->withArgs([['POST']]); - $class = m::mock(\ReflectionClass::class); - $method = m::mock(\ReflectionMethod::class); + $class = m::mock(\ReflectionClass::class); + $method = m::mock(\ReflectionMethod::class); - $methodConfig = new Method(['methods' => ['GET']]); - $this->assertNull($methodConfig->modifyRouteClass($route, $class, $method)); + $methodConfig = new Method(['methods' => ['GET']]); + $this->assertNull($methodConfig->modifyRouteClass($route, $class, $method)); - $methodConfig = new Method(['methods' => ['POST']]); - $this->assertNull($methodConfig->modifyRouteMethod($route, $class, $method)); + $methodConfig = new Method(['methods' => ['POST']]); + $this->assertNull($methodConfig->modifyRouteMethod($route, $class, $method)); - m::close(); - } + m::close(); + } } diff --git a/tests/src/Unit/Configuration/RouteTest.php b/tests/src/Unit/Configuration/RouteTest.php index 3d22965..4c53615 100644 --- a/tests/src/Unit/Configuration/RouteTest.php +++ b/tests/src/Unit/Configuration/RouteTest.php @@ -9,57 +9,57 @@ class RouteTest extends UnitTestCase { - public function testModifyRouteClass() - { - $route = m::mock(Route::class); - $route->shouldReceive('setOption')->once()->withArgs(['_admin_route', true]); + public function testModifyRouteClass() + { + $route = m::mock(Route::class); + $route->shouldReceive('setOption')->once()->withArgs(['_admin_route', true]); - $class = m::mock(\ReflectionClass::class); - $method = m::mock(\ReflectionMethod::class); + $class = m::mock(\ReflectionClass::class); + $method = m::mock(\ReflectionMethod::class); - $routeConfig = new RouteConfiguration(['admin' => true]); - $this->assertNull($routeConfig->modifyRouteClass($route, $class, $method)); + $routeConfig = new RouteConfiguration(['admin' => true]); + $this->assertNull($routeConfig->modifyRouteClass($route, $class, $method)); - m::close(); - } + m::close(); + } - public function testModifyMethodClass() - { - $route = m::mock(Route::class); + public function testModifyMethodClass() + { + $route = m::mock(Route::class); - $class = m::mock(\ReflectionClass::class); - $method = m::mock(\ReflectionMethod::class); + $class = m::mock(\ReflectionClass::class); + $method = m::mock(\ReflectionMethod::class); - $routeConfig = new RouteConfiguration([]); - $this->assertNull($routeConfig->modifyRouteMethod($route, $class, $method)); + $routeConfig = new RouteConfiguration([]); + $this->assertNull($routeConfig->modifyRouteMethod($route, $class, $method)); - m::close(); - } + m::close(); + } - public function testServiceNotAllowedOnMethodLevel() - { - $this->setExpectedException(\LogicException::class); + public function testServiceNotAllowedOnMethodLevel() + { + $this->setExpectedException(\LogicException::class); - $route = m::mock(Route::class); + $route = m::mock(Route::class); - $class = m::mock(\ReflectionClass::class); - $method = m::mock(\ReflectionMethod::class); + $class = m::mock(\ReflectionClass::class); + $method = m::mock(\ReflectionMethod::class); - $routeConfig = new RouteConfiguration(['service' => 'foo']); - $this->assertNull($routeConfig->modifyRouteMethod($route, $class, $method)); + $routeConfig = new RouteConfiguration(['service' => 'foo']); + $this->assertNull($routeConfig->modifyRouteMethod($route, $class, $method)); - m::close(); - } + m::close(); + } - public function testAllowArray() - { - $routeConfig = new RouteConfiguration([]); - $this->assertTrue($routeConfig->allowArray()); - } + public function testAllowArray() + { + $routeConfig = new RouteConfiguration([]); + $this->assertTrue($routeConfig->allowArray()); + } - public function testUnknownProperty() - { - $this->setExpectedException(\BadMethodCallException::class); - new RouteConfiguration(['foo' => 'bar']); - } + public function testUnknownProperty() + { + $this->setExpectedException(\BadMethodCallException::class); + new RouteConfiguration(['foo' => 'bar']); + } } diff --git a/tests/src/Unit/Configuration/SecurityTest.php b/tests/src/Unit/Configuration/SecurityTest.php index 74235d1..f374956 100644 --- a/tests/src/Unit/Configuration/SecurityTest.php +++ b/tests/src/Unit/Configuration/SecurityTest.php @@ -9,47 +9,47 @@ class SecurityTest extends UnitTestCase { - public function testModifyRouteMethod() - { - $route = m::mock(Route::class); - $route->shouldReceive('setRequirement')->once()->withArgs(['_access', true]); - $route->shouldReceive('setRequirement')->once()->withArgs(['_permission', 'permission']); - $route->shouldReceive('setRequirement')->once()->withArgs(['_role', 'role']); - $route->shouldReceive('setRequirement')->once()->withArgs(['_entity_access', 'entity']); - $route->shouldReceive('setRequirement')->once()->withArgs(['_csrf_token', true]); - $route->shouldReceive('setRequirement')->once()->withArgs(['_custom_access', 'foo::custom']); - - $class = m::mock(\ReflectionClass::class); - $method = m::mock(\ReflectionMethod::class); - - $security = new Security([ - 'access' => true, - 'permission' => 'permission', - 'role' => 'role', - 'entity' => 'entity', - 'csrf' => true, - 'custom' => 'foo::custom' - ]); - $this->assertNull($security->modifyRouteMethod($route, $class, $method)); - - m::close(); - } - - public function testModifyRouteMethodInlineAccess() - { - $route = m::mock(Route::class); - $route->shouldReceive('setRequirement')->once()->withArgs(['_custom_access', 'foo::custom']); - - $class = m::mock(\ReflectionClass::class); - $class->shouldReceive('hasMethod')->andReturn('custom'); - $class->shouldReceive('getName')->andReturn('foo'); - $method = m::mock(\ReflectionMethod::class); - - $security = new Security([ - 'custom' => 'custom' - ]); - $this->assertNull($security->modifyRouteMethod($route, $class, $method)); - - m::close(); - } + public function testModifyRouteMethod() + { + $route = m::mock(Route::class); + $route->shouldReceive('setRequirement')->once()->withArgs(['_access', true]); + $route->shouldReceive('setRequirement')->once()->withArgs(['_permission', 'permission']); + $route->shouldReceive('setRequirement')->once()->withArgs(['_role', 'role']); + $route->shouldReceive('setRequirement')->once()->withArgs(['_entity_access', 'entity']); + $route->shouldReceive('setRequirement')->once()->withArgs(['_csrf_token', true]); + $route->shouldReceive('setRequirement')->once()->withArgs(['_custom_access', 'foo::custom']); + + $class = m::mock(\ReflectionClass::class); + $method = m::mock(\ReflectionMethod::class); + + $security = new Security([ + 'access' => true, + 'permission' => 'permission', + 'role' => 'role', + 'entity' => 'entity', + 'csrf' => true, + 'custom' => 'foo::custom' + ]); + $this->assertNull($security->modifyRouteMethod($route, $class, $method)); + + m::close(); + } + + public function testModifyRouteMethodInlineAccess() + { + $route = m::mock(Route::class); + $route->shouldReceive('setRequirement')->once()->withArgs(['_custom_access', 'foo::custom']); + + $class = m::mock(\ReflectionClass::class); + $class->shouldReceive('hasMethod')->andReturn('custom'); + $class->shouldReceive('getName')->andReturn('foo'); + $method = m::mock(\ReflectionMethod::class); + + $security = new Security([ + 'custom' => 'custom' + ]); + $this->assertNull($security->modifyRouteMethod($route, $class, $method)); + + m::close(); + } } diff --git a/tests/src/Unit/Configuration/TitleTest.php b/tests/src/Unit/Configuration/TitleTest.php index 11f0e7e..f48d372 100644 --- a/tests/src/Unit/Configuration/TitleTest.php +++ b/tests/src/Unit/Configuration/TitleTest.php @@ -9,49 +9,49 @@ class TitleTest extends UnitTestCase { - public function testModifyRouteMethod() - { - $route = m::mock(Route::class); - $route->shouldReceive('setDefault')->once()->withArgs(['_title', 'Hello World']); - $route->shouldReceive('setDefault')->once()->withArgs(['_title_arguments', ['arguments' => true]]); - $route->shouldReceive('setDefault')->once()->withArgs(['_title_context', ['context' => true]]); - $route->shouldReceive('setDefault')->once()->withArgs(['_title_callback', 'foo::callback']); - - $class = m::mock(\ReflectionClass::class); - $method = m::mock(\ReflectionMethod::class); - - $security = new Title([ - 'value' => 'Hello World', - 'arguments' => ['arguments' => true], - 'context' => ['context' => true], - 'callback' => 'foo::callback' - ]); - $this->assertNull($security->modifyRouteMethod($route, $class, $method)); - - m::close(); - } - - public function testModifyRouteMethodInlineAccess() - { - $route = m::mock(Route::class); - $route->shouldReceive('setDefault')->once()->withArgs(['_title_callback', 'foo::callback']); - - $class = m::mock(\ReflectionClass::class); - $class->shouldReceive('hasMethod')->andReturn('callback'); - $class->shouldReceive('getName')->andReturn('foo'); - $method = m::mock(\ReflectionMethod::class); - - $security = new Title([ - 'callback' => 'callback' - ]); - $this->assertNull($security->modifyRouteClass($route, $class, $method)); - - m::close(); - } - - public function testUnknownProperty() - { - $this->setExpectedException(\RuntimeException::class); - new Title(['foo' => 'bar']); - } + public function testModifyRouteMethod() + { + $route = m::mock(Route::class); + $route->shouldReceive('setDefault')->once()->withArgs(['_title', 'Hello World']); + $route->shouldReceive('setDefault')->once()->withArgs(['_title_arguments', ['arguments' => true]]); + $route->shouldReceive('setDefault')->once()->withArgs(['_title_context', ['context' => true]]); + $route->shouldReceive('setDefault')->once()->withArgs(['_title_callback', 'foo::callback']); + + $class = m::mock(\ReflectionClass::class); + $method = m::mock(\ReflectionMethod::class); + + $security = new Title([ + 'value' => 'Hello World', + 'arguments' => ['arguments' => true], + 'context' => ['context' => true], + 'callback' => 'foo::callback' + ]); + $this->assertNull($security->modifyRouteMethod($route, $class, $method)); + + m::close(); + } + + public function testModifyRouteMethodInlineAccess() + { + $route = m::mock(Route::class); + $route->shouldReceive('setDefault')->once()->withArgs(['_title_callback', 'foo::callback']); + + $class = m::mock(\ReflectionClass::class); + $class->shouldReceive('hasMethod')->andReturn('callback'); + $class->shouldReceive('getName')->andReturn('foo'); + $method = m::mock(\ReflectionMethod::class); + + $security = new Title([ + 'callback' => 'callback' + ]); + $this->assertNull($security->modifyRouteClass($route, $class, $method)); + + m::close(); + } + + public function testUnknownProperty() + { + $this->setExpectedException(\RuntimeException::class); + new Title(['foo' => 'bar']); + } } diff --git a/tests/src/Unit/EventSubscriber/ControllerEventSubscriberTest.php b/tests/src/Unit/EventSubscriber/ControllerEventSubscriberTest.php index ec15ce1..e79412b 100644 --- a/tests/src/Unit/EventSubscriber/ControllerEventSubscriberTest.php +++ b/tests/src/Unit/EventSubscriber/ControllerEventSubscriberTest.php @@ -16,109 +16,109 @@ */ class ControllerEventSubscriberTest extends UnitTestCase { - public function testOnKernelController() - { - $reader = m::mock(Reader::class); - - $eventSubscriber = new ControllerEventSubscriber($reader); - - $event = m::mock(FilterControllerEvent::class); - $event->shouldReceive('getController')->once()->andReturn(null); - - $this->assertNull($eventSubscriber->onKernelController($event)); - } - - public function testControllerInvoke() - { - $reader = m::mock(Reader::class); - $reader->shouldReceive('getClassAnnotations')->andReturn([]); - $reader->shouldReceive('getMethodAnnotations')->andReturn([]); - - $eventSubscriber = new ControllerEventSubscriber($reader); - - $event = m::mock(FilterControllerEvent::class); - $event->shouldReceive('getController')->once()->andReturn(new ControllerInvokableController); - $event->shouldReceive('getRequest')->once()->andReturn(new Request); - - $this->assertNull($eventSubscriber->onKernelController($event)); - } - - public function testMultipleConfigurations() - { - $configuration = m::mock(ConfigurationInterface::class); - $configuration->shouldReceive('allowArray')->andReturn(true); - $configuration->shouldReceive('getAliasName')->andReturn('foo'); - - $reader = m::mock(Reader::class); - $reader->shouldReceive('getClassAnnotations')->andReturn([ - $configuration, - $configuration - ]); - $reader->shouldReceive('getMethodAnnotations')->andReturn([]); - - $eventSubscriber = new ControllerEventSubscriber($reader); - - $event = m::mock(FilterControllerEvent::class); - $event->shouldReceive('getController')->once()->andReturn(new ControllerInvokableController); - $event->shouldReceive('getRequest')->once()->andReturn(new Request); - - $this->assertNull($eventSubscriber->onKernelController($event)); - } - - public function testMergeConfigurations() - { - $classConfigurations = [ - 'foo' => 'bar' - ]; - $methodConfigurations = [ - 'foo' => 'bar' - ]; - - $reader = m::mock(Reader::class); - $method = Helper::getProtectedMethod(ControllerEventSubscriber::class, 'mergeConfigurations'); - $eventSubscriber = new ControllerEventSubscriber($reader); - $result = $method->invokeArgs($eventSubscriber, [$classConfigurations, $methodConfigurations]); - $this->assertEquals(['foo' => 'bar'], $result); - } - - public function testMergeConfigurationsArray() - { - $classConfigurations = [ - 'foo' => ['bar'] - ]; - $methodConfigurations = [ - 'foo' => ['baz'] - ]; - - $reader = m::mock(Reader::class); - $method = Helper::getProtectedMethod(ControllerEventSubscriber::class, 'mergeConfigurations'); - $eventSubscriber = new ControllerEventSubscriber($reader); - $result = $method->invokeArgs($eventSubscriber, [$classConfigurations, $methodConfigurations]); - - $this->assertEquals(['foo' => ['bar', 'baz']], $result); - } - - public function testMergeConfigurationsMismatch() - { - $this->setExpectedException(\UnexpectedValueException::class); - - $classConfigurations = [ - 'foo' => ['bar'] - ]; - $methodConfigurations = [ - 'foo' => 'bar' - ]; - - $reader = m::mock(Reader::class); - $method = Helper::getProtectedMethod(ControllerEventSubscriber::class, 'mergeConfigurations'); - $eventSubscriber = new ControllerEventSubscriber($reader); - $method->invokeArgs($eventSubscriber, [$classConfigurations, $methodConfigurations]); - } + public function testOnKernelController() + { + $reader = m::mock(Reader::class); + + $eventSubscriber = new ControllerEventSubscriber($reader); + + $event = m::mock(FilterControllerEvent::class); + $event->shouldReceive('getController')->once()->andReturn(null); + + $this->assertNull($eventSubscriber->onKernelController($event)); + } + + public function testControllerInvoke() + { + $reader = m::mock(Reader::class); + $reader->shouldReceive('getClassAnnotations')->andReturn([]); + $reader->shouldReceive('getMethodAnnotations')->andReturn([]); + + $eventSubscriber = new ControllerEventSubscriber($reader); + + $event = m::mock(FilterControllerEvent::class); + $event->shouldReceive('getController')->once()->andReturn(new ControllerInvokableController); + $event->shouldReceive('getRequest')->once()->andReturn(new Request); + + $this->assertNull($eventSubscriber->onKernelController($event)); + } + + public function testMultipleConfigurations() + { + $configuration = m::mock(ConfigurationInterface::class); + $configuration->shouldReceive('allowArray')->andReturn(true); + $configuration->shouldReceive('getAliasName')->andReturn('foo'); + + $reader = m::mock(Reader::class); + $reader->shouldReceive('getClassAnnotations')->andReturn([ + $configuration, + $configuration + ]); + $reader->shouldReceive('getMethodAnnotations')->andReturn([]); + + $eventSubscriber = new ControllerEventSubscriber($reader); + + $event = m::mock(FilterControllerEvent::class); + $event->shouldReceive('getController')->once()->andReturn(new ControllerInvokableController); + $event->shouldReceive('getRequest')->once()->andReturn(new Request); + + $this->assertNull($eventSubscriber->onKernelController($event)); + } + + public function testMergeConfigurations() + { + $classConfigurations = [ + 'foo' => 'bar' + ]; + $methodConfigurations = [ + 'foo' => 'bar' + ]; + + $reader = m::mock(Reader::class); + $method = Helper::getProtectedMethod(ControllerEventSubscriber::class, 'mergeConfigurations'); + $eventSubscriber = new ControllerEventSubscriber($reader); + $result = $method->invokeArgs($eventSubscriber, [$classConfigurations, $methodConfigurations]); + $this->assertEquals(['foo' => 'bar'], $result); + } + + public function testMergeConfigurationsArray() + { + $classConfigurations = [ + 'foo' => ['bar'] + ]; + $methodConfigurations = [ + 'foo' => ['baz'] + ]; + + $reader = m::mock(Reader::class); + $method = Helper::getProtectedMethod(ControllerEventSubscriber::class, 'mergeConfigurations'); + $eventSubscriber = new ControllerEventSubscriber($reader); + $result = $method->invokeArgs($eventSubscriber, [$classConfigurations, $methodConfigurations]); + + $this->assertEquals(['foo' => ['bar', 'baz']], $result); + } + + public function testMergeConfigurationsMismatch() + { + $this->setExpectedException(\UnexpectedValueException::class); + + $classConfigurations = [ + 'foo' => ['bar'] + ]; + $methodConfigurations = [ + 'foo' => 'bar' + ]; + + $reader = m::mock(Reader::class); + $method = Helper::getProtectedMethod(ControllerEventSubscriber::class, 'mergeConfigurations'); + $eventSubscriber = new ControllerEventSubscriber($reader); + $method->invokeArgs($eventSubscriber, [$classConfigurations, $methodConfigurations]); + } } class ControllerInvokableController { - public function __invoke() - { - } + public function __invoke() + { + } } diff --git a/tests/src/Unit/EventSubscriber/HttpCacheListenerTest.php b/tests/src/Unit/EventSubscriber/HttpCacheListenerTest.php index 7e34e29..92b0778 100644 --- a/tests/src/Unit/EventSubscriber/HttpCacheListenerTest.php +++ b/tests/src/Unit/EventSubscriber/HttpCacheListenerTest.php @@ -12,249 +12,249 @@ class HttpCacheListenerTest extends UnitTestCase { - public function setUp() - { - $this->listener = new HttpCacheEventSubscriber(); - $this->response = new Response(); - $this->cache = new Cache(array()); - $this->request = $this->createRequest($this->cache); - $this->event = $this->createEventMock($this->request, $this->response); - } - - public function testWontReassignResponseWhenResponseIsUnsuccessful() - { - $this->event - ->expects($this->never()) - ->method('setResponse') - ; - - $this->response->setStatusCode(500); - - $this->assertInternalType('null', $this->listener->onKernelResponse($this->event)); - } - - public function testWontReassignResponseWhenNoConfigurationIsPresent() - { - $this->event - ->expects($this->never()) - ->method('setResponse') - ; - - $this->request->attributes->remove('_cache'); - - $this->assertInternalType('null', $this->listener->onKernelResponse($this->event)); - } - - public function testResponseIsPublicIfConfigurationIsPublicTrue() - { - $request = $this->createRequest(new Cache(array( - 'public' => true, + public function setUp() + { + $this->listener = new HttpCacheEventSubscriber(); + $this->response = new Response(); + $this->cache = new Cache(array()); + $this->request = $this->createRequest($this->cache); + $this->event = $this->createEventMock($this->request, $this->response); + } + + public function testWontReassignResponseWhenResponseIsUnsuccessful() + { + $this->event + ->expects($this->never()) + ->method('setResponse') + ; + + $this->response->setStatusCode(500); + + $this->assertInternalType('null', $this->listener->onKernelResponse($this->event)); + } + + public function testWontReassignResponseWhenNoConfigurationIsPresent() + { + $this->event + ->expects($this->never()) + ->method('setResponse') + ; + + $this->request->attributes->remove('_cache'); + + $this->assertInternalType('null', $this->listener->onKernelResponse($this->event)); + } + + public function testResponseIsPublicIfConfigurationIsPublicTrue() + { + $request = $this->createRequest(new Cache(array( + 'public' => true, + ))); + + $this->listener->onKernelResponse($this->createEventMock($request, $this->response)); + + $this->assertTrue($this->response->headers->hasCacheControlDirective('public')); + $this->assertFalse($this->response->headers->hasCacheControlDirective('private')); + } + + public function testResponseIsPrivateIfConfigurationIsPublicFalse() + { + $request = $this->createRequest(new Cache(array( + 'public' => false, ))); - $this->listener->onKernelResponse($this->createEventMock($request, $this->response)); - - $this->assertTrue($this->response->headers->hasCacheControlDirective('public')); - $this->assertFalse($this->response->headers->hasCacheControlDirective('private')); - } - - public function testResponseIsPrivateIfConfigurationIsPublicFalse() - { - $request = $this->createRequest(new Cache(array( - 'public' => false, - ))); - - $this->listener->onKernelResponse($this->createEventMock($request, $this->response)); - - $this->assertFalse($this->response->headers->hasCacheControlDirective('public')); - $this->assertTrue($this->response->headers->hasCacheControlDirective('private')); - } - - public function testResponseVary() - { - $vary = array('foobar'); - $request = $this->createRequest(new Cache(array('vary' => $vary))); - - $this->listener->onKernelResponse($this->createEventMock($request, $this->response)); - $this->assertTrue($this->response->hasVary()); - $result = $this->response->getVary(); - $this->assertEquals($vary, $result); - } - - public function testResponseVaryWhenVaryNotSet() - { - $request = $this->createRequest(new Cache(array())); - $vary = array('foobar'); - $this->response->setVary($vary); - - $this->listener->onKernelResponse($this->createEventMock($request, $this->response)); - $this->assertTrue($this->response->hasVary()); - $result = $this->response->getVary(); - $this->assertFalse(empty($result), 'Existing vary headers should not be removed'); - $this->assertEquals($vary, $result, 'Vary header should not be changed'); - } - - public function testResponseIsPrivateIfConfigurationIsPublicNotSet() - { - $request = $this->createRequest(new Cache(array())); - - $this->listener->onKernelResponse($this->createEventMock($request, $this->response)); - - $this->assertFalse($this->response->headers->hasCacheControlDirective('public')); - } - - public function testConfigurationAttributesAreSetOnResponse() - { - $this->assertInternalType('null', $this->response->getMaxAge()); - $this->assertInternalType('null', $this->response->getExpires()); - $this->assertFalse($this->response->headers->hasCacheControlDirective('s-maxage')); - - $this->request->attributes->set('_cache', new Cache(array( - 'expires' => 'tomorrow', - 'smaxage' => '15', - 'maxage' => '15', - ))); - - $this->listener->onKernelResponse($this->event); - - $this->assertEquals('15', $this->response->getMaxAge()); - $this->assertEquals('15', $this->response->headers->getCacheControlDirective('s-maxage')); - $this->assertInstanceOf('DateTime', $this->response->getExpires()); - } - - public function testCacheMaxAgeSupportsStrtotimeFormat() - { - $this->request->attributes->set('_cache', new Cache(array( - 'smaxage' => '1 day', - 'maxage' => '1 day', - ))); - - $this->listener->onKernelResponse($this->event); - - $this->assertEquals(60 * 60 * 24, $this->response->headers->getCacheControlDirective('s-maxage')); - $this->assertEquals(60 * 60 * 24, $this->response->getMaxAge()); - } - - public function testLastModifiedNotModifiedResponse() - { - $request = $this->createRequest(new Cache(array('lastModified' => 'test.getDate()'))); - $request->attributes->set('test', new TestEntity()); - $request->headers->add(array('If-Modified-Since' => 'Fri, 23 Aug 2013 00:00:00 GMT')); - - $listener = new HttpCacheEventSubscriber(); - $controllerEvent = new FilterControllerEvent($this->getKernel(), function () { - return new Response(500); - }, $request, null); - - $listener->onKernelController($controllerEvent); - $response = call_user_func($controllerEvent->getController()); - - $this->assertEquals(304, $response->getStatusCode()); - } - - public function testLastModifiedHeader() - { - $request = $this->createRequest(new Cache(array('lastModified' => 'test.getDate()'))); - $request->attributes->set('test', new TestEntity()); - $response = new Response(); - - $listener = new HttpCacheEventSubscriber(); - $controllerEvent = new FilterControllerEvent($this->getKernel(), function () { - return new Response(); - }, $request, null); - $listener->onKernelController($controllerEvent); - - $responseEvent = new FilterResponseEvent($this->getKernel(), $request, null, call_user_func($controllerEvent->getController())); - $listener->onKernelResponse($responseEvent); - - $response = $responseEvent->getResponse(); - - $this->assertEquals(200, $response->getStatusCode()); - $this->assertTrue($response->headers->has('Last-Modified')); - $this->assertEquals('Fri, 23 Aug 2013 00:00:00 GMT', $response->headers->get('Last-Modified')); - } - - public function testETagNotModifiedResponse() - { - $request = $this->createRequest(new Cache(array('etag' => 'test.getId()'))); - $request->attributes->set('test', $entity = new TestEntity()); - $request->headers->add(array('If-None-Match' => sprintf('"%s"', hash('sha256', $entity->getId())))); - - $listener = new HttpCacheEventSubscriber(); - $controllerEvent = new FilterControllerEvent($this->getKernel(), function () { - return new Response(500); - }, $request, null); - - $listener->onKernelController($controllerEvent); - $response = call_user_func($controllerEvent->getController()); - - $this->assertEquals(304, $response->getStatusCode()); - } - - public function testETagHeader() - { - $request = $this->createRequest(new Cache(array('ETag' => 'test.getId()'))); - $request->attributes->set('test', $entity = new TestEntity()); - $response = new Response(); - - $listener = new HttpCacheEventSubscriber(); - $controllerEvent = new FilterControllerEvent($this->getKernel(), function () { - return new Response(); - }, $request, null); - $listener->onKernelController($controllerEvent); - - $responseEvent = new FilterResponseEvent($this->getKernel(), $request, null, call_user_func($controllerEvent->getController())); - $listener->onKernelResponse($responseEvent); - - $response = $responseEvent->getResponse(); - - $this->assertEquals(200, $response->getStatusCode()); - $this->assertTrue($response->headers->has('ETag')); - $this->assertContains(hash('sha256', $entity->getId()), $response->headers->get('ETag')); - } - - private function createRequest(Cache $cache = null) - { - return new Request(array(), array(), array( - '_cache' => $cache, - )); - } - - private function createEventMock(Request $request, Response $response) - { - $event = $this - ->getMockBuilder('Symfony\Component\HttpKernel\Event\FilterResponseEvent') - ->disableOriginalConstructor() - ->getMock(); - $event - ->expects($this->any()) - ->method('getRequest') - ->will($this->returnValue($request)) - ; - - $event - ->expects($this->any()) - ->method('getResponse') - ->will($this->returnValue($response)) - ; - - return $event; - } - - private function getKernel() - { - return $this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernelInterface')->getMock(); - } + $this->listener->onKernelResponse($this->createEventMock($request, $this->response)); + + $this->assertFalse($this->response->headers->hasCacheControlDirective('public')); + $this->assertTrue($this->response->headers->hasCacheControlDirective('private')); + } + + public function testResponseVary() + { + $vary = array('foobar'); + $request = $this->createRequest(new Cache(array('vary' => $vary))); + + $this->listener->onKernelResponse($this->createEventMock($request, $this->response)); + $this->assertTrue($this->response->hasVary()); + $result = $this->response->getVary(); + $this->assertEquals($vary, $result); + } + + public function testResponseVaryWhenVaryNotSet() + { + $request = $this->createRequest(new Cache(array())); + $vary = array('foobar'); + $this->response->setVary($vary); + + $this->listener->onKernelResponse($this->createEventMock($request, $this->response)); + $this->assertTrue($this->response->hasVary()); + $result = $this->response->getVary(); + $this->assertFalse(empty($result), 'Existing vary headers should not be removed'); + $this->assertEquals($vary, $result, 'Vary header should not be changed'); + } + + public function testResponseIsPrivateIfConfigurationIsPublicNotSet() + { + $request = $this->createRequest(new Cache(array())); + + $this->listener->onKernelResponse($this->createEventMock($request, $this->response)); + + $this->assertFalse($this->response->headers->hasCacheControlDirective('public')); + } + + public function testConfigurationAttributesAreSetOnResponse() + { + $this->assertInternalType('null', $this->response->getMaxAge()); + $this->assertInternalType('null', $this->response->getExpires()); + $this->assertFalse($this->response->headers->hasCacheControlDirective('s-maxage')); + + $this->request->attributes->set('_cache', new Cache(array( + 'expires' => 'tomorrow', + 'smaxage' => '15', + 'maxage' => '15', + ))); + + $this->listener->onKernelResponse($this->event); + + $this->assertEquals('15', $this->response->getMaxAge()); + $this->assertEquals('15', $this->response->headers->getCacheControlDirective('s-maxage')); + $this->assertInstanceOf('DateTime', $this->response->getExpires()); + } + + public function testCacheMaxAgeSupportsStrtotimeFormat() + { + $this->request->attributes->set('_cache', new Cache(array( + 'smaxage' => '1 day', + 'maxage' => '1 day', + ))); + + $this->listener->onKernelResponse($this->event); + + $this->assertEquals(60 * 60 * 24, $this->response->headers->getCacheControlDirective('s-maxage')); + $this->assertEquals(60 * 60 * 24, $this->response->getMaxAge()); + } + + public function testLastModifiedNotModifiedResponse() + { + $request = $this->createRequest(new Cache(array('lastModified' => 'test.getDate()'))); + $request->attributes->set('test', new TestEntity()); + $request->headers->add(array('If-Modified-Since' => 'Fri, 23 Aug 2013 00:00:00 GMT')); + + $listener = new HttpCacheEventSubscriber(); + $controllerEvent = new FilterControllerEvent($this->getKernel(), function () { + return new Response(500); + }, $request, null); + + $listener->onKernelController($controllerEvent); + $response = call_user_func($controllerEvent->getController()); + + $this->assertEquals(304, $response->getStatusCode()); + } + + public function testLastModifiedHeader() + { + $request = $this->createRequest(new Cache(array('lastModified' => 'test.getDate()'))); + $request->attributes->set('test', new TestEntity()); + $response = new Response(); + + $listener = new HttpCacheEventSubscriber(); + $controllerEvent = new FilterControllerEvent($this->getKernel(), function () { + return new Response(); + }, $request, null); + $listener->onKernelController($controllerEvent); + + $responseEvent = new FilterResponseEvent($this->getKernel(), $request, null, call_user_func($controllerEvent->getController())); + $listener->onKernelResponse($responseEvent); + + $response = $responseEvent->getResponse(); + + $this->assertEquals(200, $response->getStatusCode()); + $this->assertTrue($response->headers->has('Last-Modified')); + $this->assertEquals('Fri, 23 Aug 2013 00:00:00 GMT', $response->headers->get('Last-Modified')); + } + + public function testETagNotModifiedResponse() + { + $request = $this->createRequest(new Cache(array('etag' => 'test.getId()'))); + $request->attributes->set('test', $entity = new TestEntity()); + $request->headers->add(array('If-None-Match' => sprintf('"%s"', hash('sha256', $entity->getId())))); + + $listener = new HttpCacheEventSubscriber(); + $controllerEvent = new FilterControllerEvent($this->getKernel(), function () { + return new Response(500); + }, $request, null); + + $listener->onKernelController($controllerEvent); + $response = call_user_func($controllerEvent->getController()); + + $this->assertEquals(304, $response->getStatusCode()); + } + + public function testETagHeader() + { + $request = $this->createRequest(new Cache(array('ETag' => 'test.getId()'))); + $request->attributes->set('test', $entity = new TestEntity()); + $response = new Response(); + + $listener = new HttpCacheEventSubscriber(); + $controllerEvent = new FilterControllerEvent($this->getKernel(), function () { + return new Response(); + }, $request, null); + $listener->onKernelController($controllerEvent); + + $responseEvent = new FilterResponseEvent($this->getKernel(), $request, null, call_user_func($controllerEvent->getController())); + $listener->onKernelResponse($responseEvent); + + $response = $responseEvent->getResponse(); + + $this->assertEquals(200, $response->getStatusCode()); + $this->assertTrue($response->headers->has('ETag')); + $this->assertContains(hash('sha256', $entity->getId()), $response->headers->get('ETag')); + } + + private function createRequest(Cache $cache = null) + { + return new Request(array(), array(), array( + '_cache' => $cache, + )); + } + + private function createEventMock(Request $request, Response $response) + { + $event = $this + ->getMockBuilder('Symfony\Component\HttpKernel\Event\FilterResponseEvent') + ->disableOriginalConstructor() + ->getMock(); + $event + ->expects($this->any()) + ->method('getRequest') + ->will($this->returnValue($request)) + ; + + $event + ->expects($this->any()) + ->method('getResponse') + ->will($this->returnValue($response)) + ; + + return $event; + } + + private function getKernel() + { + return $this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernelInterface')->getMock(); + } } class TestEntity { - public function getDate() - { - return new \DateTime('Fri, 23 Aug 2013 00:00:00 GMT'); - } - - public function getId() - { - return '12345'; - } + public function getDate() + { + return new \DateTime('Fri, 23 Aug 2013 00:00:00 GMT'); + } + + public function getId() + { + return '12345'; + } } diff --git a/tests/src/Unit/EventSubscriber/ParamConverterEventSubscriberTest.php b/tests/src/Unit/EventSubscriber/ParamConverterEventSubscriberTest.php index 82b7ffa..e479d74 100644 --- a/tests/src/Unit/EventSubscriber/ParamConverterEventSubscriberTest.php +++ b/tests/src/Unit/EventSubscriber/ParamConverterEventSubscriberTest.php @@ -15,195 +15,195 @@ class ParamConverterEventSubscriberTest extends UnitTestCase { - /** - * @dataProvider getControllerWithNoArgsFixtures - */ - public function testRequestIsSkipped($controllerCallable) - { - $kernel = $this->getMockBuilder(HttpKernelInterface::class)->getMock(); - $request = new Request(); - - $eventSubscriber = new ParamConverterEventSubscriber( - $this->getParamConverterManager($request, []) - ); - $event = new FilterControllerEvent( - $kernel, - $controllerCallable, - $request, - null - ); - - $eventSubscriber->onKernelController($event); - } - - public function getControllerWithNoArgsFixtures() - { - return [ - [[new ParamConverterTestController(), 'noArgAction']], - [new ParamConverterInvokableNoArgController()], - ]; - } - - /** - * @dataProvider getControllerWithArgsFixtures - */ - public function testAutoConvert($controllerCallable) - { - $kernel = $this->getMockBuilder( - HttpKernelInterface::class - )->getMock(); - $request = new Request([], [], ['date' => '2014-03-14 09:00:00']); - - $converter = new ParamConverter( - ['name' => 'date', 'class' => 'DateTime'] - ); - - $eventSubscriber = new ParamConverterEventSubscriber( - $this->getParamConverterManager($request, ['date' => $converter]) - ); - $event = new FilterControllerEvent( - $kernel, - $controllerCallable, - $request, - null - ); - - $eventSubscriber->onKernelController($event); - } - - /** - * @dataProvider settingOptionalParamProvider - * @requires PHP 7.1 - */ - public function testSettingOptionalParam($function, $isOptional) - { - $kernel = $this->getMockBuilder(HttpKernelInterface::class)->getMock(); - $request = new Request(); - - $converter = new ParamConverter( - ['name' => 'param', 'class' => 'DateTime'] - ); - $converter->setIsOptional($isOptional); - - $eventSubscriber = new ParamConverterEventSubscriber( - $this->getParamConverterManager($request, ['param' => $converter]), - true - ); - $event = new FilterControllerEvent( - $kernel, - [ - new FooControllerNullableParameter(), - $function, - ], - $request, - null - ); - - $eventSubscriber->onKernelController($event); - } - - public function settingOptionalParamProvider() - { - return [ - ['requiredParamAction', false], - ['defaultParamAction', true], - ['nullableParamAction', true], - ]; - } - - /** - * @dataProvider getControllerWithArgsFixtures - */ - public function testNoAutoConvert($controllerCallable) - { - $kernel = $this->getMockBuilder(HttpKernelInterface::class)->getMock(); - $request = new Request([], [], ['date' => '2014-03-14 09:00:00']); - - $eventSubscriber = new ParamConverterEventSubscriber( - $this->getParamConverterManager($request, []), - false - ); - $event = new FilterControllerEvent( - $kernel, - $controllerCallable, - $request, - null - ); - - $eventSubscriber->onKernelController($event); - } - - public function getControllerWithArgsFixtures() - { - return [ - [[new ParamConverterTestController(), 'dateAction']], - [new ParamConverterInvokableController()], - ]; - } - - protected function getParamConverterManager(Request $request, $configurations) - { - $manager = $this->getMockBuilder(ParamConverterManager::class)->getMock(); - $manager - ->expects($this->once()) - ->method('apply') - ->with($this->equalTo($request), $this->equalTo($configurations)); - - return $manager; - } - - public function testPredefinedConfigurations() - { - $configuration = m::mock(\stdClass::class); - $configuration->shouldReceive('getName')->andReturn('foo'); - - $configurations = [$configuration]; - - $kernel = m::mock(HttpKernelInterface::class); - $request = new Request(); - $request->attributes->set('_converters', $configurations); - - $event = new FilterControllerEvent( - $kernel, - 'time', - $request, - null - ); - - $manager = m::mock(ParamConverterManager::class); - $manager->shouldReceive('apply')->once()->withArgs([$request, ['foo' => $configuration]]); - - $eventSubscriber = new ParamConverterEventSubscriber($manager, false); - $eventSubscriber->onKernelController($event); - - $this->assertNull(m::close()); - } + /** + * @dataProvider getControllerWithNoArgsFixtures + */ + public function testRequestIsSkipped($controllerCallable) + { + $kernel = $this->getMockBuilder(HttpKernelInterface::class)->getMock(); + $request = new Request(); + + $eventSubscriber = new ParamConverterEventSubscriber( + $this->getParamConverterManager($request, []) + ); + $event = new FilterControllerEvent( + $kernel, + $controllerCallable, + $request, + null + ); + + $eventSubscriber->onKernelController($event); + } + + public function getControllerWithNoArgsFixtures() + { + return [ + [[new ParamConverterTestController(), 'noArgAction']], + [new ParamConverterInvokableNoArgController()], + ]; + } + + /** + * @dataProvider getControllerWithArgsFixtures + */ + public function testAutoConvert($controllerCallable) + { + $kernel = $this->getMockBuilder( + HttpKernelInterface::class + )->getMock(); + $request = new Request([], [], ['date' => '2014-03-14 09:00:00']); + + $converter = new ParamConverter( + ['name' => 'date', 'class' => 'DateTime'] + ); + + $eventSubscriber = new ParamConverterEventSubscriber( + $this->getParamConverterManager($request, ['date' => $converter]) + ); + $event = new FilterControllerEvent( + $kernel, + $controllerCallable, + $request, + null + ); + + $eventSubscriber->onKernelController($event); + } + + /** + * @dataProvider settingOptionalParamProvider + * @requires PHP 7.1 + */ + public function testSettingOptionalParam($function, $isOptional) + { + $kernel = $this->getMockBuilder(HttpKernelInterface::class)->getMock(); + $request = new Request(); + + $converter = new ParamConverter( + ['name' => 'param', 'class' => 'DateTime'] + ); + $converter->setIsOptional($isOptional); + + $eventSubscriber = new ParamConverterEventSubscriber( + $this->getParamConverterManager($request, ['param' => $converter]), + true + ); + $event = new FilterControllerEvent( + $kernel, + [ + new FooControllerNullableParameter(), + $function, + ], + $request, + null + ); + + $eventSubscriber->onKernelController($event); + } + + public function settingOptionalParamProvider() + { + return [ + ['requiredParamAction', false], + ['defaultParamAction', true], + ['nullableParamAction', true], + ]; + } + + /** + * @dataProvider getControllerWithArgsFixtures + */ + public function testNoAutoConvert($controllerCallable) + { + $kernel = $this->getMockBuilder(HttpKernelInterface::class)->getMock(); + $request = new Request([], [], ['date' => '2014-03-14 09:00:00']); + + $eventSubscriber = new ParamConverterEventSubscriber( + $this->getParamConverterManager($request, []), + false + ); + $event = new FilterControllerEvent( + $kernel, + $controllerCallable, + $request, + null + ); + + $eventSubscriber->onKernelController($event); + } + + public function getControllerWithArgsFixtures() + { + return [ + [[new ParamConverterTestController(), 'dateAction']], + [new ParamConverterInvokableController()], + ]; + } + + protected function getParamConverterManager(Request $request, $configurations) + { + $manager = $this->getMockBuilder(ParamConverterManager::class)->getMock(); + $manager + ->expects($this->once()) + ->method('apply') + ->with($this->equalTo($request), $this->equalTo($configurations)); + + return $manager; + } + + public function testPredefinedConfigurations() + { + $configuration = m::mock(\stdClass::class); + $configuration->shouldReceive('getName')->andReturn('foo'); + + $configurations = [$configuration]; + + $kernel = m::mock(HttpKernelInterface::class); + $request = new Request(); + $request->attributes->set('_converters', $configurations); + + $event = new FilterControllerEvent( + $kernel, + 'time', + $request, + null + ); + + $manager = m::mock(ParamConverterManager::class); + $manager->shouldReceive('apply')->once()->withArgs([$request, ['foo' => $configuration]]); + + $eventSubscriber = new ParamConverterEventSubscriber($manager, false); + $eventSubscriber->onKernelController($event); + + $this->assertNull(m::close()); + } } class ParamConverterTestController { - public function noArgAction(Request $request) - { - } + public function noArgAction(Request $request) + { + } - public function dateAction(\DateTime $date) - { - } + public function dateAction(\DateTime $date) + { + } } class ParamConverterInvokableNoArgController { - public function __invoke(Request $request) - { - } + public function __invoke(Request $request) + { + } } class ParamConverterInvokableController { - public function __invoke(\DateTime $date) - { - } + public function __invoke(\DateTime $date) + { + } } diff --git a/tests/src/Unit/EventSubscriber/RouteEventSubscriberTest.php b/tests/src/Unit/EventSubscriber/RouteEventSubscriberTest.php index a8ba981..b685eca 100644 --- a/tests/src/Unit/EventSubscriber/RouteEventSubscriberTest.php +++ b/tests/src/Unit/EventSubscriber/RouteEventSubscriberTest.php @@ -15,110 +15,110 @@ */ class RouteEventSubscriberTest extends UnitTestCase { - /** - * @var RouteCollection - */ - protected $routeCollection; - - /** - * @var RouteCollection - */ - protected $annotatedRouteCollection; - - /** - * @var RouteEventSubscriber - */ - protected $eventSubscriber; - - protected function setUpEventSubscriber() - { - $annotationDirectoryLoader = m::mock(AnnotationDirectoryLoader::class); - $annotationDirectoryLoader->shouldReceive('load')->andReturn($this->getAnnotatedRouteCollection()); - - $this->eventSubscriber = new RouteEventSubscriber($annotationDirectoryLoader, ''); + /** + * @var RouteCollection + */ + protected $routeCollection; + + /** + * @var RouteCollection + */ + protected $annotatedRouteCollection; + + /** + * @var RouteEventSubscriber + */ + protected $eventSubscriber; + + protected function setUpEventSubscriber() + { + $annotationDirectoryLoader = m::mock(AnnotationDirectoryLoader::class); + $annotationDirectoryLoader->shouldReceive('load')->andReturn($this->getAnnotatedRouteCollection()); + + $this->eventSubscriber = new RouteEventSubscriber($annotationDirectoryLoader, ''); + } + + /** + * @return RouteCollection + */ + protected function getRouteCollection() + { + if (empty($this->routeCollection)) { + $this->routeCollection = new RouteCollection; } - /** - * @return RouteCollection - */ - protected function getRouteCollection() - { - if (empty($this->routeCollection)) { - $this->routeCollection = new RouteCollection; - } + return $this->routeCollection; + } - return $this->routeCollection; + /** + * @return RouteCollection + */ + protected function getAnnotatedRouteCollection() + { + if (empty($this->annotatedRouteCollection)) { + $this->annotatedRouteCollection = new RouteCollection; } - /** - * @return RouteCollection - */ - protected function getAnnotatedRouteCollection() - { - if (empty($this->annotatedRouteCollection)) { - $this->annotatedRouteCollection = new RouteCollection; - } + return $this->annotatedRouteCollection; + } - return $this->annotatedRouteCollection; + protected function triggerOnRoutes() + { + if (empty($this->eventSubscriber)) { + $this->setUpEventSubscriber(); } + $this->eventSubscriber->onRoutes(new RouteBuildEvent($this->getRouteCollection())); + } - protected function triggerOnRoutes() - { - if (empty($this->eventSubscriber)) { - $this->setUpEventSubscriber(); - } - $this->eventSubscriber->onRoutes(new RouteBuildEvent($this->getRouteCollection())); - } - - public function testOnRoutesWithEmptyRouteCollection() - { - $this->triggerOnRoutes(); - $this->assertEquals(0, $this->getRouteCollection()->count()); - } + public function testOnRoutesWithEmptyRouteCollection() + { + $this->triggerOnRoutes(); + $this->assertEquals(0, $this->getRouteCollection()->count()); + } - public function testOnRoutesWithoutAnnotatedRoutes() - { - $route = new Route('/foo'); - $route->setOption('type', 'annotation'); - $route->setOption('path', 'foo'); + public function testOnRoutesWithoutAnnotatedRoutes() + { + $route = new Route('/foo'); + $route->setOption('type', 'annotation'); + $route->setOption('path', 'foo'); - $this->getRouteCollection()->add('foo', new Route('/foo')); + $this->getRouteCollection()->add('foo', new Route('/foo')); - $this->triggerOnRoutes(); - $this->assertEquals(1, $this->getRouteCollection()->count()); - } + $this->triggerOnRoutes(); + $this->assertEquals(1, $this->getRouteCollection()->count()); + } - public function testOnRoutesWithAnnotatedRoute() - { - $annotatedRoute = new Route('/bar'); + public function testOnRoutesWithAnnotatedRoute() + { + $annotatedRoute = new Route('/bar'); - $annotatedRouteCollection = $this->getAnnotatedRouteCollection(); - $annotatedRouteCollection->add('bar', $annotatedRoute); + $annotatedRouteCollection = $this->getAnnotatedRouteCollection(); + $annotatedRouteCollection->add('bar', $annotatedRoute); - $route = new Route('/foo'); - $route->setOption('type', 'annotation'); - $route->setOption('path', 'foo'); + $route = new Route('/foo'); + $route->setOption('type', 'annotation'); + $route->setOption('path', 'foo'); - $this->getRouteCollection()->add('foo', $route); - $this->triggerOnRoutes(); - $this->assertEquals(1, $this->getRouteCollection()->count()); - $this->assertEquals($annotatedRoute, $this->getRouteCollection()->all()['bar']); - } + $this->getRouteCollection()->add('foo', $route); + $this->triggerOnRoutes(); + $this->assertEquals(1, $this->getRouteCollection()->count()); + $this->assertEquals($annotatedRoute, $this->getRouteCollection()->all()['bar']); + } - public function testOnRoutesWithoutRequiredOptions() - { - $this->setExpectedException(\Exception::class); + public function testOnRoutesWithoutRequiredOptions() + { + $this->setExpectedException(\Exception::class); - $annotatedRoute = new Route('/bar'); + $annotatedRoute = new Route('/bar'); - $annotatedRouteCollection = $this->getAnnotatedRouteCollection(); - $annotatedRouteCollection->add('bar', $annotatedRoute); + $annotatedRouteCollection = $this->getAnnotatedRouteCollection(); + $annotatedRouteCollection->add('bar', $annotatedRoute); - $route = new Route('/foo'); - $route->setOption('type', 'annotation'); + $route = new Route('/foo'); + $route->setOption('type', 'annotation'); - $this->getRouteCollection()->add('foo', $route); + $this->getRouteCollection()->add('foo', $route); - $this->triggerOnRoutes(); - } + $this->triggerOnRoutes(); + } } diff --git a/tests/src/Unit/EventSubscriber/TemplateEventSubscriberTest.php b/tests/src/Unit/EventSubscriber/TemplateEventSubscriberTest.php index 6d985b8..2c5c567 100644 --- a/tests/src/Unit/EventSubscriber/TemplateEventSubscriberTest.php +++ b/tests/src/Unit/EventSubscriber/TemplateEventSubscriberTest.php @@ -19,171 +19,171 @@ */ class TemplateEventSubscriberTest extends UnitTestCase { - public function testOnKernelControllerWithoutTemplate() - { - $twig = m::mock(\Twig_Environment::class); - $templateResolver = m::mock(TemplateResolver::class); + public function testOnKernelControllerWithoutTemplate() + { + $twig = m::mock(\Twig_Environment::class); + $templateResolver = m::mock(TemplateResolver::class); - $request = new Request(); + $request = new Request(); - $event = m::mock(FilterControllerEvent::class); - $event->shouldReceive('getRequest')->once()->andReturn($request); + $event = m::mock(FilterControllerEvent::class); + $event->shouldReceive('getRequest')->once()->andReturn($request); - $eventSubscriber = new TemplateEventSubscriber($twig, $templateResolver); - $this->assertNull($eventSubscriber->onKernelController($event)); + $eventSubscriber = new TemplateEventSubscriber($twig, $templateResolver); + $this->assertNull($eventSubscriber->onKernelController($event)); - $event = m::mock(GetResponseForControllerResultEvent::class); - $event->shouldReceive('getRequest')->once()->andReturn($request); + $event = m::mock(GetResponseForControllerResultEvent::class); + $event->shouldReceive('getRequest')->once()->andReturn($request); - $eventSubscriber = new TemplateEventSubscriber($twig, $templateResolver); - $this->assertNull($eventSubscriber->onKernelView($event)); - } + $eventSubscriber = new TemplateEventSubscriber($twig, $templateResolver); + $this->assertNull($eventSubscriber->onKernelView($event)); + } - public function testOnKernelControllerWithInvalidTemplate() - { - $twig = m::mock(\Twig_Environment::class); - $templateResolver = m::mock(TemplateResolver::class); + public function testOnKernelControllerWithInvalidTemplate() + { + $twig = m::mock(\Twig_Environment::class); + $templateResolver = m::mock(TemplateResolver::class); - $request = new Request(); - $request->attributes->set('_template', 'foo'); + $request = new Request(); + $request->attributes->set('_template', 'foo'); - $event = m::mock(FilterControllerEvent::class); - $event->shouldReceive('getRequest')->once()->andReturn($request); + $event = m::mock(FilterControllerEvent::class); + $event->shouldReceive('getRequest')->once()->andReturn($request); - $eventSubscriber = new TemplateEventSubscriber($twig, $templateResolver); - $this->assertNull($eventSubscriber->onKernelController($event)); + $eventSubscriber = new TemplateEventSubscriber($twig, $templateResolver); + $this->assertNull($eventSubscriber->onKernelController($event)); - $event = m::mock(GetResponseForControllerResultEvent::class); - $event->shouldReceive('getRequest')->once()->andReturn($request); + $event = m::mock(GetResponseForControllerResultEvent::class); + $event->shouldReceive('getRequest')->once()->andReturn($request); - $eventSubscriber = new TemplateEventSubscriber($twig, $templateResolver); - $this->assertNull($eventSubscriber->onKernelView($event)); - } + $eventSubscriber = new TemplateEventSubscriber($twig, $templateResolver); + $this->assertNull($eventSubscriber->onKernelView($event)); + } - public function testOnKernelControllerWithTemplate() - { - $templateName = 'resolved_template'; + public function testOnKernelControllerWithTemplate() + { + $templateName = 'resolved_template'; - $twig = m::mock(\Twig_Environment::class); - $templateResolver = m::mock(TemplateResolver::class); - $templateResolver->shouldReceive('resolveByControllerAndAction')->once()->andReturn($templateName); + $twig = m::mock(\Twig_Environment::class); + $templateResolver = m::mock(TemplateResolver::class); + $templateResolver->shouldReceive('resolveByControllerAndAction')->once()->andReturn($templateName); - $template = new Template([]); + $template = new Template([]); - $request = new Request(); - $request->attributes->set('_template', $template); + $request = new Request(); + $request->attributes->set('_template', $template); - $controller = m::mock(ControllerBase::class); - $owner = [$controller, 'testAction']; + $controller = m::mock(ControllerBase::class); + $owner = [$controller, 'testAction']; - $event = m::mock(FilterControllerEvent::class); - $event->shouldReceive('getRequest')->once()->andReturn($request); - $event->shouldReceive('getController')->once()->andReturn($owner); + $event = m::mock(FilterControllerEvent::class); + $event->shouldReceive('getRequest')->once()->andReturn($request); + $event->shouldReceive('getController')->once()->andReturn($owner); - $eventSubscriber = new TemplateEventSubscriber($twig, $templateResolver); - $eventSubscriber->onKernelController($event); + $eventSubscriber = new TemplateEventSubscriber($twig, $templateResolver); + $eventSubscriber->onKernelController($event); - $this->assertEquals($templateName, $template->getTemplate()); - $this->assertEquals($owner, $template->getOwner()); - } + $this->assertEquals($templateName, $template->getTemplate()); + $this->assertEquals($owner, $template->getOwner()); + } - public function testOnKernelControllerWithTemplateName() - { - $templateName = 'resolved_template'; + public function testOnKernelControllerWithTemplateName() + { + $templateName = 'resolved_template'; - $twig = m::mock(\Twig_Environment::class); - $templateResolver = m::mock(TemplateResolver::class); - $templateResolver->shouldReceive('normalize')->once()->andReturn($templateName); + $twig = m::mock(\Twig_Environment::class); + $templateResolver = m::mock(TemplateResolver::class); + $templateResolver->shouldReceive('normalize')->once()->andReturn($templateName); - $template = new Template([ - 'template' => $templateName - ]); + $template = new Template([ + 'template' => $templateName + ]); - $request = new Request(); - $request->attributes->set('_template', $template); + $request = new Request(); + $request->attributes->set('_template', $template); - $controller = m::mock(ControllerBase::class); - $owner = [$controller, 'testAction']; + $controller = m::mock(ControllerBase::class); + $owner = [$controller, 'testAction']; - $event = m::mock(FilterControllerEvent::class); - $event->shouldReceive('getRequest')->once()->andReturn($request); - $event->shouldReceive('getController')->once()->andReturn($owner); + $event = m::mock(FilterControllerEvent::class); + $event->shouldReceive('getRequest')->once()->andReturn($request); + $event->shouldReceive('getController')->once()->andReturn($owner); - $eventSubscriber = new TemplateEventSubscriber($twig, $templateResolver); - $eventSubscriber->onKernelController($event); + $eventSubscriber = new TemplateEventSubscriber($twig, $templateResolver); + $eventSubscriber->onKernelController($event); - $this->assertEquals($templateName, $template->getTemplate()); - $this->assertEquals($owner, $template->getOwner()); - } + $this->assertEquals($templateName, $template->getTemplate()); + $this->assertEquals($owner, $template->getOwner()); + } - public function testOnKernelView() - { - $renderedContent = 'rendered_page'; - $templateName = 'template.html.twig'; + public function testOnKernelView() + { + $renderedContent = 'rendered_page'; + $templateName = 'template.html.twig'; - $twig = m::mock(\Twig_Environment::class); - $twig->shouldReceive('render')->once()->andReturn($renderedContent); + $twig = m::mock(\Twig_Environment::class); + $twig->shouldReceive('render')->once()->andReturn($renderedContent); - $templateResolver = m::mock(TemplateResolver::class); + $templateResolver = m::mock(TemplateResolver::class); - $template = m::mock(Template::class); - $template->shouldReceive('getOwner')->andReturn(['controller', 'action']); - $template->shouldReceive('isStreamable')->andReturn(false); - $template->shouldReceive('setOwner')->once()->withArgs([[]]); - $template->shouldReceive('getTemplate')->once()->andReturn($templateName); + $template = m::mock(Template::class); + $template->shouldReceive('getOwner')->andReturn(['controller', 'action']); + $template->shouldReceive('isStreamable')->andReturn(false); + $template->shouldReceive('setOwner')->once()->withArgs([[]]); + $template->shouldReceive('getTemplate')->once()->andReturn($templateName); - $request = new Request(); - $request->attributes->set('_template', $template); + $request = new Request(); + $request->attributes->set('_template', $template); - $property = null; - $value = null; + $property = null; + $value = null; - $kernel = m::mock(HttpKernelInterface::class); - $event = new GetResponseForControllerResultEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST, []); + $kernel = m::mock(HttpKernelInterface::class); + $event = new GetResponseForControllerResultEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST, []); - $eventSubscriber = new TemplateEventSubscriber($twig, $templateResolver); - $eventSubscriber->onKernelView($event); + $eventSubscriber = new TemplateEventSubscriber($twig, $templateResolver); + $eventSubscriber->onKernelView($event); - $response = $event->getResponse(); - $this->assertEquals($renderedContent, $response->getContent()); - } + $response = $event->getResponse(); + $this->assertEquals($renderedContent, $response->getContent()); + } - public function testOnKernelViewStreamed() - { - $templateName = 'template.html.twig'; + public function testOnKernelViewStreamed() + { + $templateName = 'template.html.twig'; - $twig = m::mock(\Twig_Environment::class); - $twig->shouldReceive('display')->once()->withArgs([$templateName, []]); + $twig = m::mock(\Twig_Environment::class); + $twig->shouldReceive('display')->once()->withArgs([$templateName, []]); - $templateResolver = m::mock(TemplateResolver::class); + $templateResolver = m::mock(TemplateResolver::class); - $template = m::mock(Template::class); - $template->shouldReceive('getOwner')->andReturn(['controller', 'action']); - $template->shouldReceive('isStreamable')->andReturn(true); - $template->shouldReceive('setOwner')->once()->withArgs([[]]); - $template->shouldReceive('getTemplate')->once()->andReturn($templateName); + $template = m::mock(Template::class); + $template->shouldReceive('getOwner')->andReturn(['controller', 'action']); + $template->shouldReceive('isStreamable')->andReturn(true); + $template->shouldReceive('setOwner')->once()->withArgs([[]]); + $template->shouldReceive('getTemplate')->once()->andReturn($templateName); - $request = new Request(); - $request->attributes->set('_template', $template); + $request = new Request(); + $request->attributes->set('_template', $template); - $property = null; - $value = null; + $property = null; + $value = null; - $kernel = m::mock(HttpKernelInterface::class); - $event = new GetResponseForControllerResultEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST, []); + $kernel = m::mock(HttpKernelInterface::class); + $event = new GetResponseForControllerResultEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST, []); - $eventSubscriber = new TemplateEventSubscriber($twig, $templateResolver); - $eventSubscriber->onKernelView($event); + $eventSubscriber = new TemplateEventSubscriber($twig, $templateResolver); + $eventSubscriber->onKernelView($event); - $response = $event->getResponse(); - $this->assertEquals(false, $response->getContent()); - $this->assertInstanceOf(StreamedResponse::class, $response); + $response = $event->getResponse(); + $this->assertEquals(false, $response->getContent()); + $this->assertInstanceOf(StreamedResponse::class, $response); - $response->sendContent(); - } + $response->sendContent(); + } - public function tearDown() - { - m::close(); - } + public function tearDown() + { + m::close(); + } } diff --git a/tests/src/Unit/Fixture/FooControllerNullableParameter.php b/tests/src/Unit/Fixture/FooControllerNullableParameter.php index a2fb417..5ac9f60 100644 --- a/tests/src/Unit/Fixture/FooControllerNullableParameter.php +++ b/tests/src/Unit/Fixture/FooControllerNullableParameter.php @@ -4,15 +4,15 @@ class FooControllerNullableParameter { - public function requiredParamAction(\DateTime $param) - { - } + public function requiredParamAction(\DateTime $param) + { + } - public function defaultParamAction(\DateTime $param = null) - { - } + public function defaultParamAction(\DateTime $param = null) + { + } - public function nullableParamAction(?\DateTime $param) - { - } + public function nullableParamAction(?\DateTime $param) + { + } } diff --git a/tests/src/Unit/Fixture/FooControllerParamConverterAtClassAndMethod.php b/tests/src/Unit/Fixture/FooControllerParamConverterAtClassAndMethod.php index c077b6e..f64c755 100644 --- a/tests/src/Unit/Fixture/FooControllerParamConverterAtClassAndMethod.php +++ b/tests/src/Unit/Fixture/FooControllerParamConverterAtClassAndMethod.php @@ -9,10 +9,10 @@ */ class FooControllerParamConverterAtClassAndMethod { - /** - * @ParamConverter("test2") - */ - public function barAction($test, $test2) - { - } + /** + * @ParamConverter("test2") + */ + public function barAction($test, $test2) + { + } } diff --git a/tests/src/Unit/Helper.php b/tests/src/Unit/Helper.php index b512722..e503586 100644 --- a/tests/src/Unit/Helper.php +++ b/tests/src/Unit/Helper.php @@ -4,12 +4,12 @@ class Helper { - public static function getProtectedMethod($class, $name) - { - $class = new \ReflectionClass($class); - $method = $class->getMethod($name); - $method->setAccessible(true); + public static function getProtectedMethod($class, $name) + { + $class = new \ReflectionClass($class); + $method = $class->getMethod($name); + $method->setAccessible(true); - return $method; - } + return $method; + } } diff --git a/tests/src/Unit/Request/ParamConverter/DateTimeParamConverterTest.php b/tests/src/Unit/Request/ParamConverter/DateTimeParamConverterTest.php index 379428d..2c76288 100644 --- a/tests/src/Unit/Request/ParamConverter/DateTimeParamConverterTest.php +++ b/tests/src/Unit/Request/ParamConverter/DateTimeParamConverterTest.php @@ -13,114 +13,114 @@ class DateTimeParamConverterTest extends UnitTestCase { - private $converter; - - public function setUp() - { - $this->converter = new DateTimeParamConverter(); - } - - public function testSupports() - { - $config = $this->createConfiguration('DateTime'); - $this->assertTrue($this->converter->supports($config)); - - $config = $this->createConfiguration(__CLASS__); - $this->assertFalse($this->converter->supports($config)); - - $config = $this->createConfiguration(); - $this->assertFalse($this->converter->supports($config)); - } - - public function testApply() - { - $request = new Request([], [], ['start' => '2012-07-21 00:00:00']); - $config = $this->createConfiguration('DateTime', 'start'); - - $this->converter->apply($request, $config); - - $this->assertInstanceOf('DateTime', $request->attributes->get('start')); - $this->assertEquals( - '2012-07-21', - $request->attributes->get('start')->format('Y-m-d') - ); - } - - public function testApplyInvalidDate404Exception() - { - $request = new Request([], [], ['start' => 'Invalid DateTime Format']); - $config = $this->createConfiguration('DateTime', 'start'); - - $this->setExpectedException( - 'Symfony\Component\HttpKernel\Exception\NotFoundHttpException', - 'Invalid date given for parameter "start".' - ); - $this->converter->apply($request, $config); - } - - public function testApplyWithFormatInvalidDate404Exception() - { - $request = new Request([], [], ['start' => '2012-07-21']); - $config = $this->createConfiguration('DateTime', 'start'); - $config->expects($this->any())->method('getOptions')->will( - $this->returnValue(['format' => 'd.m.Y']) - ); - - $this->setExpectedException( - 'Symfony\Component\HttpKernel\Exception\NotFoundHttpException', - 'Invalid date given for parameter "start".' - ); - $this->converter->apply($request, $config); - } - - public function testApplyOptionalWithEmptyAttribute() - { - $request = new Request([], [], ['start' => null]); - $config = $this->createConfiguration('DateTime', 'start'); - $config->expects($this->once()) - ->method('isOptional') - ->will($this->returnValue(true)); - - $this->assertFalse($this->converter->apply($request, $config)); - $this->assertNull($request->attributes->get('start')); + private $converter; + + public function setUp() + { + $this->converter = new DateTimeParamConverter(); + } + + public function testSupports() + { + $config = $this->createConfiguration('DateTime'); + $this->assertTrue($this->converter->supports($config)); + + $config = $this->createConfiguration(__CLASS__); + $this->assertFalse($this->converter->supports($config)); + + $config = $this->createConfiguration(); + $this->assertFalse($this->converter->supports($config)); + } + + public function testApply() + { + $request = new Request([], [], ['start' => '2012-07-21 00:00:00']); + $config = $this->createConfiguration('DateTime', 'start'); + + $this->converter->apply($request, $config); + + $this->assertInstanceOf('DateTime', $request->attributes->get('start')); + $this->assertEquals( + '2012-07-21', + $request->attributes->get('start')->format('Y-m-d') + ); + } + + public function testApplyInvalidDate404Exception() + { + $request = new Request([], [], ['start' => 'Invalid DateTime Format']); + $config = $this->createConfiguration('DateTime', 'start'); + + $this->setExpectedException( + 'Symfony\Component\HttpKernel\Exception\NotFoundHttpException', + 'Invalid date given for parameter "start".' + ); + $this->converter->apply($request, $config); + } + + public function testApplyWithFormatInvalidDate404Exception() + { + $request = new Request([], [], ['start' => '2012-07-21']); + $config = $this->createConfiguration('DateTime', 'start'); + $config->expects($this->any())->method('getOptions')->will( + $this->returnValue(['format' => 'd.m.Y']) + ); + + $this->setExpectedException( + 'Symfony\Component\HttpKernel\Exception\NotFoundHttpException', + 'Invalid date given for parameter "start".' + ); + $this->converter->apply($request, $config); + } + + public function testApplyOptionalWithEmptyAttribute() + { + $request = new Request([], [], ['start' => null]); + $config = $this->createConfiguration('DateTime', 'start'); + $config->expects($this->once()) + ->method('isOptional') + ->will($this->returnValue(true)); + + $this->assertFalse($this->converter->apply($request, $config)); + $this->assertNull($request->attributes->get('start')); + } + + public function testApplyEmptyAttribute() + { + $request = new Request(); + $config = $this->createConfiguration('DateTime', 'start'); + + $this->assertFalse($this->converter->apply($request, $config)); + } + + public function createConfiguration($class = null, $name = null) + { + $config = $this + ->getMockBuilder(ParamConverter::class) + ->setMethods( + [ + 'getClass', + 'getAliasName', + 'getOptions', + 'getName', + 'allowArray', + 'isOptional', + ] + ) + ->disableOriginalConstructor() + ->getMock(); + + if ($name !== null) { + $config->expects($this->any()) + ->method('getName') + ->will($this->returnValue($name)); } - - public function testApplyEmptyAttribute() - { - $request = new Request(); - $config = $this->createConfiguration('DateTime', 'start'); - - $this->assertFalse($this->converter->apply($request, $config)); + if ($class !== null) { + $config->expects($this->any()) + ->method('getClass') + ->will($this->returnValue($class)); } - public function createConfiguration($class = null, $name = null) - { - $config = $this - ->getMockBuilder(ParamConverter::class) - ->setMethods( - [ - 'getClass', - 'getAliasName', - 'getOptions', - 'getName', - 'allowArray', - 'isOptional', - ] - ) - ->disableOriginalConstructor() - ->getMock(); - - if ($name !== null) { - $config->expects($this->any()) - ->method('getName') - ->will($this->returnValue($name)); - } - if ($class !== null) { - $config->expects($this->any()) - ->method('getClass') - ->will($this->returnValue($class)); - } - - return $config; - } + return $config; + } } diff --git a/tests/src/Unit/Request/ParamConverter/EntityParamConverterTest.php b/tests/src/Unit/Request/ParamConverter/EntityParamConverterTest.php index 2e0dc04..62db8e2 100644 --- a/tests/src/Unit/Request/ParamConverter/EntityParamConverterTest.php +++ b/tests/src/Unit/Request/ParamConverter/EntityParamConverterTest.php @@ -17,244 +17,244 @@ */ class EntityParamConverterTest extends UnitTestCase { - private function getEntityParamConverter() - { - $node = m::mock(Node::class); + private function getEntityParamConverter() + { + $node = m::mock(Node::class); - $entityInterface = m::mock(EntityInterface::class); - $entityInterface->shouldReceive('load')->andReturn($node); + $entityInterface = m::mock(EntityInterface::class); + $entityInterface->shouldReceive('load')->andReturn($node); - $entityTypeManager = m::mock(EntityTypeManager::class); - $entityTypeManager->shouldReceive('getStorage')->andReturn($entityInterface); + $entityTypeManager = m::mock(EntityTypeManager::class); + $entityTypeManager->shouldReceive('getStorage')->andReturn($entityInterface); - return new EntityParamConverter($entityTypeManager); - } + return new EntityParamConverter($entityTypeManager); + } - public function testSupports() - { - $paramConverter = m::mock(ParamConverter::class); - $paramConverter->shouldReceive('getClass')->once()->andReturn(Node::class); - $this->assertTrue($this->getEntityParamConverter()->supports($paramConverter)); - } + public function testSupports() + { + $paramConverter = m::mock(ParamConverter::class); + $paramConverter->shouldReceive('getClass')->once()->andReturn(Node::class); + $this->assertTrue($this->getEntityParamConverter()->supports($paramConverter)); + } - public function testNotSupports() - { - $paramConverter = m::mock(ParamConverter::class); - $paramConverter->shouldReceive('getClass')->once()->andReturn(self::class); - $this->assertFalse($this->getEntityParamConverter()->supports($paramConverter)); - } + public function testNotSupports() + { + $paramConverter = m::mock(ParamConverter::class); + $paramConverter->shouldReceive('getClass')->once()->andReturn(self::class); + $this->assertFalse($this->getEntityParamConverter()->supports($paramConverter)); + } - public function testApply() - { - $name = 'test'; - $request = new Request(); - $request->attributes->set($name, 1); + public function testApply() + { + $name = 'test'; + $request = new Request(); + $request->attributes->set($name, 1); - $node = m::mock(Node::class); + $node = m::mock(Node::class); - $paramConverter = m::mock(ParamConverter::class); - $paramConverter->shouldReceive('getClass')->once()->andReturn(Node::class); - $paramConverter->shouldReceive('getName')->once()->andReturn($name); - $paramConverter->shouldReceive('getOptions')->once()->andReturn([]); + $paramConverter = m::mock(ParamConverter::class); + $paramConverter->shouldReceive('getClass')->once()->andReturn(Node::class); + $paramConverter->shouldReceive('getName')->once()->andReturn($name); + $paramConverter->shouldReceive('getOptions')->once()->andReturn([]); - $this->assertTrue($this->getEntityParamConverter()->supports($paramConverter)); - $this->getEntityParamConverter()->apply($request, $paramConverter); + $this->assertTrue($this->getEntityParamConverter()->supports($paramConverter)); + $this->getEntityParamConverter()->apply($request, $paramConverter); - $this->assertTrue($request->attributes->has($name)); - $this->assertEquals($node, $request->attributes->get($name)); - } + $this->assertTrue($request->attributes->has($name)); + $this->assertEquals($node, $request->attributes->get($name)); + } - public function testApplyNonExistingEntity() - { - $this->setExpectedException(NotFoundHttpException::class); + public function testApplyNonExistingEntity() + { + $this->setExpectedException(NotFoundHttpException::class); - $entityInterface = m::mock(EntityInterface::class); - $entityInterface->shouldReceive('load')->andReturnNull(); + $entityInterface = m::mock(EntityInterface::class); + $entityInterface->shouldReceive('load')->andReturnNull(); - $entityTypeManager = m::mock(EntityTypeManager::class); - $entityTypeManager->shouldReceive('getStorage')->andReturn($entityInterface); + $entityTypeManager = m::mock(EntityTypeManager::class); + $entityTypeManager->shouldReceive('getStorage')->andReturn($entityInterface); - $name = 'test'; - $request = new Request(); - $request->attributes->set($name, 1); + $name = 'test'; + $request = new Request(); + $request->attributes->set($name, 1); - $paramConverter = m::mock(ParamConverter::class); - $paramConverter->shouldReceive('getClass')->once()->andReturn(Node::class); - $paramConverter->shouldReceive('getName')->once()->andReturn($name); - $paramConverter->shouldReceive('isOptional')->once()->andReturn(false); + $paramConverter = m::mock(ParamConverter::class); + $paramConverter->shouldReceive('getClass')->once()->andReturn(Node::class); + $paramConverter->shouldReceive('getName')->once()->andReturn($name); + $paramConverter->shouldReceive('isOptional')->once()->andReturn(false); - $entityParamConverter = new EntityParamConverter($entityTypeManager); + $entityParamConverter = new EntityParamConverter($entityTypeManager); - $this->assertTrue($entityParamConverter->supports($paramConverter)); - $entityParamConverter->apply($request, $paramConverter); - } + $this->assertTrue($entityParamConverter->supports($paramConverter)); + $entityParamConverter->apply($request, $paramConverter); + } - public function testApplyWithBundle() - { - $id = 1; - $bundle = 'article'; + public function testApplyWithBundle() + { + $id = 1; + $bundle = 'article'; - $node = m::mock(Node::class); - $node->shouldReceive('bundle')->once()->andReturn($bundle); + $node = m::mock(Node::class); + $node->shouldReceive('bundle')->once()->andReturn($bundle); - $entityInterface = m::mock(EntityInterface::class); - $entityInterface->shouldReceive('load')->withArgs([$id])->andReturn($node); + $entityInterface = m::mock(EntityInterface::class); + $entityInterface->shouldReceive('load')->withArgs([$id])->andReturn($node); - $entityTypeManager = m::mock(EntityTypeManager::class); - $entityTypeManager->shouldReceive('getStorage')->withArgs(['node'])->andReturn($entityInterface); + $entityTypeManager = m::mock(EntityTypeManager::class); + $entityTypeManager->shouldReceive('getStorage')->withArgs(['node'])->andReturn($entityInterface); - $nodeParamConverter = new EntityParamConverter($entityTypeManager); + $nodeParamConverter = new EntityParamConverter($entityTypeManager); - $name = 'test'; - $request = new Request(); - $request->attributes->set($name, $id); + $name = 'test'; + $request = new Request(); + $request->attributes->set($name, $id); - $paramConverter = m::mock(ParamConverter::class); - $paramConverter->shouldReceive('getClass')->once()->andReturn(Node::class); - $paramConverter->shouldReceive('getName')->once()->andReturn($name); - $paramConverter->shouldReceive('getOptions')->once()->andReturn(['bundle' => $bundle]); + $paramConverter = m::mock(ParamConverter::class); + $paramConverter->shouldReceive('getClass')->once()->andReturn(Node::class); + $paramConverter->shouldReceive('getName')->once()->andReturn($name); + $paramConverter->shouldReceive('getOptions')->once()->andReturn(['bundle' => $bundle]); - $this->assertTrue($nodeParamConverter->supports($paramConverter)); - $nodeParamConverter->apply($request, $paramConverter); + $this->assertTrue($nodeParamConverter->supports($paramConverter)); + $nodeParamConverter->apply($request, $paramConverter); - $this->assertTrue($request->attributes->has($name)); - $this->assertEquals($node, $request->attributes->get($name)); - } + $this->assertTrue($request->attributes->has($name)); + $this->assertEquals($node, $request->attributes->get($name)); + } - public function testApplyWithWrongBundle() - { - $this->setExpectedException(NotFoundHttpException::class); + public function testApplyWithWrongBundle() + { + $this->setExpectedException(NotFoundHttpException::class); - $id = 1; - $bundle = 'article'; + $id = 1; + $bundle = 'article'; - $node = m::mock(Node::class); - $node->shouldReceive('bundle')->once()->andReturn('not_an_article'); + $node = m::mock(Node::class); + $node->shouldReceive('bundle')->once()->andReturn('not_an_article'); - $entityInterface = m::mock(EntityInterface::class); - $entityInterface->shouldReceive('load')->withArgs([$id])->andReturn($node); + $entityInterface = m::mock(EntityInterface::class); + $entityInterface->shouldReceive('load')->withArgs([$id])->andReturn($node); - $entityTypeManager = m::mock(EntityTypeManager::class); - $entityTypeManager->shouldReceive('getStorage')->withArgs(['node'])->andReturn($entityInterface); + $entityTypeManager = m::mock(EntityTypeManager::class); + $entityTypeManager->shouldReceive('getStorage')->withArgs(['node'])->andReturn($entityInterface); - $nodeParamConverter = new EntityParamConverter($entityTypeManager); + $nodeParamConverter = new EntityParamConverter($entityTypeManager); - $name = 'test'; - $request = new Request(); - $request->attributes->set($name, $id); + $name = 'test'; + $request = new Request(); + $request->attributes->set($name, $id); - $paramConverter = m::mock(ParamConverter::class); - $paramConverter->shouldReceive('getClass')->once()->andReturn(Node::class); - $paramConverter->shouldReceive('getName')->once()->andReturn($name); - $paramConverter->shouldReceive('getOptions')->once()->andReturn(['bundle' => $bundle]); + $paramConverter = m::mock(ParamConverter::class); + $paramConverter->shouldReceive('getClass')->once()->andReturn(Node::class); + $paramConverter->shouldReceive('getName')->once()->andReturn($name); + $paramConverter->shouldReceive('getOptions')->once()->andReturn(['bundle' => $bundle]); - $this->assertTrue($nodeParamConverter->supports($paramConverter)); - $nodeParamConverter->apply($request, $paramConverter); - } + $this->assertTrue($nodeParamConverter->supports($paramConverter)); + $nodeParamConverter->apply($request, $paramConverter); + } - public function testApplyOptionalWhenEmpty() - { - $id = 1; + public function testApplyOptionalWhenEmpty() + { + $id = 1; - $entityInterface = m::mock(EntityInterface::class); - $entityInterface->shouldReceive('load')->withArgs([$id])->andReturn(null); + $entityInterface = m::mock(EntityInterface::class); + $entityInterface->shouldReceive('load')->withArgs([$id])->andReturn(null); - $entityTypeManager = m::mock(EntityTypeManager::class); - $entityTypeManager->shouldReceive('getStorage')->withArgs(['node'])->andReturn($entityInterface); + $entityTypeManager = m::mock(EntityTypeManager::class); + $entityTypeManager->shouldReceive('getStorage')->withArgs(['node'])->andReturn($entityInterface); - $nodeParamConverter = new EntityParamConverter($entityTypeManager); + $nodeParamConverter = new EntityParamConverter($entityTypeManager); - $name = 'test'; - $request = new Request(); - $request->attributes->set($name, $id); + $name = 'test'; + $request = new Request(); + $request->attributes->set($name, $id); - $paramConverter = m::mock(ParamConverter::class); - $paramConverter->shouldReceive('getClass')->once()->andReturn(Node::class); - $paramConverter->shouldReceive('getName')->once()->andReturn($name); - $paramConverter->shouldReceive('isOptional')->once()->andReturn(true); + $paramConverter = m::mock(ParamConverter::class); + $paramConverter->shouldReceive('getClass')->once()->andReturn(Node::class); + $paramConverter->shouldReceive('getName')->once()->andReturn($name); + $paramConverter->shouldReceive('isOptional')->once()->andReturn(true); - $this->assertTrue($nodeParamConverter->supports($paramConverter)); - $nodeParamConverter->apply($request, $paramConverter); + $this->assertTrue($nodeParamConverter->supports($paramConverter)); + $nodeParamConverter->apply($request, $paramConverter); - $this->assertTrue($request->attributes->has($name)); - $this->assertEquals(null, $request->attributes->get($name)); - } + $this->assertTrue($request->attributes->has($name)); + $this->assertEquals(null, $request->attributes->get($name)); + } - public function testApplyWithoutAttribute() - { - $id = 1; - $bundle = 'article'; + public function testApplyWithoutAttribute() + { + $id = 1; + $bundle = 'article'; - $entityInterface = m::mock(EntityInterface::class); - $entityInterface->shouldReceive('load')->withArgs([$id])->andReturn(null); + $entityInterface = m::mock(EntityInterface::class); + $entityInterface->shouldReceive('load')->withArgs([$id])->andReturn(null); - $entityTypeManager = m::mock(EntityTypeManager::class); - $entityTypeManager->shouldReceive('getStorage')->withArgs(['node'])->andReturn($entityInterface); + $entityTypeManager = m::mock(EntityTypeManager::class); + $entityTypeManager->shouldReceive('getStorage')->withArgs(['node'])->andReturn($entityInterface); - $nodeParamConverter = new EntityParamConverter($entityTypeManager); + $nodeParamConverter = new EntityParamConverter($entityTypeManager); - $name = 'test'; - $request = new Request(); + $name = 'test'; + $request = new Request(); - $paramConverter = m::mock(ParamConverter::class); - $paramConverter->shouldReceive('getClass')->once()->andReturn(Node::class); - $paramConverter->shouldReceive('getName')->once()->andReturn($name); - $paramConverter->shouldReceive('getOptions')->never()->andReturn(['bundle' => $bundle]); + $paramConverter = m::mock(ParamConverter::class); + $paramConverter->shouldReceive('getClass')->once()->andReturn(Node::class); + $paramConverter->shouldReceive('getName')->once()->andReturn($name); + $paramConverter->shouldReceive('getOptions')->never()->andReturn(['bundle' => $bundle]); - $this->assertTrue($nodeParamConverter->supports($paramConverter)); - $this->assertFalse($nodeParamConverter->apply($request, $paramConverter)); - } + $this->assertTrue($nodeParamConverter->supports($paramConverter)); + $this->assertFalse($nodeParamConverter->apply($request, $paramConverter)); + } - public function testOptional() - { - $id = 1; - $bundle = 'article'; + public function testOptional() + { + $id = 1; + $bundle = 'article'; - $entityInterface = m::mock(EntityInterface::class); - $entityInterface->shouldReceive('load')->withArgs([$id])->andReturn(null); + $entityInterface = m::mock(EntityInterface::class); + $entityInterface->shouldReceive('load')->withArgs([$id])->andReturn(null); - $entityTypeManager = m::mock(EntityTypeManager::class); - $entityTypeManager->shouldReceive('getStorage')->withArgs(['node'])->andReturn($entityInterface); + $entityTypeManager = m::mock(EntityTypeManager::class); + $entityTypeManager->shouldReceive('getStorage')->withArgs(['node'])->andReturn($entityInterface); - $nodeParamConverter = new EntityParamConverter($entityTypeManager); + $nodeParamConverter = new EntityParamConverter($entityTypeManager); - $name = 'test'; - $request = new Request(); + $name = 'test'; + $request = new Request(); - $paramConverter = m::mock(ParamConverter::class); - $paramConverter->shouldReceive('getName')->once()->andReturn($name); - $paramConverter->shouldReceive('getOptions')->never()->andReturn(['bundle' => $bundle]); + $paramConverter = m::mock(ParamConverter::class); + $paramConverter->shouldReceive('getName')->once()->andReturn($name); + $paramConverter->shouldReceive('getOptions')->never()->andReturn(['bundle' => $bundle]); - $this->assertFalse($nodeParamConverter->apply($request, $paramConverter)); - } + $this->assertFalse($nodeParamConverter->apply($request, $paramConverter)); + } - public function testOptionalEmptyAttribute() - { - $id = 1; - $bundle = 'article'; + public function testOptionalEmptyAttribute() + { + $id = 1; + $bundle = 'article'; - $entityInterface = m::mock(EntityInterface::class); - $entityInterface->shouldReceive('load')->withArgs([$id])->andReturn(null); + $entityInterface = m::mock(EntityInterface::class); + $entityInterface->shouldReceive('load')->withArgs([$id])->andReturn(null); - $entityTypeManager = m::mock(EntityTypeManager::class); - $entityTypeManager->shouldReceive('getStorage')->withArgs(['node'])->andReturn($entityInterface); + $entityTypeManager = m::mock(EntityTypeManager::class); + $entityTypeManager->shouldReceive('getStorage')->withArgs(['node'])->andReturn($entityInterface); - $nodeParamConverter = new EntityParamConverter($entityTypeManager); + $nodeParamConverter = new EntityParamConverter($entityTypeManager); - $name = 'test'; - $request = new Request(); - $request->attributes->set($name, ''); + $name = 'test'; + $request = new Request(); + $request->attributes->set($name, ''); - $paramConverter = m::mock(ParamConverter::class); - $paramConverter->shouldReceive('getName')->once()->andReturn($name); - $paramConverter->shouldReceive('getOptions')->never()->andReturn(['bundle' => $bundle]); - $paramConverter->shouldReceive('isOptional')->once()->andReturn(true); + $paramConverter = m::mock(ParamConverter::class); + $paramConverter->shouldReceive('getName')->once()->andReturn($name); + $paramConverter->shouldReceive('getOptions')->never()->andReturn(['bundle' => $bundle]); + $paramConverter->shouldReceive('isOptional')->once()->andReturn(true); - $this->assertFalse($nodeParamConverter->apply($request, $paramConverter)); - } + $this->assertFalse($nodeParamConverter->apply($request, $paramConverter)); + } - public function tearDown() - { - m::close(); - } + public function tearDown() + { + m::close(); + } } diff --git a/tests/src/Unit/Request/ParamConverter/ParamConverterManagerTest.php b/tests/src/Unit/Request/ParamConverter/ParamConverterManagerTest.php index 9fd30d1..b9f6fbb 100644 --- a/tests/src/Unit/Request/ParamConverter/ParamConverterManagerTest.php +++ b/tests/src/Unit/Request/ParamConverter/ParamConverterManagerTest.php @@ -13,184 +13,184 @@ */ class ParamConverterManagerTest extends UnitTestCase { - public function testPriorities() - { - $manager = new ParamConverterManager(); - $this->assertEquals(array(), $manager->all()); - - $high = $this->createParamConverterMock(); - $low = $this->createParamConverterMock(); - - $manager->add($low); - $manager->add($high, 10); - - $this->assertEquals(array($high, $low), $manager->all()); - } - - public function testApply() - { - $supported = $this->createParamConverterMock(); - $supported - ->expects($this->once()) - ->method('supports') - ->will($this->returnValue(true)) - ; - $supported - ->expects($this->once()) - ->method('apply') - ->will($this->returnValue(false)) - ; - - $invalid = $this->createParamConverterMock(); - $invalid - ->expects($this->once()) - ->method('supports') - ->will($this->returnValue(false)) - ; - $invalid - ->expects($this->never()) - ->method('apply') - ; - - $configurations = array( - new Configuration\ParamConverter(array( - 'name' => 'var', - )), - ); - - $manager = new ParamConverterManager(); - $manager->add($supported); - $manager->add($invalid); - $manager->apply(new Request(), $configurations); - } - - public function testApplyNamedConverter() - { - $converter = $this->createParamConverterMock(); - $converter - ->expects($this->any()) - ->method('supports') - ->will($this->returnValue(true)) - ; - - $converter - ->expects($this->any()) - ->method('apply') - ; - - $request = new Request(); - $request->attributes->set('param', '1234'); - - $configuration = new Configuration\ParamConverter(array( - 'name' => 'param', - 'class' => 'stdClass', - 'converter' => 'test', - )); - - $manager = new ParamConverterManager(); - $manager->add($converter, 0, 'test'); - $this->assertNull($manager->apply($request, array($configuration))); - } - - /** - * @expectedException \RuntimeException - * @expectedExceptionMessage Converter 'test' does not support conversion of parameter 'param'. - */ - public function testApplyNamedConverterNotSupportsParameter() - { - $converter = $this->createParamConverterMock(); - $converter - ->expects($this->any()) - ->method('supports') - ->will($this->returnValue(false)) - ; - - $request = new Request(); - $request->attributes->set('param', '1234'); - - $configuration = new Configuration\ParamConverter(array( - 'name' => 'param', - 'class' => 'stdClass', - 'converter' => 'test', - )); - - $manager = new ParamConverterManager(); - $manager->add($converter, 0, 'test'); - $manager->apply($request, array($configuration)); - } - - /** - * @expectedException \RuntimeException - * @expectedExceptionMessage No converter named 'test' found for conversion of parameter 'param'. - */ - public function testApplyNamedConverterNoConverter() - { - $request = new Request(); - $request->attributes->set('param', '1234'); - - $configuration = new Configuration\ParamConverter(array( - 'name' => 'param', - 'class' => 'stdClass', - 'converter' => 'test', - )); - - $manager = new ParamConverterManager(); - $manager->apply($request, array($configuration)); - } - - public function testApplyNotCalledOnAlreadyConvertedObjects() - { - $converter = $this->createParamConverterMock(); - $converter - ->expects($this->never()) - ->method('supports') - ; - - $converter - ->expects($this->never()) - ->method('apply') - ; - - $request = new Request(); - $request->attributes->set('converted', new \stdClass()); - - $configuration = new Configuration\ParamConverter(array( - 'name' => 'converted', - 'class' => 'stdClass', - )); - - $manager = new ParamConverterManager(); - $manager->add($converter); - $manager->apply($request, array($configuration)); - } - - public function testApplyWithoutArray() - { - $converter = $this->createParamConverterMock(); - $converter - ->expects($this->any()) - ->method('supports') - ->will($this->returnValue(false)) - ; - - $converter - ->expects($this->never()) - ->method('apply') - ; - - $request = new Request(); - - $configuration = new Configuration\ParamConverter(array( - 'name' => 'var', - )); - - $manager = new ParamConverterManager(); - $manager->add($converter); - $manager->apply($request, $configuration); - } - - protected function createParamConverterMock() - { - return $this->getMockBuilder(ParamConverterInterface::class)->getMock(); - } + public function testPriorities() + { + $manager = new ParamConverterManager(); + $this->assertEquals(array(), $manager->all()); + + $high = $this->createParamConverterMock(); + $low = $this->createParamConverterMock(); + + $manager->add($low); + $manager->add($high, 10); + + $this->assertEquals(array($high, $low), $manager->all()); + } + + public function testApply() + { + $supported = $this->createParamConverterMock(); + $supported + ->expects($this->once()) + ->method('supports') + ->will($this->returnValue(true)) + ; + $supported + ->expects($this->once()) + ->method('apply') + ->will($this->returnValue(false)) + ; + + $invalid = $this->createParamConverterMock(); + $invalid + ->expects($this->once()) + ->method('supports') + ->will($this->returnValue(false)) + ; + $invalid + ->expects($this->never()) + ->method('apply') + ; + + $configurations = array( + new Configuration\ParamConverter(array( + 'name' => 'var', + )), + ); + + $manager = new ParamConverterManager(); + $manager->add($supported); + $manager->add($invalid); + $manager->apply(new Request(), $configurations); + } + + public function testApplyNamedConverter() + { + $converter = $this->createParamConverterMock(); + $converter + ->expects($this->any()) + ->method('supports') + ->will($this->returnValue(true)) + ; + + $converter + ->expects($this->any()) + ->method('apply') + ; + + $request = new Request(); + $request->attributes->set('param', '1234'); + + $configuration = new Configuration\ParamConverter(array( + 'name' => 'param', + 'class' => 'stdClass', + 'converter' => 'test', + )); + + $manager = new ParamConverterManager(); + $manager->add($converter, 0, 'test'); + $this->assertNull($manager->apply($request, array($configuration))); + } + + /** + * @expectedException \RuntimeException + * @expectedExceptionMessage Converter 'test' does not support conversion of parameter 'param'. + */ + public function testApplyNamedConverterNotSupportsParameter() + { + $converter = $this->createParamConverterMock(); + $converter + ->expects($this->any()) + ->method('supports') + ->will($this->returnValue(false)) + ; + + $request = new Request(); + $request->attributes->set('param', '1234'); + + $configuration = new Configuration\ParamConverter(array( + 'name' => 'param', + 'class' => 'stdClass', + 'converter' => 'test', + )); + + $manager = new ParamConverterManager(); + $manager->add($converter, 0, 'test'); + $manager->apply($request, array($configuration)); + } + + /** + * @expectedException \RuntimeException + * @expectedExceptionMessage No converter named 'test' found for conversion of parameter 'param'. + */ + public function testApplyNamedConverterNoConverter() + { + $request = new Request(); + $request->attributes->set('param', '1234'); + + $configuration = new Configuration\ParamConverter(array( + 'name' => 'param', + 'class' => 'stdClass', + 'converter' => 'test', + )); + + $manager = new ParamConverterManager(); + $manager->apply($request, array($configuration)); + } + + public function testApplyNotCalledOnAlreadyConvertedObjects() + { + $converter = $this->createParamConverterMock(); + $converter + ->expects($this->never()) + ->method('supports') + ; + + $converter + ->expects($this->never()) + ->method('apply') + ; + + $request = new Request(); + $request->attributes->set('converted', new \stdClass()); + + $configuration = new Configuration\ParamConverter(array( + 'name' => 'converted', + 'class' => 'stdClass', + )); + + $manager = new ParamConverterManager(); + $manager->add($converter); + $manager->apply($request, array($configuration)); + } + + public function testApplyWithoutArray() + { + $converter = $this->createParamConverterMock(); + $converter + ->expects($this->any()) + ->method('supports') + ->will($this->returnValue(false)) + ; + + $converter + ->expects($this->never()) + ->method('apply') + ; + + $request = new Request(); + + $configuration = new Configuration\ParamConverter(array( + 'name' => 'var', + )); + + $manager = new ParamConverterManager(); + $manager->add($converter); + $manager->apply($request, $configuration); + } + + protected function createParamConverterMock() + { + return $this->getMockBuilder(ParamConverterInterface::class)->getMock(); + } } diff --git a/tests/src/Unit/Routing/AnnotatedRouteControllerLoaderTest.php b/tests/src/Unit/Routing/AnnotatedRouteControllerLoaderTest.php index 69d1022..abd34e4 100644 --- a/tests/src/Unit/Routing/AnnotatedRouteControllerLoaderTest.php +++ b/tests/src/Unit/Routing/AnnotatedRouteControllerLoaderTest.php @@ -15,42 +15,42 @@ */ class AnnotatedRouteControllerLoaderTest extends UnitTestCase { - public function testConfigureRoute() - { - $routeConfiguration = m::mock(\Drupal\controller_annotations\Configuration\Route::class); - $routeConfiguration->shouldReceive('getService')->andReturn(false); - $routeConfiguration->shouldReceive('isAdmin')->andReturn(true); - $routeConfiguration->shouldReceive('modifyRouteMethod')->andReturnNull(); - $routeConfiguration->shouldReceive('modifyRouteClass')->andReturnNull(); - - $methodConfiguration = m::mock(Method::class); - $methodConfiguration->shouldReceive('getMethods')->andReturn(['GET']); - $methodConfiguration->shouldReceive('modifyRouteMethod')->andReturnNull(); - $methodConfiguration->shouldReceive('modifyRouteClass')->andReturnNull(); - - $reader = m::mock(Reader::class); - $reader->shouldReceive('getClassAnnotation')->andReturn($routeConfiguration); - $reader->shouldReceive('getMethodAnnotations')->andReturn([ - $routeConfiguration, - $methodConfiguration - ]); - $reader->shouldReceive('getClassAnnotations')->andReturn([]); - - $route = m::mock(Route::class); - $route->shouldReceive('setDefault')->once(); - - $reflectionClass = m::mock(\ReflectionClass::class); - $reflectionClass->shouldReceive('getName')->once()->andReturn('Controller'); - - $reflectionMethod = m::mock(\ReflectionMethod::class); - $reflectionMethod->shouldReceive('getName')->once()->andReturn('action'); - - $method = Helper::getProtectedMethod(AnnotatedRouteControllerLoader::class, 'configureRoute'); - $annotatedRouteControllerLoader = new AnnotatedRouteControllerLoader($reader); - $method->invokeArgs($annotatedRouteControllerLoader, [$route, $reflectionClass, $reflectionMethod, null]); - - $this->assertTrue(true); - - m::close(); - } + public function testConfigureRoute() + { + $routeConfiguration = m::mock(\Drupal\controller_annotations\Configuration\Route::class); + $routeConfiguration->shouldReceive('getService')->andReturn(false); + $routeConfiguration->shouldReceive('isAdmin')->andReturn(true); + $routeConfiguration->shouldReceive('modifyRouteMethod')->andReturnNull(); + $routeConfiguration->shouldReceive('modifyRouteClass')->andReturnNull(); + + $methodConfiguration = m::mock(Method::class); + $methodConfiguration->shouldReceive('getMethods')->andReturn(['GET']); + $methodConfiguration->shouldReceive('modifyRouteMethod')->andReturnNull(); + $methodConfiguration->shouldReceive('modifyRouteClass')->andReturnNull(); + + $reader = m::mock(Reader::class); + $reader->shouldReceive('getClassAnnotation')->andReturn($routeConfiguration); + $reader->shouldReceive('getMethodAnnotations')->andReturn([ + $routeConfiguration, + $methodConfiguration + ]); + $reader->shouldReceive('getClassAnnotations')->andReturn([]); + + $route = m::mock(Route::class); + $route->shouldReceive('setDefault')->once(); + + $reflectionClass = m::mock(\ReflectionClass::class); + $reflectionClass->shouldReceive('getName')->once()->andReturn('Controller'); + + $reflectionMethod = m::mock(\ReflectionMethod::class); + $reflectionMethod->shouldReceive('getName')->once()->andReturn('action'); + + $method = Helper::getProtectedMethod(AnnotatedRouteControllerLoader::class, 'configureRoute'); + $annotatedRouteControllerLoader = new AnnotatedRouteControllerLoader($reader); + $method->invokeArgs($annotatedRouteControllerLoader, [$route, $reflectionClass, $reflectionMethod, null]); + + $this->assertTrue(true); + + m::close(); + } } diff --git a/tests/src/Unit/Templating/TemplateResolverTest.php b/tests/src/Unit/Templating/TemplateResolverTest.php index 8158fb7..fd418db 100644 --- a/tests/src/Unit/Templating/TemplateResolverTest.php +++ b/tests/src/Unit/Templating/TemplateResolverTest.php @@ -12,95 +12,95 @@ */ class TemplateResolverTest extends UnitTestCase { - /** - * @var TemplateResolver - */ - private $templateResolver; + /** + * @var TemplateResolver + */ + private $templateResolver; - public function setUp() - { - $this->templateResolver = new TemplateResolver(); - } + public function setUp() + { + $this->templateResolver = new TemplateResolver(); + } - /** - * @dataProvider controllerActionProvider - */ - public function testResolveByControllerAndAction( + /** + * @dataProvider controllerActionProvider + */ + public function testResolveByControllerAndAction( + $controller, + $action, + $expected + ) { + $this->assertEquals( + $expected, + $this->templateResolver->resolveByControllerAndAction( $controller, - $action, - $expected - ) { - $this->assertEquals( - $expected, - $this->templateResolver->resolveByControllerAndAction( - $controller, - $action - ) - ); - } + $action + ) + ); + } - /** - * @return array - */ - public function controllerActionProvider() - { - $expected = 'modules/foo/templates/foo-foo-bar.html.twig'; + /** + * @return array + */ + public function controllerActionProvider() + { + $expected = 'modules/foo/templates/foo-foo-bar.html.twig'; - return [ - ['Drupal\foo\Controller\FooController', 'barAction', $expected], - ['Drupal\foo\Controller\Foo', 'barAction', $expected], - ['Drupal\foo\Controller\FooController', 'bar', $expected], - ['Drupal\foo\Controller\Foo', 'bar', $expected], - [ - 'Drupal\foo\Controller\Bar\FooController', - 'barAction', - 'modules/foo/templates/foo-bar-foo-bar.html.twig', - ], - [ - 'Drupal\foo\Controller\Foo\FooController', - 'barAction', - 'modules/foo/templates/foo-foo-foo-bar.html.twig', - ], - [ - 'Drupal\foo\Controller\Foo\FooController', - 'fooAction', - 'modules/foo/templates/foo-foo-foo-foo.html.twig', - ], - ]; - } + return [ + ['Drupal\foo\Controller\FooController', 'barAction', $expected], + ['Drupal\foo\Controller\Foo', 'barAction', $expected], + ['Drupal\foo\Controller\FooController', 'bar', $expected], + ['Drupal\foo\Controller\Foo', 'bar', $expected], + [ + 'Drupal\foo\Controller\Bar\FooController', + 'barAction', + 'modules/foo/templates/foo-bar-foo-bar.html.twig', + ], + [ + 'Drupal\foo\Controller\Foo\FooController', + 'barAction', + 'modules/foo/templates/foo-foo-foo-bar.html.twig', + ], + [ + 'Drupal\foo\Controller\Foo\FooController', + 'fooAction', + 'modules/foo/templates/foo-foo-foo-foo.html.twig', + ], + ]; + } - /** - * @dataProvider normalizeProvider - */ - public function testNormalize($template, $expected) - { - $this->assertEquals( - $expected, - $this->templateResolver->normalize($template) - ); - } + /** + * @dataProvider normalizeProvider + */ + public function testNormalize($template, $expected) + { + $this->assertEquals( + $expected, + $this->templateResolver->normalize($template) + ); + } - /** - * @return array - */ - public function normalizeProvider() - { - return [ - ['foo:bar', 'modules/foo/templates/foo-bar.html.twig'], - ['foobar:baz', 'modules/foobar/templates/foobar-baz.html.twig'], - ['foo:bar:baz', 'modules/foo/templates/foo-bar-baz.html.twig'], - ]; - } + /** + * @return array + */ + public function normalizeProvider() + { + return [ + ['foo:bar', 'modules/foo/templates/foo-bar.html.twig'], + ['foobar:baz', 'modules/foobar/templates/foobar-baz.html.twig'], + ['foo:bar:baz', 'modules/foo/templates/foo-bar-baz.html.twig'], + ]; + } - public function testNormalizeWithInvalidTemplate() - { - $this->setExpectedException(\InvalidArgumentException::class); - $this->templateResolver->normalize('foo'); - } + public function testNormalizeWithInvalidTemplate() + { + $this->setExpectedException(\InvalidArgumentException::class); + $this->templateResolver->normalize('foo'); + } - public function testResolveByControllerAndActionWithInvalidController() - { - $this->setExpectedException(\InvalidArgumentException::class); - $this->templateResolver->resolveByControllerAndAction('Foo', 'fooAction'); - } + public function testResolveByControllerAndActionWithInvalidController() + { + $this->setExpectedException(\InvalidArgumentException::class); + $this->templateResolver->resolveByControllerAndAction('Foo', 'fooAction'); + } } diff --git a/tests/src/polyfill.php b/tests/src/polyfill.php index 1134fd7..92b8321 100644 --- a/tests/src/polyfill.php +++ b/tests/src/polyfill.php @@ -1,15 +1,15 @@ <?php if (!function_exists('drupal_get_path')) { - function drupal_get_path($type, $name) - { - switch ($type) { - case 'module': - return 'modules/'.$name; - } - - throw new \LogicException( - sprintf('Type "%s" not implemented by this polyfill method', $type) - ); + function drupal_get_path($type, $name) + { + switch ($type) { + case 'module': + return 'modules/'.$name; } + + throw new \LogicException( + sprintf('Type "%s" not implemented by this polyfill method', $type) + ); + } } From 497d05df36ee05d6ac6aa6b72b348916c8a8b3c5 Mon Sep 17 00:00:00 2001 From: Andreas Hennings <andreas@dqxtech.net> Date: Sat, 11 Jan 2020 23:24:49 +0100 Subject: [PATCH 02/23] (CS) Function/method curly bracket on same line. --- src/Cache/DrupalCache.php | 21 ++---- src/Configuration/Cache.php | 51 +++++--------- src/Configuration/ConfigurationAnnotation.php | 3 +- src/Configuration/Method.php | 24 +++---- src/Configuration/ParamConverter.php | 39 ++++------- src/Configuration/Route.php | 24 +++---- src/Configuration/Security.php | 66 +++++++------------ src/Configuration/Template.php | 33 ++++------ src/Configuration/Title.php | 57 ++++++---------- .../ControllerEventSubscriber.php | 18 ++--- .../HttpCacheEventSubscriber.php | 30 +++------ .../ParamConverterEventSubscriber.php | 15 ++--- src/EventSubscriber/RouteEventSubscriber.php | 15 ++--- .../TemplateEventSubscriber.php | 30 +++------ .../ParamConverter/DateTimeParamConverter.php | 9 +-- .../ParamConverter/EntityParamConverter.php | 12 ++-- .../ParamConverter/ParamConverterManager.php | 15 ++--- .../AnnotatedRouteControllerLoader.php | 18 ++--- src/Templating/TemplateResolver.php | 12 ++-- .../src/Controller/AdminController.php | 6 +- .../src/Controller/BasicController.php | 3 +- .../src/Controller/InvokeController.php | 3 +- .../src/Controller/MethodController.php | 9 +-- .../Controller/ParamConverterController.php | 12 ++-- .../Controller/PrefixedRouteController.php | 6 +- .../src/Controller/SecurityController.php | 24 +++---- .../src/Controller/ServiceController.php | 3 +- .../src/Controller/TemplateController.php | 21 ++---- .../src/Controller/TitleController.php | 15 ++--- .../src/Security/Custom.php | 3 +- .../src/Title/Custom.php | 3 +- tests/src/Kernel/AnnotationsTest.php | 24 +++---- tests/src/Kernel/DrupalTestKernel.php | 6 +- tests/src/Kernel/KernelTestBase.php | 36 ++++------ tests/src/Kernel/TestUserSession.php | 3 +- tests/src/Unit/Cache/DrupalCacheTest.php | 27 +++----- tests/src/Unit/Configuration/CacheTest.php | 9 +-- tests/src/Unit/Configuration/MethodTest.php | 9 +-- tests/src/Unit/Configuration/RouteTest.php | 15 ++--- tests/src/Unit/Configuration/SecurityTest.php | 6 +- tests/src/Unit/Configuration/TitleTest.php | 9 +-- .../ControllerEventSubscriberTest.php | 21 ++---- .../EventSubscriber/HttpCacheListenerTest.php | 57 ++++++---------- .../ParamConverterEventSubscriberTest.php | 39 ++++------- .../RouteEventSubscriberTest.php | 24 +++---- .../TemplateEventSubscriberTest.php | 21 ++---- .../FooControllerNullableParameter.php | 9 +-- ...ntrollerParamConverterAtClassAndMethod.php | 3 +- tests/src/Unit/Helper.php | 3 +- .../DateTimeParamConverterTest.php | 24 +++---- .../EntityParamConverterTest.php | 36 ++++------ .../ParamConverterManagerTest.php | 24 +++---- .../AnnotatedRouteControllerLoaderTest.php | 3 +- .../Unit/Templating/TemplateResolverTest.php | 18 ++--- tests/src/polyfill.php | 3 +- 55 files changed, 343 insertions(+), 686 deletions(-) diff --git a/src/Cache/DrupalCache.php b/src/Cache/DrupalCache.php index 70961b7..8ce73ad 100644 --- a/src/Cache/DrupalCache.php +++ b/src/Cache/DrupalCache.php @@ -15,16 +15,14 @@ class DrupalCache extends CacheProvider /** * @param CacheBackendInterface $cache */ - public function __construct(CacheBackendInterface $cache) - { + public function __construct(CacheBackendInterface $cache) { $this->cache = $cache; } /** * @inheritdoc */ - protected function doFetch($id) - { + protected function doFetch($id) { if ($cache = $this->cache->get($id)) { return $cache->data; } @@ -35,16 +33,14 @@ protected function doFetch($id) /** * @inheritdoc */ - protected function doContains($id) - { + protected function doContains($id) { return $this->doFetch($id) !== false; } /** * @inheritdoc */ - protected function doSave($id, $data, $lifeTime = 0) - { + protected function doSave($id, $data, $lifeTime = 0) { if ($lifeTime === 0) { $this->cache->set($id, $data); } else { @@ -57,8 +53,7 @@ protected function doSave($id, $data, $lifeTime = 0) /** * @inheritdoc */ - protected function doDelete($id) - { + protected function doDelete($id) { $this->cache->delete($id); return true; @@ -67,8 +62,7 @@ protected function doDelete($id) /** * @inheritdoc */ - protected function doFlush() - { + protected function doFlush() { $this->cache->deleteAll(); return true; @@ -77,8 +71,7 @@ protected function doFlush() /** * @inheritdoc */ - protected function doGetStats() - { + protected function doGetStats() { return; } } diff --git a/src/Configuration/Cache.php b/src/Configuration/Cache.php index 9004311..8f5d328 100644 --- a/src/Configuration/Cache.php +++ b/src/Configuration/Cache.php @@ -63,8 +63,7 @@ class Cache extends ConfigurationAnnotation * * @return string */ - public function getExpires() - { + public function getExpires() { return $this->expires; } @@ -73,8 +72,7 @@ public function getExpires() * * @param string $expires A valid php date */ - public function setExpires($expires) - { + public function setExpires($expires) { $this->expires = $expires; } @@ -83,8 +81,7 @@ public function setExpires($expires) * * @param int $maxage A number of seconds */ - public function setMaxAge($maxage) - { + public function setMaxAge($maxage) { $this->maxage = $maxage; } @@ -94,8 +91,7 @@ public function setMaxAge($maxage) * * @return int */ - public function getMaxAge() - { + public function getMaxAge() { return $this->maxage; } @@ -104,8 +100,7 @@ public function getMaxAge() * * @param int $smaxage A number of seconds */ - public function setSMaxAge($smaxage) - { + public function setSMaxAge($smaxage) { $this->smaxage = $smaxage; } @@ -115,8 +110,7 @@ public function setSMaxAge($smaxage) * * @return int */ - public function getSMaxAge() - { + public function getSMaxAge() { return $this->smaxage; } @@ -125,8 +119,7 @@ public function getSMaxAge() * * @return bool */ - public function isPublic() - { + public function isPublic() { return $this->public === true; } @@ -135,8 +128,7 @@ public function isPublic() * * @return bool */ - public function isPrivate() - { + public function isPrivate() { return $this->public === false; } @@ -145,8 +137,7 @@ public function isPrivate() * * @param bool $public A boolean value */ - public function setPublic($public) - { + public function setPublic($public) { $this->public = (bool)$public; } @@ -155,8 +146,7 @@ public function setPublic($public) * * @return array */ - public function getVary() - { + public function getVary() { return $this->vary; } @@ -165,8 +155,7 @@ public function getVary() * * @param array $vary */ - public function setVary($vary) - { + public function setVary($vary) { $this->vary = $vary; } @@ -175,8 +164,7 @@ public function setVary($vary) * * @param string $expression */ - public function setLastModified($expression) - { + public function setLastModified($expression) { $this->lastModified = $expression; } @@ -185,8 +173,7 @@ public function setLastModified($expression) * * @return string */ - public function getLastModified() - { + public function getLastModified() { return $this->lastModified; } @@ -195,8 +182,7 @@ public function getLastModified() * * @param string $expression */ - public function setETag($expression) - { + public function setETag($expression) { $this->etag = $expression; } @@ -205,8 +191,7 @@ public function setETag($expression) * * @return string */ - public function getETag() - { + public function getETag() { return $this->etag; } @@ -217,8 +202,7 @@ public function getETag() * * @see ConfigurationInterface */ - public function getAliasName() - { + public function getAliasName() { return 'cache'; } @@ -229,8 +213,7 @@ public function getAliasName() * * @see ConfigurationInterface */ - public function allowArray() - { + public function allowArray() { return false; } } diff --git a/src/Configuration/ConfigurationAnnotation.php b/src/Configuration/ConfigurationAnnotation.php index fb05f53..1fe8757 100644 --- a/src/Configuration/ConfigurationAnnotation.php +++ b/src/Configuration/ConfigurationAnnotation.php @@ -9,8 +9,7 @@ */ abstract class ConfigurationAnnotation implements ConfigurationInterface { - public function __construct(array $values) - { + public function __construct(array $values) { foreach ($values as $k => $v) { if (!method_exists($this, $name = 'set'.$k)) { throw new \RuntimeException(sprintf('Unknown key "%s" for annotation "@%s".', $k, get_class($this))); diff --git a/src/Configuration/Method.php b/src/Configuration/Method.php index d89c2be..ba6f63c 100644 --- a/src/Configuration/Method.php +++ b/src/Configuration/Method.php @@ -21,8 +21,7 @@ class Method extends ConfigurationAnnotation implements RouteModifierMethodInter * * @return array */ - public function getMethods() - { + public function getMethods() { return $this->methods; } @@ -31,8 +30,7 @@ public function getMethods() * * @param array|string $methods An HTTP method or an array of HTTP methods */ - public function setMethods($methods) - { + public function setMethods($methods) { $this->methods = is_array($methods) ? $methods : array($methods); } @@ -41,8 +39,7 @@ public function setMethods($methods) * * @param array|string $methods An HTTP method or an array of HTTP methods */ - public function setValue($methods) - { + public function setValue($methods) { $this->setMethods($methods); } @@ -53,8 +50,7 @@ public function setValue($methods) * * @see ConfigurationInterface */ - public function getAliasName() - { + public function getAliasName() { return 'method'; } @@ -65,8 +61,7 @@ public function getAliasName() * * @see ConfigurationInterface */ - public function allowArray() - { + public function allowArray() { return false; } @@ -75,8 +70,7 @@ public function allowArray() * @param \ReflectionClass $class * @param \ReflectionMethod $method */ - public function modifyRouteClass(RoutingRoute $route, \ReflectionClass $class, \ReflectionMethod $method) - { + public function modifyRouteClass(RoutingRoute $route, \ReflectionClass $class, \ReflectionMethod $method) { $this->modifyRoute($route); } @@ -85,8 +79,7 @@ public function modifyRouteClass(RoutingRoute $route, \ReflectionClass $class, \ * @param \ReflectionClass $class * @param \ReflectionMethod $method */ - public function modifyRouteMethod(RoutingRoute $route, \ReflectionClass $class, \ReflectionMethod $method) - { + public function modifyRouteMethod(RoutingRoute $route, \ReflectionClass $class, \ReflectionMethod $method) { $this->modifyRoute($route); } @@ -96,8 +89,7 @@ public function modifyRouteMethod(RoutingRoute $route, \ReflectionClass $class, * * @param RoutingRoute $route */ - protected function modifyRoute(RoutingRoute $route) - { + protected function modifyRoute(RoutingRoute $route) { $route->setMethods($this->getMethods()); } } diff --git a/src/Configuration/ParamConverter.php b/src/Configuration/ParamConverter.php index 8642838..6201b58 100644 --- a/src/Configuration/ParamConverter.php +++ b/src/Configuration/ParamConverter.php @@ -51,8 +51,7 @@ class ParamConverter extends ConfigurationAnnotation * * @return string */ - public function getName() - { + public function getName() { return $this->name; } @@ -61,8 +60,7 @@ public function getName() * * @param string $name The parameter name */ - public function setValue($name) - { + public function setValue($name) { $this->setName($name); } @@ -71,8 +69,7 @@ public function setValue($name) * * @param string $name The parameter name */ - public function setName($name) - { + public function setName($name) { $this->name = $name; } @@ -81,8 +78,7 @@ public function setName($name) * * @return string $name */ - public function getClass() - { + public function getClass() { return $this->class; } @@ -91,8 +87,7 @@ public function getClass() * * @param string $class The parameter class name */ - public function setClass($class) - { + public function setClass($class) { $this->class = $class; } @@ -101,8 +96,7 @@ public function setClass($class) * * @return array */ - public function getOptions() - { + public function getOptions() { return $this->options; } @@ -111,8 +105,7 @@ public function getOptions() * * @param array $options An array of options */ - public function setOptions($options) - { + public function setOptions($options) { $this->options = $options; } @@ -121,8 +114,7 @@ public function setOptions($options) * * @param bool $optional Whether the parameter is optional */ - public function setIsOptional($optional) - { + public function setIsOptional($optional) { $this->optional = (bool)$optional; } @@ -131,8 +123,7 @@ public function setIsOptional($optional) * * @return bool */ - public function isOptional() - { + public function isOptional() { return $this->optional; } @@ -141,8 +132,7 @@ public function isOptional() * * @return string */ - public function getConverter() - { + public function getConverter() { return $this->converter; } @@ -151,8 +141,7 @@ public function getConverter() * * @param string $converter */ - public function setConverter($converter) - { + public function setConverter($converter) { $this->converter = $converter; } @@ -163,8 +152,7 @@ public function setConverter($converter) * * @see ConfigurationInterface */ - public function getAliasName() - { + public function getAliasName() { return 'converters'; } @@ -175,8 +163,7 @@ public function getAliasName() * * @see ConfigurationInterface */ - public function allowArray() - { + public function allowArray() { return true; } } diff --git a/src/Configuration/Route.php b/src/Configuration/Route.php index 22833f7..ffb4b26 100644 --- a/src/Configuration/Route.php +++ b/src/Configuration/Route.php @@ -24,8 +24,7 @@ class Route extends BaseRoute implements RouteModifierMethodInterface, RouteModi /** * @param $service */ - public function setService($service) - { + public function setService($service) { // avoid a BC notice in case of @Route(service="") with sf ^2.7 if (null === $this->getPath()) { $this->setPath(''); @@ -33,16 +32,14 @@ public function setService($service) $this->service = $service; } - public function getService() - { + public function getService() { return $this->service; } /** * @return bool */ - public function isAdmin() - { + public function isAdmin() { return $this->admin; } @@ -50,8 +47,7 @@ public function isAdmin() * @param bool $admin * @return Route */ - public function setAdmin($admin) - { + public function setAdmin($admin) { $this->admin = $admin; return $this; @@ -64,8 +60,7 @@ public function setAdmin($admin) * * @see ConfigurationInterface */ - public function allowArray() - { + public function allowArray() { return true; } @@ -74,8 +69,7 @@ public function allowArray() * @param \ReflectionClass $class * @param \ReflectionMethod $method */ - public function modifyRouteClass(RoutingRoute $route, \ReflectionClass $class, \ReflectionMethod $method) - { + public function modifyRouteClass(RoutingRoute $route, \ReflectionClass $class, \ReflectionMethod $method) { $this->modifyRoute($route, $class, $method); } @@ -84,8 +78,7 @@ public function modifyRouteClass(RoutingRoute $route, \ReflectionClass $class, \ * @param \ReflectionClass $class * @param \ReflectionMethod $method */ - public function modifyRouteMethod(RoutingRoute $route, \ReflectionClass $class, \ReflectionMethod $method) - { + public function modifyRouteMethod(RoutingRoute $route, \ReflectionClass $class, \ReflectionMethod $method) { if ($this->getService()) { throw new \LogicException('The service option can only be specified at class level.'); } @@ -98,8 +91,7 @@ public function modifyRouteMethod(RoutingRoute $route, \ReflectionClass $class, * @param \ReflectionClass $class * @param \ReflectionMethod $method */ - protected function modifyRoute(RoutingRoute $route, \ReflectionClass $class, \ReflectionMethod $method) - { + protected function modifyRoute(RoutingRoute $route, \ReflectionClass $class, \ReflectionMethod $method) { if ($this->isAdmin()) { $route->setOption('_admin_route', true); } diff --git a/src/Configuration/Security.php b/src/Configuration/Security.php index fd78661..142f90d 100644 --- a/src/Configuration/Security.php +++ b/src/Configuration/Security.php @@ -42,16 +42,14 @@ class Security extends ConfigurationAnnotation implements RouteModifierMethodInt /** * @return bool */ - public function hasPermission() - { + public function hasPermission() { return !empty($this->permission); } /** * @return string */ - public function getPermission() - { + public function getPermission() { return $this->permission; } @@ -59,8 +57,7 @@ public function getPermission() * @param string $permission * @return Security */ - public function setPermission($permission) - { + public function setPermission($permission) { $this->permission = $permission; return $this; @@ -69,16 +66,14 @@ public function setPermission($permission) /** * @return bool */ - public function hasRole() - { + public function hasRole() { return !empty($this->role); } /** * @return string */ - public function getRole() - { + public function getRole() { return $this->role; } @@ -86,8 +81,7 @@ public function getRole() * @param string $role * @return Security */ - public function setRole($role) - { + public function setRole($role) { $this->role = $role; return $this; @@ -96,8 +90,7 @@ public function setRole($role) /** * @return bool */ - public function isAccess() - { + public function isAccess() { return $this->access; } @@ -105,8 +98,7 @@ public function isAccess() * @param bool $access * @return Security */ - public function setAccess($access) - { + public function setAccess($access) { $this->access = $access; return $this; @@ -115,16 +107,14 @@ public function setAccess($access) /** * @return bool */ - public function hasEntity() - { + public function hasEntity() { return !empty($this->entity); } /** * @return string */ - public function getEntity() - { + public function getEntity() { return $this->entity; } @@ -132,8 +122,7 @@ public function getEntity() * @param string $entity * @return Security */ - public function setEntity($entity) - { + public function setEntity($entity) { $this->entity = $entity; return $this; @@ -142,16 +131,14 @@ public function setEntity($entity) /** * @return bool */ - public function hasCustom() - { + public function hasCustom() { return !empty($this->custom); } /** * @return string */ - public function getCustom() - { + public function getCustom() { return $this->custom; } @@ -159,8 +146,7 @@ public function getCustom() * @param string $custom * @return Security */ - public function setCustom($custom) - { + public function setCustom($custom) { $this->custom = $custom; return $this; @@ -169,8 +155,7 @@ public function setCustom($custom) /** * @return bool */ - public function hasCsrf() - { + public function hasCsrf() { return !empty($this->csrf); } @@ -178,20 +163,17 @@ public function hasCsrf() * @param bool $csrf * @return Security */ - public function setCsrf($csrf) - { + public function setCsrf($csrf) { $this->csrf = $csrf; return $this; } - public function getAliasName() - { + public function getAliasName() { return 'security'; } - public function allowArray() - { + public function allowArray() { return false; } @@ -200,8 +182,7 @@ public function allowArray() * @param \ReflectionClass $class * @param \ReflectionMethod $method */ - public function modifyRouteClass(RoutingRoute $route, \ReflectionClass $class, \ReflectionMethod $method) - { + public function modifyRouteClass(RoutingRoute $route, \ReflectionClass $class, \ReflectionMethod $method) { $this->modifyRoute($route, $class); } @@ -210,8 +191,7 @@ public function modifyRouteClass(RoutingRoute $route, \ReflectionClass $class, \ * @param \ReflectionClass $class * @param \ReflectionMethod $method */ - public function modifyRouteMethod(RoutingRoute $route, \ReflectionClass $class, \ReflectionMethod $method) - { + public function modifyRouteMethod(RoutingRoute $route, \ReflectionClass $class, \ReflectionMethod $method) { $this->modifyRoute($route, $class); } @@ -219,8 +199,7 @@ public function modifyRouteMethod(RoutingRoute $route, \ReflectionClass $class, * @param RoutingRoute $route * @param \ReflectionClass $class */ - protected function modifyRoute(RoutingRoute $route, \ReflectionClass $class) - { + protected function modifyRoute(RoutingRoute $route, \ReflectionClass $class) { if ($this->isAccess()) { $route->setRequirement('_access', 'TRUE'); } @@ -244,8 +223,7 @@ protected function modifyRoute(RoutingRoute $route, \ReflectionClass $class) * @param RoutingRoute $route * @param \ReflectionClass $class */ - protected function setCustomSecurity(RoutingRoute $route, \ReflectionClass $class) - { + protected function setCustomSecurity(RoutingRoute $route, \ReflectionClass $class) { if ($this->hasCustom()) { if (strpos($this->getCustom(), '::') === false && $class->hasMethod($this->getCustom())) { $this->setCustom(sprintf('%s::%s', $class->getName(), $this->getCustom())); diff --git a/src/Configuration/Template.php b/src/Configuration/Template.php index f48e64c..7ee6a88 100644 --- a/src/Configuration/Template.php +++ b/src/Configuration/Template.php @@ -41,24 +41,21 @@ class Template extends ConfigurationAnnotation * * @return array */ - public function getVars() - { + public function getVars() { return $this->vars; } /** * @param bool $streamable */ - public function setIsStreamable($streamable) - { + public function setIsStreamable($streamable) { $this->streamable = $streamable; } /** * @return bool */ - public function isStreamable() - { + public function isStreamable() { return (bool)$this->streamable; } @@ -67,8 +64,7 @@ public function isStreamable() * * @param array $vars The template variables */ - public function setVars($vars) - { + public function setVars($vars) { $this->vars = $vars; } @@ -77,8 +73,7 @@ public function setVars($vars) * * @param string $template The template logic name */ - public function setValue($template) - { + public function setValue($template) { $this->setTemplate($template); } @@ -87,8 +82,7 @@ public function setValue($template) * * @return string */ - public function getTemplate() - { + public function getTemplate() { return $this->template; } @@ -97,8 +91,7 @@ public function getTemplate() * * @param string $template The template reference */ - public function setTemplate($template) - { + public function setTemplate($template) { $this->template = $template; } @@ -109,8 +102,7 @@ public function setTemplate($template) * * @see ConfigurationInterface */ - public function getAliasName() - { + public function getAliasName() { return 'template'; } @@ -121,16 +113,14 @@ public function getAliasName() * * @see ConfigurationInterface */ - public function allowArray() - { + public function allowArray() { return false; } /** * @param array $owner */ - public function setOwner(array $owner) - { + public function setOwner(array $owner) { $this->owner = $owner; } @@ -139,8 +129,7 @@ public function setOwner(array $owner) * * @return array */ - public function getOwner() - { + public function getOwner() { return $this->owner; } } diff --git a/src/Configuration/Title.php b/src/Configuration/Title.php index 50ba4bb..c03d2a5 100644 --- a/src/Configuration/Title.php +++ b/src/Configuration/Title.php @@ -32,120 +32,105 @@ class Title extends ConfigurationAnnotation implements RouteModifierMethodInterf /** * @param $title */ - public function setValue($title) - { + public function setValue($title) { $this->setTitle($title); } /** * @return bool */ - public function hasTitle() - { + public function hasTitle() { return !empty($this->value); } /** * @return string */ - public function getTitle() - { + public function getTitle() { return $this->value; } /** * @param string $title */ - public function setTitle($title) - { + public function setTitle($title) { $this->value = $title; } /** * @return bool */ - public function hasArguments() - { + public function hasArguments() { return !empty($this->arguments); } /** * @return array */ - public function getArguments() - { + public function getArguments() { return $this->arguments; } /** * @param array $arguments */ - public function setArguments(array $arguments) - { + public function setArguments(array $arguments) { $this->arguments = $arguments; } /** * @return bool */ - public function hasContext() - { + public function hasContext() { return !empty($this->context); } /** * @return array */ - public function getContext() - { + public function getContext() { return $this->context; } /** * @param array $context */ - public function setContext(array $context) - { + public function setContext(array $context) { $this->context = $context; } /** * @return bool */ - public function hasCallback() - { + public function hasCallback() { return !empty($this->callback); } /** * @return string */ - public function getCallback() - { + public function getCallback() { return $this->callback; } /** * @param string $callback */ - public function setCallback($callback) - { + public function setCallback($callback) { $this->callback = $callback; } /** * @return string */ - public function getAliasName() - { + public function getAliasName() { return 'title'; } /** * @return bool */ - public function allowArray() - { + public function allowArray() { return false; } @@ -154,8 +139,7 @@ public function allowArray() * @param \ReflectionClass $class * @param \ReflectionMethod $method */ - public function modifyRouteClass(RoutingRoute $route, \ReflectionClass $class, \ReflectionMethod $method) - { + public function modifyRouteClass(RoutingRoute $route, \ReflectionClass $class, \ReflectionMethod $method) { $this->modifyRoute($route, $class); } @@ -164,8 +148,7 @@ public function modifyRouteClass(RoutingRoute $route, \ReflectionClass $class, \ * @param \ReflectionClass $class * @param \ReflectionMethod $method */ - public function modifyRouteMethod(RoutingRoute $route, \ReflectionClass $class, \ReflectionMethod $method) - { + public function modifyRouteMethod(RoutingRoute $route, \ReflectionClass $class, \ReflectionMethod $method) { $this->modifyRoute($route, $class); } @@ -173,8 +156,7 @@ public function modifyRouteMethod(RoutingRoute $route, \ReflectionClass $class, * @param RoutingRoute $route * @param \ReflectionClass $class */ - protected function modifyRoute(RoutingRoute $route, \ReflectionClass $class) - { + protected function modifyRoute(RoutingRoute $route, \ReflectionClass $class) { if ($this->hasTitle()) { $route->setDefault('_title', $this->getTitle()); } @@ -192,8 +174,7 @@ protected function modifyRoute(RoutingRoute $route, \ReflectionClass $class) * @param RoutingRoute $route * @param \ReflectionClass $class */ - protected function registerCallback(RoutingRoute $route, \ReflectionClass $class) - { + protected function registerCallback(RoutingRoute $route, \ReflectionClass $class) { if ($this->hasCallback()) { if (strpos($this->getCallback(), '::') === false && $class->hasMethod($this->getCallback())) { $this->setCallback(sprintf('%s::%s', $class->getName(), $this->getCallback())); diff --git a/src/EventSubscriber/ControllerEventSubscriber.php b/src/EventSubscriber/ControllerEventSubscriber.php index 9b8dc2f..b55ec3e 100644 --- a/src/EventSubscriber/ControllerEventSubscriber.php +++ b/src/EventSubscriber/ControllerEventSubscriber.php @@ -20,8 +20,7 @@ class ControllerEventSubscriber implements EventSubscriberInterface /** * @param Reader $reader */ - public function __construct(Reader $reader) - { + public function __construct(Reader $reader) { $this->reader = $reader; } @@ -33,8 +32,7 @@ public function __construct(Reader $reader) * @param FilterControllerEvent $event * @throws \ReflectionException */ - public function onKernelController(FilterControllerEvent $event) - { + public function onKernelController(FilterControllerEvent $event) { $controller = $event->getController(); if (!is_array($controller) && method_exists($controller, '__invoke')) { @@ -62,8 +60,7 @@ public function onKernelController(FilterControllerEvent $event) * @param Request $request * @param array $configurations */ - protected function setRequestAttributes(Request $request, array $configurations) - { + protected function setRequestAttributes(Request $request, array $configurations) { foreach ($configurations as $key => $attributes) { $request->attributes->set($key, $attributes); } @@ -75,8 +72,7 @@ protected function setRequestAttributes(Request $request, array $configurations) * * @return array */ - protected function mergeConfigurations(array $classConfigurations, array $methodConfigurations) - { + protected function mergeConfigurations(array $classConfigurations, array $methodConfigurations) { $configurations = []; foreach (array_merge(array_keys($classConfigurations), array_keys($methodConfigurations)) as $key) { if (!array_key_exists($key, $classConfigurations)) { @@ -106,8 +102,7 @@ protected function mergeConfigurations(array $classConfigurations, array $method * * @return array */ - protected function getConfigurations(array $annotations) - { + protected function getConfigurations(array $annotations) { $configurations = []; foreach ($annotations as $configuration) { if ($configuration instanceof ConfigurationInterface) { @@ -129,8 +124,7 @@ protected function getConfigurations(array $annotations) /** * @return array */ - public static function getSubscribedEvents() - { + public static function getSubscribedEvents() { return [ KernelEvents::CONTROLLER => [ ['onKernelController', 200], diff --git a/src/EventSubscriber/HttpCacheEventSubscriber.php b/src/EventSubscriber/HttpCacheEventSubscriber.php index dace62e..0e60540 100644 --- a/src/EventSubscriber/HttpCacheEventSubscriber.php +++ b/src/EventSubscriber/HttpCacheEventSubscriber.php @@ -31,8 +31,7 @@ class HttpCacheEventSubscriber implements EventSubscriberInterface /** */ - public function __construct() - { + public function __construct() { $this->lastModifiedDates = new \SplObjectStorage(); $this->eTags = new \SplObjectStorage(); } @@ -42,8 +41,7 @@ public function __construct() * * @param FilterControllerEvent $event */ - public function onKernelController(FilterControllerEvent $event) - { + public function onKernelController(FilterControllerEvent $event) { $request = $event->getRequest(); if (!$configuration = $this->getConfiguration($request)) { return; @@ -72,8 +70,7 @@ function () use ($response) { * * @param FilterResponseEvent $event */ - public function onKernelResponse(FilterResponseEvent $event) - { + public function onKernelResponse(FilterResponseEvent $event) { $request = $event->getRequest(); if (!$configuration = $this->getConfiguration($request)) { return; @@ -126,8 +123,7 @@ protected function setETag( * * @return string */ - protected function createETag(Request $request, Cache $configuration) - { + protected function createETag(Request $request, Cache $configuration) { return hash( 'sha256', $this->getExpressionLanguage()->evaluate( @@ -142,8 +138,7 @@ protected function createETag(Request $request, Cache $configuration) * * @return float */ - protected function calculateAge($age) - { + protected function calculateAge($age) { $now = microtime(true); return ceil(strtotime($age, $now) - $now); @@ -154,8 +149,7 @@ protected function calculateAge($age) * * @return Cache|false */ - protected function getConfiguration(Request $request) - { + protected function getConfiguration(Request $request) { $configuration = $request->attributes->get('_cache'); if (empty($configuration) || !$configuration instanceof Cache) { return false; @@ -224,8 +218,7 @@ protected function setCacheProperties( * * @return bool|\DateTime */ - protected function calculateExpires(Cache $configuration) - { + protected function calculateExpires(Cache $configuration) { return \DateTime::createFromFormat( 'U', strtotime($configuration->getExpires()), @@ -240,8 +233,7 @@ protected function calculateExpires(Cache $configuration) * * @return bool */ - protected function hasUncachableStatusCode(Response $response) - { + protected function hasUncachableStatusCode(Response $response) { if (!in_array( $response->getStatusCode(), [200, 203, 300, 301, 302, 304, 404, 410] @@ -256,8 +248,7 @@ protected function hasUncachableStatusCode(Response $response) * @codeCoverageIgnore * @return ExpressionLanguage */ - private function getExpressionLanguage() - { + private function getExpressionLanguage() { if (null === $this->expressionLanguage) { if (!class_exists(ExpressionLanguage::class)) { throw new \RuntimeException( @@ -273,8 +264,7 @@ private function getExpressionLanguage() /** * @return array */ - public static function getSubscribedEvents() - { + public static function getSubscribedEvents() { return [ KernelEvents::CONTROLLER => [ ['onKernelController', 0], diff --git a/src/EventSubscriber/ParamConverterEventSubscriber.php b/src/EventSubscriber/ParamConverterEventSubscriber.php index 0b9188c..bc5610c 100644 --- a/src/EventSubscriber/ParamConverterEventSubscriber.php +++ b/src/EventSubscriber/ParamConverterEventSubscriber.php @@ -30,8 +30,7 @@ class ParamConverterEventSubscriber implements EventSubscriberInterface * @param ParamConverterManager $manager A ParamConverterManager instance * @param bool $autoConvert Auto convert non-configured objects */ - public function __construct(ParamConverterManager $manager, $autoConvert = true) - { + public function __construct(ParamConverterManager $manager, $autoConvert = true) { $this->manager = $manager; $this->autoConvert = $autoConvert; $this->isParameterTypeSupported = method_exists('ReflectionParameter', 'getType'); @@ -42,8 +41,7 @@ public function __construct(ParamConverterManager $manager, $autoConvert = true) * * @param FilterControllerEvent $event A FilterControllerEvent instance */ - public function onKernelController(FilterControllerEvent $event) - { + public function onKernelController(FilterControllerEvent $event) { $controller = $event->getController(); $request = $event->getRequest(); $configurations = []; @@ -67,8 +65,7 @@ public function onKernelController(FilterControllerEvent $event) * * @return \ReflectionFunction|\ReflectionMethod */ - protected function resolveMethod($controller) - { + protected function resolveMethod($controller) { if (is_array($controller)) { return new \ReflectionMethod($controller[0], $controller[1]); } @@ -86,8 +83,7 @@ protected function resolveMethod($controller) * * @return array */ - private function autoConfigure(\ReflectionFunctionAbstract $r, Request $request, $configurations) - { + private function autoConfigure(\ReflectionFunctionAbstract $r, Request $request, $configurations) { foreach ($r->getParameters() as $param) { if ($param->getClass() && $param->getClass()->isInstance($request)) { continue; @@ -125,8 +121,7 @@ private function autoConfigure(\ReflectionFunctionAbstract $r, Request $request, /** * @return array */ - public static function getSubscribedEvents() - { + public static function getSubscribedEvents() { return [ KernelEvents::CONTROLLER => [ ['onKernelController', 100], diff --git a/src/EventSubscriber/RouteEventSubscriber.php b/src/EventSubscriber/RouteEventSubscriber.php index cc4af84..f51ac0b 100644 --- a/src/EventSubscriber/RouteEventSubscriber.php +++ b/src/EventSubscriber/RouteEventSubscriber.php @@ -25,8 +25,7 @@ class RouteEventSubscriber implements EventSubscriberInterface * @param AnnotationDirectoryLoader $annotationDirectoryLoader * @param string $rootPath */ - public function __construct(AnnotationDirectoryLoader $annotationDirectoryLoader, string $rootPath) - { + public function __construct(AnnotationDirectoryLoader $annotationDirectoryLoader, string $rootPath) { $this->registerAnnotations(); $this->annotationDirectoryLoader = $annotationDirectoryLoader; $this->rootPath = $rootPath; @@ -35,8 +34,7 @@ public function __construct(AnnotationDirectoryLoader $annotationDirectoryLoader /** * Configure the annotation registry to make routing annotations available */ - private function registerAnnotations() - { + private function registerAnnotations() { AnnotationRegistry::registerLoader('class_exists'); } @@ -44,8 +42,7 @@ private function registerAnnotations() * @param RouteBuildEvent $event * @throws \Exception */ - public function onRoutes(RouteBuildEvent $event) - { + public function onRoutes(RouteBuildEvent $event) { /** * @var $route Route */ @@ -65,8 +62,7 @@ public function onRoutes(RouteBuildEvent $event) /** * @return array */ - public static function getSubscribedEvents() - { + public static function getSubscribedEvents() { return [ RoutingEvents::DYNAMIC => [ ['onRoutes', 0], @@ -79,8 +75,7 @@ public static function getSubscribedEvents() * @return string * @throws \Exception */ - protected function getRoutePath(Route $route) - { + protected function getRoutePath(Route $route) { if ($route->hasOption('path')) { $path = $route->getOption('path'); } elseif ($route->hasOption('module')) { diff --git a/src/EventSubscriber/TemplateEventSubscriber.php b/src/EventSubscriber/TemplateEventSubscriber.php index 9b672c8..a66a789 100644 --- a/src/EventSubscriber/TemplateEventSubscriber.php +++ b/src/EventSubscriber/TemplateEventSubscriber.php @@ -29,8 +29,7 @@ class TemplateEventSubscriber implements EventSubscriberInterface * @param \Twig_Environment $twig * @param TemplateResolver $resolver */ - public function __construct(\Twig_Environment $twig, TemplateResolver $resolver) - { + public function __construct(\Twig_Environment $twig, TemplateResolver $resolver) { $this->twig = $twig; $this->resolver = $resolver; } @@ -41,8 +40,7 @@ public function __construct(\Twig_Environment $twig, TemplateResolver $resolver) * * @param FilterControllerEvent $event A FilterControllerEvent instance */ - public function onKernelController(FilterControllerEvent $event) - { + public function onKernelController(FilterControllerEvent $event) { $template = $this->getTemplateFromRequest($event); if (!$template instanceof Template) { return; @@ -58,8 +56,7 @@ public function onKernelController(FilterControllerEvent $event) * * @param GetResponseForControllerResultEvent $event */ - public function onKernelView(GetResponseForControllerResultEvent $event) - { + public function onKernelView(GetResponseForControllerResultEvent $event) { $template = $this->getTemplateFromRequest($event); if (!$template instanceof Template) { return; @@ -72,16 +69,14 @@ public function onKernelView(GetResponseForControllerResultEvent $event) * @param KernelEvent $event * @return mixed */ - private function getTemplateFromRequest(KernelEvent $event) - { + private function getTemplateFromRequest(KernelEvent $event) { return $event->getRequest()->attributes->get('_template'); } /** * @param Template $template */ - private function normalizeTemplate(Template $template) - { + private function normalizeTemplate(Template $template) { if (is_null($template->getTemplate())) { $templateFile = $this->resolver->resolveByControllerAndAction( get_class($template->getOwner()[0]), @@ -99,8 +94,7 @@ private function normalizeTemplate(Template $template) * @param Template $template * @param $parameters */ - private function setResponse(GetResponseForControllerResultEvent $event, Template $template, $parameters) - { + private function setResponse(GetResponseForControllerResultEvent $event, Template $template, $parameters) { // make sure the owner (controller+dependencies) is not cached or stored elsewhere $template->setOwner([]); @@ -120,8 +114,7 @@ private function setResponse(GetResponseForControllerResultEvent $event, Templat * @param Template $template * @return array|mixed */ - private function getParameters(GetResponseForControllerResultEvent $event, Template $template) - { + private function getParameters(GetResponseForControllerResultEvent $event, Template $template) { $parameters = $event->getControllerResult(); $owner = $template->getOwner(); @@ -143,8 +136,7 @@ private function getParameters(GetResponseForControllerResultEvent $event, Templ * @param string $action * @return array */ - private function resolveDefaultParameters(Request $request, Template $template, $controller, $action) - { + private function resolveDefaultParameters(Request $request, Template $template, $controller, $action) { $arguments = $template->getVars(); if (0 === count($arguments)) { @@ -167,8 +159,7 @@ private function resolveDefaultParameters(Request $request, Template $template, * @param array $arguments * @return array */ - private function resolveParametersWithReflection(Request $request, array $arguments) - { + private function resolveParametersWithReflection(Request $request, array $arguments) { $parameters = []; foreach ($arguments as $argument) { if ($argument instanceof \ReflectionParameter) { @@ -188,8 +179,7 @@ private function resolveParametersWithReflection(Request $request, array $argume /** * @return array */ - public static function getSubscribedEvents() - { + public static function getSubscribedEvents() { return [ KernelEvents::CONTROLLER => ['onKernelController', 100], KernelEvents::VIEW => ['onKernelView', 10], diff --git a/src/Request/ParamConverter/DateTimeParamConverter.php b/src/Request/ParamConverter/DateTimeParamConverter.php index 7db9f90..9b21ad8 100644 --- a/src/Request/ParamConverter/DateTimeParamConverter.php +++ b/src/Request/ParamConverter/DateTimeParamConverter.php @@ -19,8 +19,7 @@ class DateTimeParamConverter implements ParamConverterInterface * * @throws NotFoundHttpException When invalid date given */ - public function apply(Request $request, ParamConverter $configuration) - { + public function apply(Request $request, ParamConverter $configuration) { $param = $configuration->getName(); if (!$request->attributes->has($param)) { return false; @@ -46,8 +45,7 @@ public function apply(Request $request, ParamConverter $configuration) * @return bool|DateTime * @throws \Exception */ - protected function getDateTime(ParamConverter $configuration, $value, $param) - { + protected function getDateTime(ParamConverter $configuration, $value, $param) { $options = $configuration->getOptions(); if (isset($options['format'])) { @@ -68,8 +66,7 @@ protected function getDateTime(ParamConverter $configuration, $value, $param) /** * {@inheritdoc} */ - public function supports(ParamConverter $configuration) - { + public function supports(ParamConverter $configuration) { return \DateTime::class === $configuration->getClass(); } } diff --git a/src/Request/ParamConverter/EntityParamConverter.php b/src/Request/ParamConverter/EntityParamConverter.php index bb2dfce..b9ab9d2 100644 --- a/src/Request/ParamConverter/EntityParamConverter.php +++ b/src/Request/ParamConverter/EntityParamConverter.php @@ -24,8 +24,7 @@ class EntityParamConverter implements ParamConverterInterface /** * @param EntityTypeManagerInterface $entityTypeManager */ - public function __construct(EntityTypeManagerInterface $entityTypeManager) - { + public function __construct(EntityTypeManagerInterface $entityTypeManager) { $this->entityTypeManager = $entityTypeManager; } @@ -35,8 +34,7 @@ public function __construct(EntityTypeManagerInterface $entityTypeManager) * * @return bool */ - public function apply(Request $request, ParamConverter $configuration) - { + public function apply(Request $request, ParamConverter $configuration) { $param = $configuration->getName(); if (!$request->attributes->has($param)) { return false; @@ -61,8 +59,7 @@ public function apply(Request $request, ParamConverter $configuration) * * @return EntityInterface|null */ - protected function getNode($value, ParamConverter $configuration) - { + protected function getNode($value, ParamConverter $configuration) { $node = $this->entityTypeManager->getStorage('node')->load($value); $this->assertValidNode($configuration, $node); @@ -96,8 +93,7 @@ protected function assertValidNode( * * @return bool */ - public function supports(ParamConverter $configuration) - { + public function supports(ParamConverter $configuration) { return in_array( $configuration->getClass(), [ diff --git a/src/Request/ParamConverter/ParamConverterManager.php b/src/Request/ParamConverter/ParamConverterManager.php index d95f094..3dbb042 100644 --- a/src/Request/ParamConverter/ParamConverterManager.php +++ b/src/Request/ParamConverter/ParamConverterManager.php @@ -29,8 +29,7 @@ class ParamConverterManager * @param Request $request * @param array|object $configurations */ - public function apply(Request $request, $configurations) - { + public function apply(Request $request, $configurations) { if (is_object($configurations)) { $configurations = [$configurations]; } @@ -46,8 +45,7 @@ public function apply(Request $request, $configurations) * @param Request $request * @param ParamConverter $configuration */ - protected function applyConverter(Request $request, ParamConverter $configuration) - { + protected function applyConverter(Request $request, ParamConverter $configuration) { $value = $request->attributes->get($configuration->getName()); $className = $configuration->getClass(); @@ -76,8 +74,7 @@ protected function applyConverter(Request $request, ParamConverter $configuratio * @param Request $request * @param ParamConverter $configuration */ - protected function applyNamedConverter(Request $request, ParamConverter $configuration) - { + protected function applyNamedConverter(Request $request, ParamConverter $configuration) { $converterName = $configuration->getConverter(); if (!isset($this->namedConverters[$converterName])) { throw new \RuntimeException( @@ -116,8 +113,7 @@ protected function applyNamedConverter(Request $request, ParamConverter $configu * @param int $priority The priority (between -10 and 10). * @param string $name Name of the converter. */ - public function add(ParamConverterInterface $converter, $priority = 0, $name = null) - { + public function add(ParamConverterInterface $converter, $priority = 0, $name = null) { if ($priority !== null) { if (!isset($this->converters[$priority])) { $this->converters[$priority] = []; @@ -136,8 +132,7 @@ public function add(ParamConverterInterface $converter, $priority = 0, $name = n * * @return array An array of param converters */ - public function all() - { + public function all() { krsort($this->converters); $converters = array(); diff --git a/src/Routing/AnnotatedRouteControllerLoader.php b/src/Routing/AnnotatedRouteControllerLoader.php index 4c1aaba..09cfd0e 100644 --- a/src/Routing/AnnotatedRouteControllerLoader.php +++ b/src/Routing/AnnotatedRouteControllerLoader.php @@ -16,8 +16,7 @@ class AnnotatedRouteControllerLoader extends AnnotationClassLoader * @param \ReflectionMethod $method * @param mixed $annotation */ - protected function configureRoute(Route $route, \ReflectionClass $class, \ReflectionMethod $method, $annotation) - { + protected function configureRoute(Route $route, \ReflectionClass $class, \ReflectionMethod $method, $annotation) { $this->setController($route, $class, $method); $this->configureClassAnnotations($route, $class, $method); $this->configureMethodAnnotations($route, $class, $method); @@ -27,8 +26,7 @@ protected function configureRoute(Route $route, \ReflectionClass $class, \Reflec * @param \ReflectionClass $class * @return array */ - protected function getGlobals(\ReflectionClass $class): array - { + protected function getGlobals(\ReflectionClass $class): array { $globals = parent::getGlobals($class); foreach ($this->reader->getClassAnnotations($class) as $configuration) { @@ -45,8 +43,7 @@ protected function getGlobals(\ReflectionClass $class): array * @param \ReflectionClass $class * @param \ReflectionMethod $method */ - protected function configureClassAnnotations(Route $route, \ReflectionClass $class, \ReflectionMethod $method) - { + protected function configureClassAnnotations(Route $route, \ReflectionClass $class, \ReflectionMethod $method) { foreach ($this->reader->getClassAnnotations($class) as $configuration) { if ($configuration instanceof RouteModifierClassInterface) { $configuration->modifyRouteClass($route, $class, $method); @@ -59,8 +56,7 @@ protected function configureClassAnnotations(Route $route, \ReflectionClass $cla * @param \ReflectionClass $class * @param \ReflectionMethod $method */ - protected function configureMethodAnnotations(Route $route, \ReflectionClass $class, \ReflectionMethod $method) - { + protected function configureMethodAnnotations(Route $route, \ReflectionClass $class, \ReflectionMethod $method) { foreach ($this->reader->getMethodAnnotations($method) as $configuration) { if ($configuration instanceof RouteModifierMethodInterface) { $configuration->modifyRouteMethod($route, $class, $method); @@ -73,8 +69,7 @@ protected function configureMethodAnnotations(Route $route, \ReflectionClass $cl * @param \ReflectionClass $class * @param \ReflectionMethod $method */ - protected function setController(Route $route, \ReflectionClass $class, \ReflectionMethod $method) - { + protected function setController(Route $route, \ReflectionClass $class, \ReflectionMethod $method) { $route->setDefault('_controller', $this->getControllerName($class, $method)); } @@ -83,8 +78,7 @@ protected function setController(Route $route, \ReflectionClass $class, \Reflect * @param \ReflectionMethod $method * @return string */ - protected function getControllerName(\ReflectionClass $class, \ReflectionMethod $method) - { + protected function getControllerName(\ReflectionClass $class, \ReflectionMethod $method) { $annotation = $this->reader->getClassAnnotation($class, $this->routeAnnotationClass); if ($annotation instanceof \Drupal\controller_annotations\Configuration\Route && $service = $annotation->getService( )) { diff --git a/src/Templating/TemplateResolver.php b/src/Templating/TemplateResolver.php index 4c9fd79..049ed5c 100644 --- a/src/Templating/TemplateResolver.php +++ b/src/Templating/TemplateResolver.php @@ -16,8 +16,7 @@ class TemplateResolver * @param string $action * @return string */ - public function resolveByControllerAndAction(string $controllerClass, string $action): string - { + public function resolveByControllerAndAction(string $controllerClass, string $action): string { preg_match('/^Drupal\\\(.*)\\\Controller\\\(.*)/', $controllerClass, $data); if (!empty($data)) { $module = $data[1]; @@ -49,8 +48,7 @@ public function resolveByControllerAndAction(string $controllerClass, string $ac * @param string $template * @return string */ - public function normalize(string $template): string - { + public function normalize(string $template): string { if (preg_match('/^(.+):(.+):(.+)$/', $template, $matches)) { return $this->format($matches[1], $matches[2], $matches[3]); } @@ -69,8 +67,7 @@ public function normalize(string $template): string * @param string $action * @return string */ - private function format(string $module, string $controller, string $action = null): string - { + private function format(string $module, string $controller, string $action = null): string { $controller = $this->normalizeString($controller); $templateName = sprintf('%s-%s', $module, $controller); @@ -93,8 +90,7 @@ private function format(string $module, string $controller, string $action = nul * @param string $value * @return string */ - private function normalizeString(string $value): string - { + private function normalizeString(string $value): string { return str_replace('\\', '-', mb_strtolower($value)); } } diff --git a/tests/modules/controller_annotations_test/src/Controller/AdminController.php b/tests/modules/controller_annotations_test/src/Controller/AdminController.php index 1480571..0a46c5e 100644 --- a/tests/modules/controller_annotations_test/src/Controller/AdminController.php +++ b/tests/modules/controller_annotations_test/src/Controller/AdminController.php @@ -15,8 +15,7 @@ class AdminController extends ControllerBase * @Route("admin", admin=true) * @Security(role="administrator") */ - public function adminAction() - { + public function adminAction() { return []; } @@ -24,8 +23,7 @@ public function adminAction() * @Route("normal") * @Security(role="administrator") */ - public function normalAction() - { + public function normalAction() { return []; } } diff --git a/tests/modules/controller_annotations_test/src/Controller/BasicController.php b/tests/modules/controller_annotations_test/src/Controller/BasicController.php index d5a6365..193b311 100644 --- a/tests/modules/controller_annotations_test/src/Controller/BasicController.php +++ b/tests/modules/controller_annotations_test/src/Controller/BasicController.php @@ -15,8 +15,7 @@ class BasicController extends ControllerBase /** * @Route("test/basic") */ - public function basicAction() - { + public function basicAction() { return new Response('BasicController::basicAction'); } } diff --git a/tests/modules/controller_annotations_test/src/Controller/InvokeController.php b/tests/modules/controller_annotations_test/src/Controller/InvokeController.php index a07bdf2..a984a5b 100644 --- a/tests/modules/controller_annotations_test/src/Controller/InvokeController.php +++ b/tests/modules/controller_annotations_test/src/Controller/InvokeController.php @@ -12,8 +12,7 @@ */ class InvokeController { - public function __invoke() - { + public function __invoke() { return new Response('InvokeController::__invoke'); } } diff --git a/tests/modules/controller_annotations_test/src/Controller/MethodController.php b/tests/modules/controller_annotations_test/src/Controller/MethodController.php index b53eabc..30e0dfa 100644 --- a/tests/modules/controller_annotations_test/src/Controller/MethodController.php +++ b/tests/modules/controller_annotations_test/src/Controller/MethodController.php @@ -15,8 +15,7 @@ class MethodController extends ControllerBase * @Method("GET") * @Security(access=true) */ - public function getAction() - { + public function getAction() { return new Response('ClassRouteController::getAction'); } @@ -25,8 +24,7 @@ public function getAction() * @Method("POST") * @Security(access=true) */ - public function postAction() - { + public function postAction() { return new Response('ClassRouteController::postAction'); } @@ -35,8 +33,7 @@ public function postAction() * @Method({"GET", "POST"}) * @Security(access=true) */ - public function getAndPostAction() - { + public function getAndPostAction() { return new Response('ClassRouteController::getAndPostAction'); } } diff --git a/tests/modules/controller_annotations_test/src/Controller/ParamConverterController.php b/tests/modules/controller_annotations_test/src/Controller/ParamConverterController.php index 3b454f6..6c43be6 100644 --- a/tests/modules/controller_annotations_test/src/Controller/ParamConverterController.php +++ b/tests/modules/controller_annotations_test/src/Controller/ParamConverterController.php @@ -19,8 +19,7 @@ class ParamConverterController extends ControllerBase * @Security(access=true) * @ParamConverter() */ - public function dateAction(\DateTime $start) - { + public function dateAction(\DateTime $start) { return new Response($start->format('Y-m-d')); } @@ -29,8 +28,7 @@ public function dateAction(\DateTime $start) * @Security(access=true) * @ParamConverter("start", options={"format": "d-m-Y"}) */ - public function dateFormatAction(\DateTime $start) - { + public function dateFormatAction(\DateTime $start) { return new Response($start->format('Y-m-d')); } @@ -39,8 +37,7 @@ public function dateFormatAction(\DateTime $start) * @Security(access=true) * @ParamConverter */ - public function dateMultipleAction(\DateTime $start, \DateTime $end) - { + public function dateMultipleAction(\DateTime $start, \DateTime $end) { return new Response($start->format('Y-m-d').'-'.$end->format('Y-m-d')); } @@ -49,8 +46,7 @@ public function dateMultipleAction(\DateTime $start, \DateTime $end) * @Security(access=true) * @ParamConverter() */ - public function optionalDateAction(\DateTime $start = null) - { + public function optionalDateAction(\DateTime $start = null) { if (empty($start)) { return new Response('empty'); } diff --git a/tests/modules/controller_annotations_test/src/Controller/PrefixedRouteController.php b/tests/modules/controller_annotations_test/src/Controller/PrefixedRouteController.php index bfbbb63..ef9be63 100644 --- a/tests/modules/controller_annotations_test/src/Controller/PrefixedRouteController.php +++ b/tests/modules/controller_annotations_test/src/Controller/PrefixedRouteController.php @@ -16,8 +16,7 @@ class PrefixedRouteController extends ControllerBase * @Route * @Security(access=true) */ - public function emptyRouteAction() - { + public function emptyRouteAction() { return new Response('PrefixedBasicController::emptyRouteAction'); } @@ -25,8 +24,7 @@ public function emptyRouteAction() * @Route("/named", name="named_route") * @Security(access=true) */ - public function namedRouteAction() - { + public function namedRouteAction() { return new Response('PrefixedBasicController::namedRouteAction'); } } diff --git a/tests/modules/controller_annotations_test/src/Controller/SecurityController.php b/tests/modules/controller_annotations_test/src/Controller/SecurityController.php index db34b12..fa4d223 100644 --- a/tests/modules/controller_annotations_test/src/Controller/SecurityController.php +++ b/tests/modules/controller_annotations_test/src/Controller/SecurityController.php @@ -21,8 +21,7 @@ class SecurityController extends ControllerBase * @Route("access") * @Security(access=true) */ - public function accessAction() - { + public function accessAction() { return new Response('OK'); } @@ -30,8 +29,7 @@ public function accessAction() * @Route("permission") * @Security(permission="access content") */ - public function permissionAction() - { + public function permissionAction() { return new Response('OK'); } @@ -39,8 +37,7 @@ public function permissionAction() * @Route("role") * @Security(role="administrator") */ - public function roleAction() - { + public function roleAction() { return new Response('OK'); } @@ -48,8 +45,7 @@ public function roleAction() * @Route("entity/{node}") * @Security(entity="node.view") */ - public function entityAction(Node $node) - { + public function entityAction(Node $node) { return new Response('OK'); } @@ -57,8 +53,7 @@ public function entityAction(Node $node) * @Route("custom") * @Security(custom="\Drupal\controller_annotations_test\Security\Custom::access") */ - public function customAction() - { + public function customAction() { return new Response('OK'); } @@ -66,8 +61,7 @@ public function customAction() * @Route("custom-inline") * @Security(custom="access") */ - public function customInlineAction() - { + public function customInlineAction() { return new Response('OK'); } @@ -75,8 +69,7 @@ public function customInlineAction() * @Route("csrf") * @Security(access=true, csrf=true) */ - public function csrfAction() - { + public function csrfAction() { return new Response('OK'); } @@ -84,8 +77,7 @@ public function csrfAction() * @param AccountInterface $account * @return AccessResult */ - public function access(AccountInterface $account) - { + public function access(AccountInterface $account) { return AccessResult::allowedIf($account->id() === 1337); } } diff --git a/tests/modules/controller_annotations_test/src/Controller/ServiceController.php b/tests/modules/controller_annotations_test/src/Controller/ServiceController.php index 16c5e2d..c2481c6 100644 --- a/tests/modules/controller_annotations_test/src/Controller/ServiceController.php +++ b/tests/modules/controller_annotations_test/src/Controller/ServiceController.php @@ -15,8 +15,7 @@ class ServiceController * @Route("test/service") * @Security(access=true) */ - public function getAction() - { + public function getAction() { return new Response('ServiceController::getAction'); } } diff --git a/tests/modules/controller_annotations_test/src/Controller/TemplateController.php b/tests/modules/controller_annotations_test/src/Controller/TemplateController.php index a1e0cee..6caa160 100644 --- a/tests/modules/controller_annotations_test/src/Controller/TemplateController.php +++ b/tests/modules/controller_annotations_test/src/Controller/TemplateController.php @@ -17,8 +17,7 @@ class TemplateController extends ControllerBase * @Security(access=true) * @Template */ - public function emptyAction() - { + public function emptyAction() { } /** @@ -26,8 +25,7 @@ public function emptyAction() * @Security(access=true) * @Template("controller_annotations_test:template") */ - public function moduleControllerAction() - { + public function moduleControllerAction() { } /** @@ -35,8 +33,7 @@ public function moduleControllerAction() * @Security(access=true) * @Template("controller_annotations_test:template:action") */ - public function moduleControllerActionAction() - { + public function moduleControllerActionAction() { } /** @@ -44,8 +41,7 @@ public function moduleControllerActionAction() * @Security(access=true) * @Template */ - public function parameterAction() - { + public function parameterAction() { return ['parameter' => 'value']; } @@ -54,8 +50,7 @@ public function parameterAction() * @Security(access=true) * @Template */ - public function parameterUrlAction($parameter, $default = 'default') - { + public function parameterUrlAction($parameter, $default = 'default') { } /** @@ -63,8 +58,7 @@ public function parameterUrlAction($parameter, $default = 'default') * @Security(access=true) * @Template(isStreamable=true) */ - public function streamableAction() - { + public function streamableAction() { } /** @@ -72,7 +66,6 @@ public function streamableAction() * @Security(access=true) * @Template() */ - public function varsAction($name = 'World') - { + public function varsAction($name = 'World') { } } diff --git a/tests/modules/controller_annotations_test/src/Controller/TitleController.php b/tests/modules/controller_annotations_test/src/Controller/TitleController.php index 5022ccd..4f66e02 100644 --- a/tests/modules/controller_annotations_test/src/Controller/TitleController.php +++ b/tests/modules/controller_annotations_test/src/Controller/TitleController.php @@ -18,8 +18,7 @@ class TitleController extends ControllerBase * @Security(access=true) * @Title("Hello World") */ - public function normalAction() - { + public function normalAction() { return []; } @@ -28,8 +27,7 @@ public function normalAction() * @Security(access=true) * @Title("Hello @name", arguments={"@name":"MediaMonks"}) */ - public function argumentsAction() - { + public function argumentsAction() { return []; } @@ -38,8 +36,7 @@ public function argumentsAction() * @Security(access=true) * @Title(callback="\Drupal\controller_annotations_test\Title\Custom::title") */ - public function callbackAction() - { + public function callbackAction() { return []; } @@ -48,16 +45,14 @@ public function callbackAction() * @Security(access=true) * @Title(callback="title") */ - public function callbackInlineAction() - { + public function callbackInlineAction() { return []; } /** * @return string */ - public function title() - { + public function title() { return 'Hello Callback Inline'; } } diff --git a/tests/modules/controller_annotations_test/src/Security/Custom.php b/tests/modules/controller_annotations_test/src/Security/Custom.php index 9de09f5..92821aa 100644 --- a/tests/modules/controller_annotations_test/src/Security/Custom.php +++ b/tests/modules/controller_annotations_test/src/Security/Custom.php @@ -11,8 +11,7 @@ class Custom * @param AccountInterface $account * @return AccessResult */ - public function access(AccountInterface $account) - { + public function access(AccountInterface $account) { return AccessResult::allowedIf($account->id() === 1337); } } diff --git a/tests/modules/controller_annotations_test/src/Title/Custom.php b/tests/modules/controller_annotations_test/src/Title/Custom.php index 61f1942..2cef320 100644 --- a/tests/modules/controller_annotations_test/src/Title/Custom.php +++ b/tests/modules/controller_annotations_test/src/Title/Custom.php @@ -8,8 +8,7 @@ class Custom /** * @return string */ - public function title() - { + public function title() { return 'Hello Callback'; } } diff --git a/tests/src/Kernel/AnnotationsTest.php b/tests/src/Kernel/AnnotationsTest.php index dc5f72f..a480ef3 100644 --- a/tests/src/Kernel/AnnotationsTest.php +++ b/tests/src/Kernel/AnnotationsTest.php @@ -10,8 +10,7 @@ */ class AnnotationsTest extends KernelTestBase { - public function testRouting() - { + public function testRouting() { $response = $this->request(Request::create('/test/basic')); $this->assertEquals('BasicController::basicAction', $response->getContent()); @@ -31,22 +30,19 @@ public function testRouting() $this->assertResponseContents(Request::create('/test/service'), 'ServiceController::getAction'); } - public function testAdmin() - { + public function testAdmin() { $this->assertForbidden(Request::create('/test/admin/admin')); $this->setAdministratorAccount(); $this->assertResponseContains(Request::create('/test/admin/admin'), 'currentPathIsAdmin":true'); } - public function testNotAdmin() - { + public function testNotAdmin() { $this->assertForbidden(Request::create('/test/admin/normal')); $this->setAdministratorAccount(); $this->assertResponseContains(Request::create('/test/admin/normal'), 'currentPathIsAdmin":false'); } - public function testTemplate() - { + public function testTemplate() { $this->setUpTemplate(); $this->assertResponseContents(Request::create('/test/template/empty'), 'empty'); $this->assertResponseContents(Request::create('/test/template/module-controller'), 'module-controller'); @@ -57,8 +53,7 @@ public function testTemplate() $this->assertResponseContents(Request::create('/test/template/vars/Monk'), 'Hello Monk'); } - private function setUpTemplate() - { + private function setUpTemplate() { $sourceModule = $this->getDrupalRoot() . '/modules/controller_annotations/tests/modules/controller_annotations_test/templates/'; if (!file_exists($sourceModule)) { @@ -78,8 +73,7 @@ private function setUpTemplate() } } - public function testSecurity() - { + public function testSecurity() { // all access $this->assertResponseContents(Request::create('/test/security/access'), 'OK'); @@ -138,16 +132,14 @@ public function testSecurity() ]), 'OK'); } - public function testTitle() - { + public function testTitle() { $this->assertTitleStartsWith(Request::create('/test/title/normal'), 'Hello World'); $this->assertTitleStartsWith(Request::create('/test/title/arguments'), 'Hello MediaMonks'); $this->assertTitleStartsWith(Request::create('/test/title/callback'), 'Hello Callback'); $this->assertTitleStartsWith(Request::create('/test/title/callback-inline'), 'Hello Callback Inline'); } - public function testParamConverter() - { + public function testParamConverter() { $this->assertResponseContents(Request::create('/test/param-converter/date/2017-08-15'), '2017-08-15'); $this->assertResponseContents(Request::create('/test/param-converter/date-format/15-08-2017'), '2017-08-15'); $this->assertResponseContents(Request::create('/test/param-converter/date-multiple/14-08-2017/15-08-2017'), '2017-08-14-2017-08-15'); diff --git a/tests/src/Kernel/DrupalTestKernel.php b/tests/src/Kernel/DrupalTestKernel.php index 1f86632..9664a2a 100644 --- a/tests/src/Kernel/DrupalTestKernel.php +++ b/tests/src/Kernel/DrupalTestKernel.php @@ -11,8 +11,7 @@ class DrupalTestKernel extends DrupalKernel /** * {@inheritdoc} */ - public function setSitePath($path) - { + public function setSitePath($path) { if (empty($this->sitePath)) { parent::setSitePath($path); } @@ -21,8 +20,7 @@ public function setSitePath($path) /** * @param Request $request */ - protected function initializeSettings(Request $request) - { + protected function initializeSettings(Request $request) { $settings = Settings::getAll(); parent::initializeSettings($request); new Settings($settings); diff --git a/tests/src/Kernel/KernelTestBase.php b/tests/src/Kernel/KernelTestBase.php index ff2b5c6..6f615ba 100644 --- a/tests/src/Kernel/KernelTestBase.php +++ b/tests/src/Kernel/KernelTestBase.php @@ -27,8 +27,7 @@ abstract class KernelTestBase extends BaseKernelTestBase * @param Request $request * @param $contents */ - protected function assertResponseContents(Request $request, $contents) - { + protected function assertResponseContents(Request $request, $contents) { $response = $this->request($request); if ($response instanceof StreamedResponse) { ob_start(); @@ -47,8 +46,7 @@ protected function assertResponseContents(Request $request, $contents) * @param Request $request * @param $contents */ - protected function assertResponseContains(Request $request, $contents) - { + protected function assertResponseContains(Request $request, $contents) { $response = $this->request($request); //echo $response->getContent(); $this->assertTrue(strpos($response->getContent(), $contents) !== false); @@ -58,8 +56,7 @@ protected function assertResponseContains(Request $request, $contents) * @param Request $request * @param $contents */ - protected function assertResponseNotContains(Request $request, $contents) - { + protected function assertResponseNotContains(Request $request, $contents) { $response = $this->request($request); $this->assertTrue(strpos($response->getContent(), $contents) === false); } @@ -67,8 +64,7 @@ protected function assertResponseNotContains(Request $request, $contents) /** * @param Request $request */ - protected function assertNotFound(Request $request) - { + protected function assertNotFound(Request $request) { $response = $this->request($request); $this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode()); } @@ -76,8 +72,7 @@ protected function assertNotFound(Request $request) /** * @param Request $request */ - protected function assertMethodNotAllowed(Request $request) - { + protected function assertMethodNotAllowed(Request $request) { $response = $this->request($request); $this->assertEquals(Response::HTTP_METHOD_NOT_ALLOWED, $response->getStatusCode()); } @@ -85,8 +80,7 @@ protected function assertMethodNotAllowed(Request $request) /** * @param Request $request */ - protected function assertForbidden(Request $request) - { + protected function assertForbidden(Request $request) { $response = $this->request($request); $this->assertEquals(Response::HTTP_FORBIDDEN, $response->getStatusCode()); } @@ -94,8 +88,7 @@ protected function assertForbidden(Request $request) /** * @param Request $request */ - protected function assertTitleStartsWith(Request $request, $title) - { + protected function assertTitleStartsWith(Request $request, $title) { $this->assertResponseContains($request, '<title>'.$title); } @@ -103,8 +96,7 @@ protected function assertTitleStartsWith(Request $request, $title) * @param Request $request * @return Response */ - protected function request(Request $request) - { + protected function request(Request $request) { if (empty($this->kernel)) { $this->kernel = DrupalTestKernel::createFromRequest($request, $this->classLoader, 'prod'); } @@ -115,16 +107,14 @@ protected function request(Request $request) /** * */ - protected function setAnonymousAccount() - { + protected function setAnonymousAccount() { $this->setAccount(new AnonymousUserSession()); } /** * */ - protected function setAuthenticatedAccount() - { + protected function setAuthenticatedAccount() { $this->setAccount(new UserSession([ 'uid' => 2, 'roles' => ['authenticated'] @@ -134,8 +124,7 @@ protected function setAuthenticatedAccount() /** * */ - protected function setAdministratorAccount() - { + protected function setAdministratorAccount() { $this->setAccount(new UserSession([ 'uid' => 1, 'roles' => ['administrator', 'authenticated'] @@ -145,8 +134,7 @@ protected function setAdministratorAccount() /** * @param AccountInterface $account */ - protected function setAccount(AccountInterface $account) - { + protected function setAccount(AccountInterface $account) { $this->kernel->getContainer()->get('current_user')->setAccount($account); } } diff --git a/tests/src/Kernel/TestUserSession.php b/tests/src/Kernel/TestUserSession.php index 078ea64..e86f4fe 100644 --- a/tests/src/Kernel/TestUserSession.php +++ b/tests/src/Kernel/TestUserSession.php @@ -14,8 +14,7 @@ class TestUserSession extends UserSession /** * {@inheritdoc} */ - public function hasPermission($permission) - { + public function hasPermission($permission) { // User #1 has all privileges. if ((int) $this->id() === 1) { return true; diff --git a/tests/src/Unit/Cache/DrupalCacheTest.php b/tests/src/Unit/Cache/DrupalCacheTest.php index ebfde33..9850b20 100644 --- a/tests/src/Unit/Cache/DrupalCacheTest.php +++ b/tests/src/Unit/Cache/DrupalCacheTest.php @@ -10,8 +10,7 @@ class DrupalCacheTest extends UnitTestCase { - public function testDoFetch() - { + public function testDoFetch() { $drupalCache = $this->getDrupalCacheMock(); $drupalCache->shouldReceive('get')->once()->withArgs(['[foo][1]'])->andReturn($this->getCacheData('bar')); @@ -20,8 +19,7 @@ public function testDoFetch() $this->assertEquals('bar', $cache->fetch('foo')); } - public function testDoContains() - { + public function testDoContains() { $drupalCache = $this->getDrupalCacheMock(); $drupalCache->shouldReceive('get')->once()->withArgs(['[foo][1]'])->andReturn($this->getCacheData('bar')); $drupalCache->shouldReceive('get')->once()->withArgs(['[bar][1]'])->andReturn(false); @@ -31,8 +29,7 @@ public function testDoContains() $this->assertFalse($cache->contains('bar')); } - public function testSave() - { + public function testSave() { $drupalCache = $this->getDrupalCacheMock(); $drupalCache->shouldReceive('set')->once()->withArgs(['[foo][1]', 'bar'])->andReturnNull(); $drupalCache->shouldReceive('set')->once()->withArgs(['[foo][1]', 'bar', m::any()])->andReturnNull(); @@ -44,8 +41,7 @@ public function testSave() m::close(); } - public function testDelete() - { + public function testDelete() { $drupalCache = $this->getDrupalCacheMock(); $drupalCache->shouldReceive('delete')->once()->withArgs(['[foo][1]'])->andReturnNull(); @@ -54,8 +50,7 @@ public function testDelete() $this->assertTrue($cache->delete('foo')); } - public function testFlushAll() - { + public function testFlushAll() { $drupalCache = $this->getDrupalCacheMock(); $drupalCache->shouldReceive('deleteAll')->once()->withNoArgs()->andReturnNull(); @@ -64,8 +59,7 @@ public function testFlushAll() $this->assertTrue($cache->flushAll()); } - public function testGetStats() - { + public function testGetStats() { $drupalCache = $this->getDrupalCacheMock(); $cache = new DrupalCache($drupalCache); @@ -75,8 +69,7 @@ public function testGetStats() /** * @return CacheBackendInterface */ - protected function getDrupalCacheMock() - { + protected function getDrupalCacheMock() { $drupalCache = m::mock(CacheBackendInterface::class); $drupalCache->shouldReceive('get')->withArgs(['DoctrineNamespaceCacheKey[]'])->andReturnNull(); @@ -88,16 +81,14 @@ protected function getDrupalCacheMock() * * @return StdClass */ - protected function getCacheData($data) - { + protected function getCacheData($data) { $cacheData = new StdClass(); $cacheData->data = $data; return $cacheData; } - protected function tearDown() - { + protected function tearDown() { m::close(); parent::tearDown(); diff --git a/tests/src/Unit/Configuration/CacheTest.php b/tests/src/Unit/Configuration/CacheTest.php index 2d3abf0..f686de7 100644 --- a/tests/src/Unit/Configuration/CacheTest.php +++ b/tests/src/Unit/Configuration/CacheTest.php @@ -7,8 +7,7 @@ class CacheTest extends UnitTestCase { - public function testProperties() - { + public function testProperties() { $cache = new Cache([]); $cache->setExpires('tomorrow'); @@ -41,15 +40,13 @@ public function testProperties() $this->assertEquals('yesterday', $cache->getLastModified()); } - public function testGetAliasName() - { + public function testGetAliasName() { $cache = new Cache([]); $this->assertEquals('cache', $cache->getAliasName()); } - public function testAllowArray() - { + public function testAllowArray() { $cache = new Cache([]); $this->assertFalse($cache->allowArray()); diff --git a/tests/src/Unit/Configuration/MethodTest.php b/tests/src/Unit/Configuration/MethodTest.php index e62ce35..fe9d4a9 100644 --- a/tests/src/Unit/Configuration/MethodTest.php +++ b/tests/src/Unit/Configuration/MethodTest.php @@ -9,8 +9,7 @@ class MethodTest extends UnitTestCase { - public function testModifyRouteClass() - { + public function testModifyRouteClass() { $route = m::mock(Route::class); $route->shouldReceive('setMethods')->once()->withArgs([['GET', 'POST']]); @@ -23,8 +22,7 @@ public function testModifyRouteClass() m::close(); } - public function testModifyRouteMethod() - { + public function testModifyRouteMethod() { $route = m::mock(Route::class); $route->shouldReceive('setMethods')->once()->withArgs([['GET', 'POST']]); @@ -37,8 +35,7 @@ public function testModifyRouteMethod() m::close(); } - public function testModify() - { + public function testModify() { $route = m::mock(Route::class); $route->shouldReceive('setMethods')->once()->withArgs([['GET']]); $route->shouldReceive('setMethods')->once()->withArgs([['POST']]); diff --git a/tests/src/Unit/Configuration/RouteTest.php b/tests/src/Unit/Configuration/RouteTest.php index 4c53615..26bf7d4 100644 --- a/tests/src/Unit/Configuration/RouteTest.php +++ b/tests/src/Unit/Configuration/RouteTest.php @@ -9,8 +9,7 @@ class RouteTest extends UnitTestCase { - public function testModifyRouteClass() - { + public function testModifyRouteClass() { $route = m::mock(Route::class); $route->shouldReceive('setOption')->once()->withArgs(['_admin_route', true]); @@ -23,8 +22,7 @@ public function testModifyRouteClass() m::close(); } - public function testModifyMethodClass() - { + public function testModifyMethodClass() { $route = m::mock(Route::class); $class = m::mock(\ReflectionClass::class); @@ -36,8 +34,7 @@ public function testModifyMethodClass() m::close(); } - public function testServiceNotAllowedOnMethodLevel() - { + public function testServiceNotAllowedOnMethodLevel() { $this->setExpectedException(\LogicException::class); $route = m::mock(Route::class); @@ -51,14 +48,12 @@ public function testServiceNotAllowedOnMethodLevel() m::close(); } - public function testAllowArray() - { + public function testAllowArray() { $routeConfig = new RouteConfiguration([]); $this->assertTrue($routeConfig->allowArray()); } - public function testUnknownProperty() - { + public function testUnknownProperty() { $this->setExpectedException(\BadMethodCallException::class); new RouteConfiguration(['foo' => 'bar']); } diff --git a/tests/src/Unit/Configuration/SecurityTest.php b/tests/src/Unit/Configuration/SecurityTest.php index f374956..68c0ad9 100644 --- a/tests/src/Unit/Configuration/SecurityTest.php +++ b/tests/src/Unit/Configuration/SecurityTest.php @@ -9,8 +9,7 @@ class SecurityTest extends UnitTestCase { - public function testModifyRouteMethod() - { + public function testModifyRouteMethod() { $route = m::mock(Route::class); $route->shouldReceive('setRequirement')->once()->withArgs(['_access', true]); $route->shouldReceive('setRequirement')->once()->withArgs(['_permission', 'permission']); @@ -35,8 +34,7 @@ public function testModifyRouteMethod() m::close(); } - public function testModifyRouteMethodInlineAccess() - { + public function testModifyRouteMethodInlineAccess() { $route = m::mock(Route::class); $route->shouldReceive('setRequirement')->once()->withArgs(['_custom_access', 'foo::custom']); diff --git a/tests/src/Unit/Configuration/TitleTest.php b/tests/src/Unit/Configuration/TitleTest.php index f48d372..3e4b138 100644 --- a/tests/src/Unit/Configuration/TitleTest.php +++ b/tests/src/Unit/Configuration/TitleTest.php @@ -9,8 +9,7 @@ class TitleTest extends UnitTestCase { - public function testModifyRouteMethod() - { + public function testModifyRouteMethod() { $route = m::mock(Route::class); $route->shouldReceive('setDefault')->once()->withArgs(['_title', 'Hello World']); $route->shouldReceive('setDefault')->once()->withArgs(['_title_arguments', ['arguments' => true]]); @@ -31,8 +30,7 @@ public function testModifyRouteMethod() m::close(); } - public function testModifyRouteMethodInlineAccess() - { + public function testModifyRouteMethodInlineAccess() { $route = m::mock(Route::class); $route->shouldReceive('setDefault')->once()->withArgs(['_title_callback', 'foo::callback']); @@ -49,8 +47,7 @@ public function testModifyRouteMethodInlineAccess() m::close(); } - public function testUnknownProperty() - { + public function testUnknownProperty() { $this->setExpectedException(\RuntimeException::class); new Title(['foo' => 'bar']); } diff --git a/tests/src/Unit/EventSubscriber/ControllerEventSubscriberTest.php b/tests/src/Unit/EventSubscriber/ControllerEventSubscriberTest.php index e79412b..4e3ac66 100644 --- a/tests/src/Unit/EventSubscriber/ControllerEventSubscriberTest.php +++ b/tests/src/Unit/EventSubscriber/ControllerEventSubscriberTest.php @@ -16,8 +16,7 @@ */ class ControllerEventSubscriberTest extends UnitTestCase { - public function testOnKernelController() - { + public function testOnKernelController() { $reader = m::mock(Reader::class); $eventSubscriber = new ControllerEventSubscriber($reader); @@ -28,8 +27,7 @@ public function testOnKernelController() $this->assertNull($eventSubscriber->onKernelController($event)); } - public function testControllerInvoke() - { + public function testControllerInvoke() { $reader = m::mock(Reader::class); $reader->shouldReceive('getClassAnnotations')->andReturn([]); $reader->shouldReceive('getMethodAnnotations')->andReturn([]); @@ -43,8 +41,7 @@ public function testControllerInvoke() $this->assertNull($eventSubscriber->onKernelController($event)); } - public function testMultipleConfigurations() - { + public function testMultipleConfigurations() { $configuration = m::mock(ConfigurationInterface::class); $configuration->shouldReceive('allowArray')->andReturn(true); $configuration->shouldReceive('getAliasName')->andReturn('foo'); @@ -65,8 +62,7 @@ public function testMultipleConfigurations() $this->assertNull($eventSubscriber->onKernelController($event)); } - public function testMergeConfigurations() - { + public function testMergeConfigurations() { $classConfigurations = [ 'foo' => 'bar' ]; @@ -81,8 +77,7 @@ public function testMergeConfigurations() $this->assertEquals(['foo' => 'bar'], $result); } - public function testMergeConfigurationsArray() - { + public function testMergeConfigurationsArray() { $classConfigurations = [ 'foo' => ['bar'] ]; @@ -98,8 +93,7 @@ public function testMergeConfigurationsArray() $this->assertEquals(['foo' => ['bar', 'baz']], $result); } - public function testMergeConfigurationsMismatch() - { + public function testMergeConfigurationsMismatch() { $this->setExpectedException(\UnexpectedValueException::class); $classConfigurations = [ @@ -118,7 +112,6 @@ public function testMergeConfigurationsMismatch() class ControllerInvokableController { - public function __invoke() - { + public function __invoke() { } } diff --git a/tests/src/Unit/EventSubscriber/HttpCacheListenerTest.php b/tests/src/Unit/EventSubscriber/HttpCacheListenerTest.php index 92b0778..e85eff1 100644 --- a/tests/src/Unit/EventSubscriber/HttpCacheListenerTest.php +++ b/tests/src/Unit/EventSubscriber/HttpCacheListenerTest.php @@ -12,8 +12,7 @@ class HttpCacheListenerTest extends UnitTestCase { - public function setUp() - { + public function setUp() { $this->listener = new HttpCacheEventSubscriber(); $this->response = new Response(); $this->cache = new Cache(array()); @@ -21,8 +20,7 @@ public function setUp() $this->event = $this->createEventMock($this->request, $this->response); } - public function testWontReassignResponseWhenResponseIsUnsuccessful() - { + public function testWontReassignResponseWhenResponseIsUnsuccessful() { $this->event ->expects($this->never()) ->method('setResponse') @@ -33,8 +31,7 @@ public function testWontReassignResponseWhenResponseIsUnsuccessful() $this->assertInternalType('null', $this->listener->onKernelResponse($this->event)); } - public function testWontReassignResponseWhenNoConfigurationIsPresent() - { + public function testWontReassignResponseWhenNoConfigurationIsPresent() { $this->event ->expects($this->never()) ->method('setResponse') @@ -45,8 +42,7 @@ public function testWontReassignResponseWhenNoConfigurationIsPresent() $this->assertInternalType('null', $this->listener->onKernelResponse($this->event)); } - public function testResponseIsPublicIfConfigurationIsPublicTrue() - { + public function testResponseIsPublicIfConfigurationIsPublicTrue() { $request = $this->createRequest(new Cache(array( 'public' => true, ))); @@ -57,8 +53,7 @@ public function testResponseIsPublicIfConfigurationIsPublicTrue() $this->assertFalse($this->response->headers->hasCacheControlDirective('private')); } - public function testResponseIsPrivateIfConfigurationIsPublicFalse() - { + public function testResponseIsPrivateIfConfigurationIsPublicFalse() { $request = $this->createRequest(new Cache(array( 'public' => false, ))); @@ -69,8 +64,7 @@ public function testResponseIsPrivateIfConfigurationIsPublicFalse() $this->assertTrue($this->response->headers->hasCacheControlDirective('private')); } - public function testResponseVary() - { + public function testResponseVary() { $vary = array('foobar'); $request = $this->createRequest(new Cache(array('vary' => $vary))); @@ -80,8 +74,7 @@ public function testResponseVary() $this->assertEquals($vary, $result); } - public function testResponseVaryWhenVaryNotSet() - { + public function testResponseVaryWhenVaryNotSet() { $request = $this->createRequest(new Cache(array())); $vary = array('foobar'); $this->response->setVary($vary); @@ -93,8 +86,7 @@ public function testResponseVaryWhenVaryNotSet() $this->assertEquals($vary, $result, 'Vary header should not be changed'); } - public function testResponseIsPrivateIfConfigurationIsPublicNotSet() - { + public function testResponseIsPrivateIfConfigurationIsPublicNotSet() { $request = $this->createRequest(new Cache(array())); $this->listener->onKernelResponse($this->createEventMock($request, $this->response)); @@ -102,8 +94,7 @@ public function testResponseIsPrivateIfConfigurationIsPublicNotSet() $this->assertFalse($this->response->headers->hasCacheControlDirective('public')); } - public function testConfigurationAttributesAreSetOnResponse() - { + public function testConfigurationAttributesAreSetOnResponse() { $this->assertInternalType('null', $this->response->getMaxAge()); $this->assertInternalType('null', $this->response->getExpires()); $this->assertFalse($this->response->headers->hasCacheControlDirective('s-maxage')); @@ -121,8 +112,7 @@ public function testConfigurationAttributesAreSetOnResponse() $this->assertInstanceOf('DateTime', $this->response->getExpires()); } - public function testCacheMaxAgeSupportsStrtotimeFormat() - { + public function testCacheMaxAgeSupportsStrtotimeFormat() { $this->request->attributes->set('_cache', new Cache(array( 'smaxage' => '1 day', 'maxage' => '1 day', @@ -134,8 +124,7 @@ public function testCacheMaxAgeSupportsStrtotimeFormat() $this->assertEquals(60 * 60 * 24, $this->response->getMaxAge()); } - public function testLastModifiedNotModifiedResponse() - { + public function testLastModifiedNotModifiedResponse() { $request = $this->createRequest(new Cache(array('lastModified' => 'test.getDate()'))); $request->attributes->set('test', new TestEntity()); $request->headers->add(array('If-Modified-Since' => 'Fri, 23 Aug 2013 00:00:00 GMT')); @@ -151,8 +140,7 @@ public function testLastModifiedNotModifiedResponse() $this->assertEquals(304, $response->getStatusCode()); } - public function testLastModifiedHeader() - { + public function testLastModifiedHeader() { $request = $this->createRequest(new Cache(array('lastModified' => 'test.getDate()'))); $request->attributes->set('test', new TestEntity()); $response = new Response(); @@ -173,8 +161,7 @@ public function testLastModifiedHeader() $this->assertEquals('Fri, 23 Aug 2013 00:00:00 GMT', $response->headers->get('Last-Modified')); } - public function testETagNotModifiedResponse() - { + public function testETagNotModifiedResponse() { $request = $this->createRequest(new Cache(array('etag' => 'test.getId()'))); $request->attributes->set('test', $entity = new TestEntity()); $request->headers->add(array('If-None-Match' => sprintf('"%s"', hash('sha256', $entity->getId())))); @@ -190,8 +177,7 @@ public function testETagNotModifiedResponse() $this->assertEquals(304, $response->getStatusCode()); } - public function testETagHeader() - { + public function testETagHeader() { $request = $this->createRequest(new Cache(array('ETag' => 'test.getId()'))); $request->attributes->set('test', $entity = new TestEntity()); $response = new Response(); @@ -212,15 +198,13 @@ public function testETagHeader() $this->assertContains(hash('sha256', $entity->getId()), $response->headers->get('ETag')); } - private function createRequest(Cache $cache = null) - { + private function createRequest(Cache $cache = null) { return new Request(array(), array(), array( '_cache' => $cache, )); } - private function createEventMock(Request $request, Response $response) - { + private function createEventMock(Request $request, Response $response) { $event = $this ->getMockBuilder('Symfony\Component\HttpKernel\Event\FilterResponseEvent') ->disableOriginalConstructor() @@ -240,21 +224,18 @@ private function createEventMock(Request $request, Response $response) return $event; } - private function getKernel() - { + private function getKernel() { return $this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernelInterface')->getMock(); } } class TestEntity { - public function getDate() - { + public function getDate() { return new \DateTime('Fri, 23 Aug 2013 00:00:00 GMT'); } - public function getId() - { + public function getId() { return '12345'; } } diff --git a/tests/src/Unit/EventSubscriber/ParamConverterEventSubscriberTest.php b/tests/src/Unit/EventSubscriber/ParamConverterEventSubscriberTest.php index e479d74..de8e240 100644 --- a/tests/src/Unit/EventSubscriber/ParamConverterEventSubscriberTest.php +++ b/tests/src/Unit/EventSubscriber/ParamConverterEventSubscriberTest.php @@ -18,8 +18,7 @@ class ParamConverterEventSubscriberTest extends UnitTestCase /** * @dataProvider getControllerWithNoArgsFixtures */ - public function testRequestIsSkipped($controllerCallable) - { + public function testRequestIsSkipped($controllerCallable) { $kernel = $this->getMockBuilder(HttpKernelInterface::class)->getMock(); $request = new Request(); @@ -36,8 +35,7 @@ public function testRequestIsSkipped($controllerCallable) $eventSubscriber->onKernelController($event); } - public function getControllerWithNoArgsFixtures() - { + public function getControllerWithNoArgsFixtures() { return [ [[new ParamConverterTestController(), 'noArgAction']], [new ParamConverterInvokableNoArgController()], @@ -47,8 +45,7 @@ public function getControllerWithNoArgsFixtures() /** * @dataProvider getControllerWithArgsFixtures */ - public function testAutoConvert($controllerCallable) - { + public function testAutoConvert($controllerCallable) { $kernel = $this->getMockBuilder( HttpKernelInterface::class )->getMock(); @@ -75,8 +72,7 @@ public function testAutoConvert($controllerCallable) * @dataProvider settingOptionalParamProvider * @requires PHP 7.1 */ - public function testSettingOptionalParam($function, $isOptional) - { + public function testSettingOptionalParam($function, $isOptional) { $kernel = $this->getMockBuilder(HttpKernelInterface::class)->getMock(); $request = new Request(); @@ -102,8 +98,7 @@ public function testSettingOptionalParam($function, $isOptional) $eventSubscriber->onKernelController($event); } - public function settingOptionalParamProvider() - { + public function settingOptionalParamProvider() { return [ ['requiredParamAction', false], ['defaultParamAction', true], @@ -114,8 +109,7 @@ public function settingOptionalParamProvider() /** * @dataProvider getControllerWithArgsFixtures */ - public function testNoAutoConvert($controllerCallable) - { + public function testNoAutoConvert($controllerCallable) { $kernel = $this->getMockBuilder(HttpKernelInterface::class)->getMock(); $request = new Request([], [], ['date' => '2014-03-14 09:00:00']); @@ -133,16 +127,14 @@ public function testNoAutoConvert($controllerCallable) $eventSubscriber->onKernelController($event); } - public function getControllerWithArgsFixtures() - { + public function getControllerWithArgsFixtures() { return [ [[new ParamConverterTestController(), 'dateAction']], [new ParamConverterInvokableController()], ]; } - protected function getParamConverterManager(Request $request, $configurations) - { + protected function getParamConverterManager(Request $request, $configurations) { $manager = $this->getMockBuilder(ParamConverterManager::class)->getMock(); $manager ->expects($this->once()) @@ -152,8 +144,7 @@ protected function getParamConverterManager(Request $request, $configurations) return $manager; } - public function testPredefinedConfigurations() - { + public function testPredefinedConfigurations() { $configuration = m::mock(\stdClass::class); $configuration->shouldReceive('getName')->andReturn('foo'); @@ -183,27 +174,23 @@ public function testPredefinedConfigurations() class ParamConverterTestController { - public function noArgAction(Request $request) - { + public function noArgAction(Request $request) { } - public function dateAction(\DateTime $date) - { + public function dateAction(\DateTime $date) { } } class ParamConverterInvokableNoArgController { - public function __invoke(Request $request) - { + public function __invoke(Request $request) { } } class ParamConverterInvokableController { - public function __invoke(\DateTime $date) - { + public function __invoke(\DateTime $date) { } } diff --git a/tests/src/Unit/EventSubscriber/RouteEventSubscriberTest.php b/tests/src/Unit/EventSubscriber/RouteEventSubscriberTest.php index b685eca..8d0e3b6 100644 --- a/tests/src/Unit/EventSubscriber/RouteEventSubscriberTest.php +++ b/tests/src/Unit/EventSubscriber/RouteEventSubscriberTest.php @@ -30,8 +30,7 @@ class RouteEventSubscriberTest extends UnitTestCase */ protected $eventSubscriber; - protected function setUpEventSubscriber() - { + protected function setUpEventSubscriber() { $annotationDirectoryLoader = m::mock(AnnotationDirectoryLoader::class); $annotationDirectoryLoader->shouldReceive('load')->andReturn($this->getAnnotatedRouteCollection()); @@ -41,8 +40,7 @@ protected function setUpEventSubscriber() /** * @return RouteCollection */ - protected function getRouteCollection() - { + protected function getRouteCollection() { if (empty($this->routeCollection)) { $this->routeCollection = new RouteCollection; } @@ -53,8 +51,7 @@ protected function getRouteCollection() /** * @return RouteCollection */ - protected function getAnnotatedRouteCollection() - { + protected function getAnnotatedRouteCollection() { if (empty($this->annotatedRouteCollection)) { $this->annotatedRouteCollection = new RouteCollection; } @@ -62,22 +59,19 @@ protected function getAnnotatedRouteCollection() return $this->annotatedRouteCollection; } - protected function triggerOnRoutes() - { + protected function triggerOnRoutes() { if (empty($this->eventSubscriber)) { $this->setUpEventSubscriber(); } $this->eventSubscriber->onRoutes(new RouteBuildEvent($this->getRouteCollection())); } - public function testOnRoutesWithEmptyRouteCollection() - { + public function testOnRoutesWithEmptyRouteCollection() { $this->triggerOnRoutes(); $this->assertEquals(0, $this->getRouteCollection()->count()); } - public function testOnRoutesWithoutAnnotatedRoutes() - { + public function testOnRoutesWithoutAnnotatedRoutes() { $route = new Route('/foo'); $route->setOption('type', 'annotation'); $route->setOption('path', 'foo'); @@ -88,8 +82,7 @@ public function testOnRoutesWithoutAnnotatedRoutes() $this->assertEquals(1, $this->getRouteCollection()->count()); } - public function testOnRoutesWithAnnotatedRoute() - { + public function testOnRoutesWithAnnotatedRoute() { $annotatedRoute = new Route('/bar'); $annotatedRouteCollection = $this->getAnnotatedRouteCollection(); @@ -105,8 +98,7 @@ public function testOnRoutesWithAnnotatedRoute() $this->assertEquals($annotatedRoute, $this->getRouteCollection()->all()['bar']); } - public function testOnRoutesWithoutRequiredOptions() - { + public function testOnRoutesWithoutRequiredOptions() { $this->setExpectedException(\Exception::class); $annotatedRoute = new Route('/bar'); diff --git a/tests/src/Unit/EventSubscriber/TemplateEventSubscriberTest.php b/tests/src/Unit/EventSubscriber/TemplateEventSubscriberTest.php index 2c5c567..6795bac 100644 --- a/tests/src/Unit/EventSubscriber/TemplateEventSubscriberTest.php +++ b/tests/src/Unit/EventSubscriber/TemplateEventSubscriberTest.php @@ -19,8 +19,7 @@ */ class TemplateEventSubscriberTest extends UnitTestCase { - public function testOnKernelControllerWithoutTemplate() - { + public function testOnKernelControllerWithoutTemplate() { $twig = m::mock(\Twig_Environment::class); $templateResolver = m::mock(TemplateResolver::class); @@ -39,8 +38,7 @@ public function testOnKernelControllerWithoutTemplate() $this->assertNull($eventSubscriber->onKernelView($event)); } - public function testOnKernelControllerWithInvalidTemplate() - { + public function testOnKernelControllerWithInvalidTemplate() { $twig = m::mock(\Twig_Environment::class); $templateResolver = m::mock(TemplateResolver::class); @@ -60,8 +58,7 @@ public function testOnKernelControllerWithInvalidTemplate() $this->assertNull($eventSubscriber->onKernelView($event)); } - public function testOnKernelControllerWithTemplate() - { + public function testOnKernelControllerWithTemplate() { $templateName = 'resolved_template'; $twig = m::mock(\Twig_Environment::class); @@ -87,8 +84,7 @@ public function testOnKernelControllerWithTemplate() $this->assertEquals($owner, $template->getOwner()); } - public function testOnKernelControllerWithTemplateName() - { + public function testOnKernelControllerWithTemplateName() { $templateName = 'resolved_template'; $twig = m::mock(\Twig_Environment::class); @@ -116,8 +112,7 @@ public function testOnKernelControllerWithTemplateName() $this->assertEquals($owner, $template->getOwner()); } - public function testOnKernelView() - { + public function testOnKernelView() { $renderedContent = 'rendered_page'; $templateName = 'template.html.twig'; @@ -148,8 +143,7 @@ public function testOnKernelView() $this->assertEquals($renderedContent, $response->getContent()); } - public function testOnKernelViewStreamed() - { + public function testOnKernelViewStreamed() { $templateName = 'template.html.twig'; $twig = m::mock(\Twig_Environment::class); @@ -182,8 +176,7 @@ public function testOnKernelViewStreamed() $response->sendContent(); } - public function tearDown() - { + public function tearDown() { m::close(); } } diff --git a/tests/src/Unit/Fixture/FooControllerNullableParameter.php b/tests/src/Unit/Fixture/FooControllerNullableParameter.php index 5ac9f60..f030056 100644 --- a/tests/src/Unit/Fixture/FooControllerNullableParameter.php +++ b/tests/src/Unit/Fixture/FooControllerNullableParameter.php @@ -4,15 +4,12 @@ class FooControllerNullableParameter { - public function requiredParamAction(\DateTime $param) - { + public function requiredParamAction(\DateTime $param) { } - public function defaultParamAction(\DateTime $param = null) - { + public function defaultParamAction(\DateTime $param = null) { } - public function nullableParamAction(?\DateTime $param) - { + public function nullableParamAction(?\DateTime $param) { } } diff --git a/tests/src/Unit/Fixture/FooControllerParamConverterAtClassAndMethod.php b/tests/src/Unit/Fixture/FooControllerParamConverterAtClassAndMethod.php index f64c755..2845ea0 100644 --- a/tests/src/Unit/Fixture/FooControllerParamConverterAtClassAndMethod.php +++ b/tests/src/Unit/Fixture/FooControllerParamConverterAtClassAndMethod.php @@ -12,7 +12,6 @@ class FooControllerParamConverterAtClassAndMethod /** * @ParamConverter("test2") */ - public function barAction($test, $test2) - { + public function barAction($test, $test2) { } } diff --git a/tests/src/Unit/Helper.php b/tests/src/Unit/Helper.php index e503586..1f22bcb 100644 --- a/tests/src/Unit/Helper.php +++ b/tests/src/Unit/Helper.php @@ -4,8 +4,7 @@ class Helper { - public static function getProtectedMethod($class, $name) - { + public static function getProtectedMethod($class, $name) { $class = new \ReflectionClass($class); $method = $class->getMethod($name); $method->setAccessible(true); diff --git a/tests/src/Unit/Request/ParamConverter/DateTimeParamConverterTest.php b/tests/src/Unit/Request/ParamConverter/DateTimeParamConverterTest.php index 2c76288..4668f53 100644 --- a/tests/src/Unit/Request/ParamConverter/DateTimeParamConverterTest.php +++ b/tests/src/Unit/Request/ParamConverter/DateTimeParamConverterTest.php @@ -15,13 +15,11 @@ class DateTimeParamConverterTest extends UnitTestCase private $converter; - public function setUp() - { + public function setUp() { $this->converter = new DateTimeParamConverter(); } - public function testSupports() - { + public function testSupports() { $config = $this->createConfiguration('DateTime'); $this->assertTrue($this->converter->supports($config)); @@ -32,8 +30,7 @@ public function testSupports() $this->assertFalse($this->converter->supports($config)); } - public function testApply() - { + public function testApply() { $request = new Request([], [], ['start' => '2012-07-21 00:00:00']); $config = $this->createConfiguration('DateTime', 'start'); @@ -46,8 +43,7 @@ public function testApply() ); } - public function testApplyInvalidDate404Exception() - { + public function testApplyInvalidDate404Exception() { $request = new Request([], [], ['start' => 'Invalid DateTime Format']); $config = $this->createConfiguration('DateTime', 'start'); @@ -58,8 +54,7 @@ public function testApplyInvalidDate404Exception() $this->converter->apply($request, $config); } - public function testApplyWithFormatInvalidDate404Exception() - { + public function testApplyWithFormatInvalidDate404Exception() { $request = new Request([], [], ['start' => '2012-07-21']); $config = $this->createConfiguration('DateTime', 'start'); $config->expects($this->any())->method('getOptions')->will( @@ -73,8 +68,7 @@ public function testApplyWithFormatInvalidDate404Exception() $this->converter->apply($request, $config); } - public function testApplyOptionalWithEmptyAttribute() - { + public function testApplyOptionalWithEmptyAttribute() { $request = new Request([], [], ['start' => null]); $config = $this->createConfiguration('DateTime', 'start'); $config->expects($this->once()) @@ -85,16 +79,14 @@ public function testApplyOptionalWithEmptyAttribute() $this->assertNull($request->attributes->get('start')); } - public function testApplyEmptyAttribute() - { + public function testApplyEmptyAttribute() { $request = new Request(); $config = $this->createConfiguration('DateTime', 'start'); $this->assertFalse($this->converter->apply($request, $config)); } - public function createConfiguration($class = null, $name = null) - { + public function createConfiguration($class = null, $name = null) { $config = $this ->getMockBuilder(ParamConverter::class) ->setMethods( diff --git a/tests/src/Unit/Request/ParamConverter/EntityParamConverterTest.php b/tests/src/Unit/Request/ParamConverter/EntityParamConverterTest.php index 62db8e2..f48c20f 100644 --- a/tests/src/Unit/Request/ParamConverter/EntityParamConverterTest.php +++ b/tests/src/Unit/Request/ParamConverter/EntityParamConverterTest.php @@ -17,8 +17,7 @@ */ class EntityParamConverterTest extends UnitTestCase { - private function getEntityParamConverter() - { + private function getEntityParamConverter() { $node = m::mock(Node::class); $entityInterface = m::mock(EntityInterface::class); @@ -30,22 +29,19 @@ private function getEntityParamConverter() return new EntityParamConverter($entityTypeManager); } - public function testSupports() - { + public function testSupports() { $paramConverter = m::mock(ParamConverter::class); $paramConverter->shouldReceive('getClass')->once()->andReturn(Node::class); $this->assertTrue($this->getEntityParamConverter()->supports($paramConverter)); } - public function testNotSupports() - { + public function testNotSupports() { $paramConverter = m::mock(ParamConverter::class); $paramConverter->shouldReceive('getClass')->once()->andReturn(self::class); $this->assertFalse($this->getEntityParamConverter()->supports($paramConverter)); } - public function testApply() - { + public function testApply() { $name = 'test'; $request = new Request(); $request->attributes->set($name, 1); @@ -64,8 +60,7 @@ public function testApply() $this->assertEquals($node, $request->attributes->get($name)); } - public function testApplyNonExistingEntity() - { + public function testApplyNonExistingEntity() { $this->setExpectedException(NotFoundHttpException::class); $entityInterface = m::mock(EntityInterface::class); @@ -89,8 +84,7 @@ public function testApplyNonExistingEntity() $entityParamConverter->apply($request, $paramConverter); } - public function testApplyWithBundle() - { + public function testApplyWithBundle() { $id = 1; $bundle = 'article'; @@ -121,8 +115,7 @@ public function testApplyWithBundle() $this->assertEquals($node, $request->attributes->get($name)); } - public function testApplyWithWrongBundle() - { + public function testApplyWithWrongBundle() { $this->setExpectedException(NotFoundHttpException::class); $id = 1; @@ -152,8 +145,7 @@ public function testApplyWithWrongBundle() $nodeParamConverter->apply($request, $paramConverter); } - public function testApplyOptionalWhenEmpty() - { + public function testApplyOptionalWhenEmpty() { $id = 1; $entityInterface = m::mock(EntityInterface::class); @@ -180,8 +172,7 @@ public function testApplyOptionalWhenEmpty() $this->assertEquals(null, $request->attributes->get($name)); } - public function testApplyWithoutAttribute() - { + public function testApplyWithoutAttribute() { $id = 1; $bundle = 'article'; @@ -205,8 +196,7 @@ public function testApplyWithoutAttribute() $this->assertFalse($nodeParamConverter->apply($request, $paramConverter)); } - public function testOptional() - { + public function testOptional() { $id = 1; $bundle = 'article'; @@ -228,8 +218,7 @@ public function testOptional() $this->assertFalse($nodeParamConverter->apply($request, $paramConverter)); } - public function testOptionalEmptyAttribute() - { + public function testOptionalEmptyAttribute() { $id = 1; $bundle = 'article'; @@ -253,8 +242,7 @@ public function testOptionalEmptyAttribute() $this->assertFalse($nodeParamConverter->apply($request, $paramConverter)); } - public function tearDown() - { + public function tearDown() { m::close(); } } diff --git a/tests/src/Unit/Request/ParamConverter/ParamConverterManagerTest.php b/tests/src/Unit/Request/ParamConverter/ParamConverterManagerTest.php index b9f6fbb..19232b9 100644 --- a/tests/src/Unit/Request/ParamConverter/ParamConverterManagerTest.php +++ b/tests/src/Unit/Request/ParamConverter/ParamConverterManagerTest.php @@ -13,8 +13,7 @@ */ class ParamConverterManagerTest extends UnitTestCase { - public function testPriorities() - { + public function testPriorities() { $manager = new ParamConverterManager(); $this->assertEquals(array(), $manager->all()); @@ -27,8 +26,7 @@ public function testPriorities() $this->assertEquals(array($high, $low), $manager->all()); } - public function testApply() - { + public function testApply() { $supported = $this->createParamConverterMock(); $supported ->expects($this->once()) @@ -64,8 +62,7 @@ public function testApply() $manager->apply(new Request(), $configurations); } - public function testApplyNamedConverter() - { + public function testApplyNamedConverter() { $converter = $this->createParamConverterMock(); $converter ->expects($this->any()) @@ -96,8 +93,7 @@ public function testApplyNamedConverter() * @expectedException \RuntimeException * @expectedExceptionMessage Converter 'test' does not support conversion of parameter 'param'. */ - public function testApplyNamedConverterNotSupportsParameter() - { + public function testApplyNamedConverterNotSupportsParameter() { $converter = $this->createParamConverterMock(); $converter ->expects($this->any()) @@ -123,8 +119,7 @@ public function testApplyNamedConverterNotSupportsParameter() * @expectedException \RuntimeException * @expectedExceptionMessage No converter named 'test' found for conversion of parameter 'param'. */ - public function testApplyNamedConverterNoConverter() - { + public function testApplyNamedConverterNoConverter() { $request = new Request(); $request->attributes->set('param', '1234'); @@ -138,8 +133,7 @@ public function testApplyNamedConverterNoConverter() $manager->apply($request, array($configuration)); } - public function testApplyNotCalledOnAlreadyConvertedObjects() - { + public function testApplyNotCalledOnAlreadyConvertedObjects() { $converter = $this->createParamConverterMock(); $converter ->expects($this->never()) @@ -164,8 +158,7 @@ public function testApplyNotCalledOnAlreadyConvertedObjects() $manager->apply($request, array($configuration)); } - public function testApplyWithoutArray() - { + public function testApplyWithoutArray() { $converter = $this->createParamConverterMock(); $converter ->expects($this->any()) @@ -189,8 +182,7 @@ public function testApplyWithoutArray() $manager->apply($request, $configuration); } - protected function createParamConverterMock() - { + protected function createParamConverterMock() { return $this->getMockBuilder(ParamConverterInterface::class)->getMock(); } } diff --git a/tests/src/Unit/Routing/AnnotatedRouteControllerLoaderTest.php b/tests/src/Unit/Routing/AnnotatedRouteControllerLoaderTest.php index abd34e4..7462fa9 100644 --- a/tests/src/Unit/Routing/AnnotatedRouteControllerLoaderTest.php +++ b/tests/src/Unit/Routing/AnnotatedRouteControllerLoaderTest.php @@ -15,8 +15,7 @@ */ class AnnotatedRouteControllerLoaderTest extends UnitTestCase { - public function testConfigureRoute() - { + public function testConfigureRoute() { $routeConfiguration = m::mock(\Drupal\controller_annotations\Configuration\Route::class); $routeConfiguration->shouldReceive('getService')->andReturn(false); $routeConfiguration->shouldReceive('isAdmin')->andReturn(true); diff --git a/tests/src/Unit/Templating/TemplateResolverTest.php b/tests/src/Unit/Templating/TemplateResolverTest.php index fd418db..35c8299 100644 --- a/tests/src/Unit/Templating/TemplateResolverTest.php +++ b/tests/src/Unit/Templating/TemplateResolverTest.php @@ -17,8 +17,7 @@ class TemplateResolverTest extends UnitTestCase */ private $templateResolver; - public function setUp() - { + public function setUp() { $this->templateResolver = new TemplateResolver(); } @@ -42,8 +41,7 @@ public function testResolveByControllerAndAction( /** * @return array */ - public function controllerActionProvider() - { + public function controllerActionProvider() { $expected = 'modules/foo/templates/foo-foo-bar.html.twig'; return [ @@ -72,8 +70,7 @@ public function controllerActionProvider() /** * @dataProvider normalizeProvider */ - public function testNormalize($template, $expected) - { + public function testNormalize($template, $expected) { $this->assertEquals( $expected, $this->templateResolver->normalize($template) @@ -83,8 +80,7 @@ public function testNormalize($template, $expected) /** * @return array */ - public function normalizeProvider() - { + public function normalizeProvider() { return [ ['foo:bar', 'modules/foo/templates/foo-bar.html.twig'], ['foobar:baz', 'modules/foobar/templates/foobar-baz.html.twig'], @@ -92,14 +88,12 @@ public function normalizeProvider() ]; } - public function testNormalizeWithInvalidTemplate() - { + public function testNormalizeWithInvalidTemplate() { $this->setExpectedException(\InvalidArgumentException::class); $this->templateResolver->normalize('foo'); } - public function testResolveByControllerAndActionWithInvalidController() - { + public function testResolveByControllerAndActionWithInvalidController() { $this->setExpectedException(\InvalidArgumentException::class); $this->templateResolver->resolveByControllerAndAction('Foo', 'fooAction'); } diff --git a/tests/src/polyfill.php b/tests/src/polyfill.php index 92b8321..ff28eb8 100644 --- a/tests/src/polyfill.php +++ b/tests/src/polyfill.php @@ -1,8 +1,7 @@ <?php if (!function_exists('drupal_get_path')) { - function drupal_get_path($type, $name) - { + function drupal_get_path($type, $name) { switch ($type) { case 'module': return 'modules/'.$name; From 6288df3fab4144ab084f3f8e9b38522adc7cfcfd Mon Sep 17 00:00:00 2001 From: Andreas Hennings <andreas@dqxtech.net> Date: Sat, 11 Jan 2020 23:25:19 +0100 Subject: [PATCH 03/23] (CS) Class/interface curly bracket on same line. --- src/Cache/DrupalCache.php | 4 ++-- src/Configuration/Cache.php | 4 ++-- src/Configuration/ConfigurationAnnotation.php | 4 ++-- src/Configuration/ConfigurationInterface.php | 4 ++-- src/Configuration/Method.php | 4 ++-- src/Configuration/ParamConverter.php | 3 +-- src/Configuration/Route.php | 3 +-- src/Configuration/RouteModifierClassInterface.php | 4 ++-- src/Configuration/RouteModifierInterface.php | 4 ++-- src/Configuration/RouteModifierMethodInterface.php | 4 ++-- src/Configuration/Security.php | 4 ++-- src/Configuration/Template.php | 3 +-- src/Configuration/Title.php | 4 ++-- src/EventSubscriber/ControllerEventSubscriber.php | 4 ++-- src/EventSubscriber/HttpCacheEventSubscriber.php | 3 +-- .../ParamConverterEventSubscriber.php | 4 ++-- src/EventSubscriber/RouteEventSubscriber.php | 4 ++-- src/EventSubscriber/TemplateEventSubscriber.php | 4 ++-- .../ParamConverter/DateTimeParamConverter.php | 4 ++-- src/Request/ParamConverter/EntityParamConverter.php | 3 +-- .../ParamConverter/ParamConverterInterface.php | 4 ++-- src/Request/ParamConverter/ParamConverterManager.php | 4 ++-- src/Routing/AnnotatedRouteControllerLoader.php | 4 ++-- src/Templating/TemplateResolver.php | 4 ++-- .../src/Controller/AdminController.php | 4 ++-- .../src/Controller/BasicController.php | 4 ++-- .../src/Controller/InvokeController.php | 4 ++-- .../src/Controller/MethodController.php | 4 ++-- .../src/Controller/ParamConverterController.php | 3 +-- .../src/Controller/PrefixedRouteController.php | 4 ++-- .../src/Controller/SecurityController.php | 4 ++-- .../src/Controller/ServiceController.php | 4 ++-- .../src/Controller/TemplateController.php | 4 ++-- .../src/Controller/TitleController.php | 3 +-- .../src/Security/Custom.php | 4 ++-- .../controller_annotations_test/src/Title/Custom.php | 3 +-- tests/src/Kernel/AnnotationsTest.php | 4 ++-- tests/src/Kernel/DrupalTestKernel.php | 4 ++-- tests/src/Kernel/KernelTestBase.php | 4 ++-- tests/src/Kernel/TestUserSession.php | 4 ++-- tests/src/Unit/Cache/DrupalCacheTest.php | 4 ++-- tests/src/Unit/Configuration/CacheTest.php | 4 ++-- tests/src/Unit/Configuration/MethodTest.php | 4 ++-- tests/src/Unit/Configuration/RouteTest.php | 4 ++-- tests/src/Unit/Configuration/SecurityTest.php | 4 ++-- tests/src/Unit/Configuration/TitleTest.php | 4 ++-- .../ControllerEventSubscriberTest.php | 8 ++++---- .../Unit/EventSubscriber/HttpCacheListenerTest.php | 8 ++++---- .../ParamConverterEventSubscriberTest.php | 12 ++++-------- .../EventSubscriber/RouteEventSubscriberTest.php | 4 ++-- .../EventSubscriber/TemplateEventSubscriberTest.php | 4 ++-- .../Unit/Fixture/FooControllerNullableParameter.php | 4 ++-- .../FooControllerParamConverterAtClassAndMethod.php | 4 ++-- tests/src/Unit/Helper.php | 4 ++-- .../ParamConverter/DateTimeParamConverterTest.php | 3 +-- .../ParamConverter/EntityParamConverterTest.php | 4 ++-- .../ParamConverter/ParamConverterManagerTest.php | 4 ++-- .../Routing/AnnotatedRouteControllerLoaderTest.php | 4 ++-- tests/src/Unit/Templating/TemplateResolverTest.php | 4 ++-- 59 files changed, 115 insertions(+), 128 deletions(-) diff --git a/src/Cache/DrupalCache.php b/src/Cache/DrupalCache.php index 8ce73ad..5c98dae 100644 --- a/src/Cache/DrupalCache.php +++ b/src/Cache/DrupalCache.php @@ -5,8 +5,8 @@ use Doctrine\Common\Cache\CacheProvider; use Drupal\Core\Cache\CacheBackendInterface; -class DrupalCache extends CacheProvider -{ +class DrupalCache extends CacheProvider { + /** * @var CacheBackendInterface */ diff --git a/src/Configuration/Cache.php b/src/Configuration/Cache.php index 8f5d328..b722d3d 100644 --- a/src/Configuration/Cache.php +++ b/src/Configuration/Cache.php @@ -5,8 +5,8 @@ /** * @Annotation */ -class Cache extends ConfigurationAnnotation -{ +class Cache extends ConfigurationAnnotation { + /** * The expiration date as a valid date for the strtotime() function. * diff --git a/src/Configuration/ConfigurationAnnotation.php b/src/Configuration/ConfigurationAnnotation.php index 1fe8757..ecd281b 100644 --- a/src/Configuration/ConfigurationAnnotation.php +++ b/src/Configuration/ConfigurationAnnotation.php @@ -7,8 +7,8 @@ * * @author Johannes M. Schmitt <schmittjoh@gmail.com> */ -abstract class ConfigurationAnnotation implements ConfigurationInterface -{ +abstract class ConfigurationAnnotation implements ConfigurationInterface { + public function __construct(array $values) { foreach ($values as $k => $v) { if (!method_exists($this, $name = 'set'.$k)) { diff --git a/src/Configuration/ConfigurationInterface.php b/src/Configuration/ConfigurationInterface.php index 9874cdb..a648cc8 100644 --- a/src/Configuration/ConfigurationInterface.php +++ b/src/Configuration/ConfigurationInterface.php @@ -7,8 +7,8 @@ * * @author Fabien Potencier <fabien@symfony.com> */ -interface ConfigurationInterface -{ +interface ConfigurationInterface { + /** * Returns the alias name for an annotated configuration. * diff --git a/src/Configuration/Method.php b/src/Configuration/Method.php index ba6f63c..eeb3c51 100644 --- a/src/Configuration/Method.php +++ b/src/Configuration/Method.php @@ -7,8 +7,8 @@ /** * @Annotation */ -class Method extends ConfigurationAnnotation implements RouteModifierMethodInterface, RouteModifierClassInterface -{ +class Method extends ConfigurationAnnotation implements RouteModifierMethodInterface, RouteModifierClassInterface { + /** * An array of restricted HTTP methods. * diff --git a/src/Configuration/ParamConverter.php b/src/Configuration/ParamConverter.php index 6201b58..affb0ca 100644 --- a/src/Configuration/ParamConverter.php +++ b/src/Configuration/ParamConverter.php @@ -8,8 +8,7 @@ * @author Fabien Potencier <fabien@symfony.com> * @Annotation */ -class ParamConverter extends ConfigurationAnnotation -{ +class ParamConverter extends ConfigurationAnnotation { /** * The parameter name. diff --git a/src/Configuration/Route.php b/src/Configuration/Route.php index ffb4b26..42bdfcd 100644 --- a/src/Configuration/Route.php +++ b/src/Configuration/Route.php @@ -8,8 +8,7 @@ /** * @Annotation */ -class Route extends BaseRoute implements RouteModifierMethodInterface, RouteModifierClassInterface -{ +class Route extends BaseRoute implements RouteModifierMethodInterface, RouteModifierClassInterface { /** * @var string diff --git a/src/Configuration/RouteModifierClassInterface.php b/src/Configuration/RouteModifierClassInterface.php index 6f5861d..d0cf6d7 100644 --- a/src/Configuration/RouteModifierClassInterface.php +++ b/src/Configuration/RouteModifierClassInterface.php @@ -4,8 +4,8 @@ use Symfony\Component\Routing\Route as RoutingRoute; -interface RouteModifierClassInterface extends RouteModifierInterface -{ +interface RouteModifierClassInterface extends RouteModifierInterface { + /** * @param RoutingRoute $route * @param \ReflectionClass $class diff --git a/src/Configuration/RouteModifierInterface.php b/src/Configuration/RouteModifierInterface.php index 6d59789..c77c7fd 100644 --- a/src/Configuration/RouteModifierInterface.php +++ b/src/Configuration/RouteModifierInterface.php @@ -2,6 +2,6 @@ namespace Drupal\controller_annotations\Configuration; -interface RouteModifierInterface -{ +interface RouteModifierInterface { + } diff --git a/src/Configuration/RouteModifierMethodInterface.php b/src/Configuration/RouteModifierMethodInterface.php index 31d4197..c87c775 100644 --- a/src/Configuration/RouteModifierMethodInterface.php +++ b/src/Configuration/RouteModifierMethodInterface.php @@ -4,8 +4,8 @@ use Symfony\Component\Routing\Route as RoutingRoute; -interface RouteModifierMethodInterface extends RouteModifierInterface -{ +interface RouteModifierMethodInterface extends RouteModifierInterface { + /** * @param RoutingRoute $route * @param \ReflectionClass $class diff --git a/src/Configuration/Security.php b/src/Configuration/Security.php index 142f90d..7458b60 100644 --- a/src/Configuration/Security.php +++ b/src/Configuration/Security.php @@ -7,8 +7,8 @@ /** * @Annotation */ -class Security extends ConfigurationAnnotation implements RouteModifierMethodInterface, RouteModifierClassInterface -{ +class Security extends ConfigurationAnnotation implements RouteModifierMethodInterface, RouteModifierClassInterface { + /** * @var string */ diff --git a/src/Configuration/Template.php b/src/Configuration/Template.php index 7ee6a88..92d2488 100644 --- a/src/Configuration/Template.php +++ b/src/Configuration/Template.php @@ -5,8 +5,7 @@ /** * @Annotation */ -class Template extends ConfigurationAnnotation -{ +class Template extends ConfigurationAnnotation { /** * The template reference. diff --git a/src/Configuration/Title.php b/src/Configuration/Title.php index c03d2a5..a9a3540 100644 --- a/src/Configuration/Title.php +++ b/src/Configuration/Title.php @@ -7,8 +7,8 @@ /** * @Annotation */ -class Title extends ConfigurationAnnotation implements RouteModifierMethodInterface, RouteModifierClassInterface -{ +class Title extends ConfigurationAnnotation implements RouteModifierMethodInterface, RouteModifierClassInterface { + /** * @var string */ diff --git a/src/EventSubscriber/ControllerEventSubscriber.php b/src/EventSubscriber/ControllerEventSubscriber.php index b55ec3e..6ce4ad6 100644 --- a/src/EventSubscriber/ControllerEventSubscriber.php +++ b/src/EventSubscriber/ControllerEventSubscriber.php @@ -10,8 +10,8 @@ use Symfony\Component\HttpKernel\Event\FilterControllerEvent; use Symfony\Component\HttpKernel\KernelEvents; -class ControllerEventSubscriber implements EventSubscriberInterface -{ +class ControllerEventSubscriber implements EventSubscriberInterface { + /** * @var Reader */ diff --git a/src/EventSubscriber/HttpCacheEventSubscriber.php b/src/EventSubscriber/HttpCacheEventSubscriber.php index 0e60540..c0e9729 100644 --- a/src/EventSubscriber/HttpCacheEventSubscriber.php +++ b/src/EventSubscriber/HttpCacheEventSubscriber.php @@ -11,8 +11,7 @@ use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\ExpressionLanguage\ExpressionLanguage; -class HttpCacheEventSubscriber implements EventSubscriberInterface -{ +class HttpCacheEventSubscriber implements EventSubscriberInterface { /** * @var \SplObjectStorage diff --git a/src/EventSubscriber/ParamConverterEventSubscriber.php b/src/EventSubscriber/ParamConverterEventSubscriber.php index bc5610c..c9b4d01 100644 --- a/src/EventSubscriber/ParamConverterEventSubscriber.php +++ b/src/EventSubscriber/ParamConverterEventSubscriber.php @@ -9,8 +9,8 @@ use Symfony\Component\HttpKernel\Event\FilterControllerEvent; use Symfony\Component\HttpKernel\KernelEvents; -class ParamConverterEventSubscriber implements EventSubscriberInterface -{ +class ParamConverterEventSubscriber implements EventSubscriberInterface { + /** * @var ParamConverterManager */ diff --git a/src/EventSubscriber/RouteEventSubscriber.php b/src/EventSubscriber/RouteEventSubscriber.php index f51ac0b..d840095 100644 --- a/src/EventSubscriber/RouteEventSubscriber.php +++ b/src/EventSubscriber/RouteEventSubscriber.php @@ -9,8 +9,8 @@ use Symfony\Component\Routing\Loader\AnnotationDirectoryLoader; use Symfony\Component\Routing\Route; -class RouteEventSubscriber implements EventSubscriberInterface -{ +class RouteEventSubscriber implements EventSubscriberInterface { + /** * @var AnnotationDirectoryLoader */ diff --git a/src/EventSubscriber/TemplateEventSubscriber.php b/src/EventSubscriber/TemplateEventSubscriber.php index a66a789..098f5df 100644 --- a/src/EventSubscriber/TemplateEventSubscriber.php +++ b/src/EventSubscriber/TemplateEventSubscriber.php @@ -13,8 +13,8 @@ use Symfony\Component\HttpKernel\Event\KernelEvent; use Symfony\Component\HttpKernel\KernelEvents; -class TemplateEventSubscriber implements EventSubscriberInterface -{ +class TemplateEventSubscriber implements EventSubscriberInterface { + /** * @var \Twig_Environment */ diff --git a/src/Request/ParamConverter/DateTimeParamConverter.php b/src/Request/ParamConverter/DateTimeParamConverter.php index 9b21ad8..2b15067 100644 --- a/src/Request/ParamConverter/DateTimeParamConverter.php +++ b/src/Request/ParamConverter/DateTimeParamConverter.php @@ -12,8 +12,8 @@ * * @author Benjamin Eberlei <kontakt@beberlei.de> */ -class DateTimeParamConverter implements ParamConverterInterface -{ +class DateTimeParamConverter implements ParamConverterInterface { + /** * {@inheritdoc} * diff --git a/src/Request/ParamConverter/EntityParamConverter.php b/src/Request/ParamConverter/EntityParamConverter.php index b9ab9d2..5dddb37 100644 --- a/src/Request/ParamConverter/EntityParamConverter.php +++ b/src/Request/ParamConverter/EntityParamConverter.php @@ -13,8 +13,7 @@ use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; -class EntityParamConverter implements ParamConverterInterface -{ +class EntityParamConverter implements ParamConverterInterface { /** * @var EntityTypeManagerInterface diff --git a/src/Request/ParamConverter/ParamConverterInterface.php b/src/Request/ParamConverter/ParamConverterInterface.php index d138b07..e433cc8 100644 --- a/src/Request/ParamConverter/ParamConverterInterface.php +++ b/src/Request/ParamConverter/ParamConverterInterface.php @@ -11,8 +11,8 @@ * * @author Fabien Potencier <fabien@symfony.com> */ -interface ParamConverterInterface -{ +interface ParamConverterInterface { + /** * Stores the object in the request. * diff --git a/src/Request/ParamConverter/ParamConverterManager.php b/src/Request/ParamConverter/ParamConverterManager.php index 3dbb042..e50065e 100644 --- a/src/Request/ParamConverter/ParamConverterManager.php +++ b/src/Request/ParamConverter/ParamConverterManager.php @@ -10,8 +10,8 @@ * @author Fabien Potencier <fabien@symfony.com> * @author Henrik Bjornskov <henrik@bjrnskov.dk> */ -class ParamConverterManager -{ +class ParamConverterManager { + /** * @var array */ diff --git a/src/Routing/AnnotatedRouteControllerLoader.php b/src/Routing/AnnotatedRouteControllerLoader.php index 09cfd0e..5460dd7 100644 --- a/src/Routing/AnnotatedRouteControllerLoader.php +++ b/src/Routing/AnnotatedRouteControllerLoader.php @@ -8,8 +8,8 @@ use Symfony\Component\Routing\Loader\AnnotationClassLoader; use Symfony\Component\Routing\Route; -class AnnotatedRouteControllerLoader extends AnnotationClassLoader -{ +class AnnotatedRouteControllerLoader extends AnnotationClassLoader { + /** * @param Route $route * @param \ReflectionClass $class diff --git a/src/Templating/TemplateResolver.php b/src/Templating/TemplateResolver.php index 049ed5c..e68c179 100644 --- a/src/Templating/TemplateResolver.php +++ b/src/Templating/TemplateResolver.php @@ -2,8 +2,8 @@ namespace Drupal\controller_annotations\Templating; -class TemplateResolver -{ +class TemplateResolver { + /** * Convert controller class * "Drupal\<module>\Controller\<controller>Controller" diff --git a/tests/modules/controller_annotations_test/src/Controller/AdminController.php b/tests/modules/controller_annotations_test/src/Controller/AdminController.php index 0a46c5e..48fd285 100644 --- a/tests/modules/controller_annotations_test/src/Controller/AdminController.php +++ b/tests/modules/controller_annotations_test/src/Controller/AdminController.php @@ -9,8 +9,8 @@ /** * @Route("test/admin/") */ -class AdminController extends ControllerBase -{ +class AdminController extends ControllerBase { + /** * @Route("admin", admin=true) * @Security(role="administrator") diff --git a/tests/modules/controller_annotations_test/src/Controller/BasicController.php b/tests/modules/controller_annotations_test/src/Controller/BasicController.php index 193b311..32ac58a 100644 --- a/tests/modules/controller_annotations_test/src/Controller/BasicController.php +++ b/tests/modules/controller_annotations_test/src/Controller/BasicController.php @@ -10,8 +10,8 @@ /** * @Security(access=true) */ -class BasicController extends ControllerBase -{ +class BasicController extends ControllerBase { + /** * @Route("test/basic") */ diff --git a/tests/modules/controller_annotations_test/src/Controller/InvokeController.php b/tests/modules/controller_annotations_test/src/Controller/InvokeController.php index a984a5b..a9824fb 100644 --- a/tests/modules/controller_annotations_test/src/Controller/InvokeController.php +++ b/tests/modules/controller_annotations_test/src/Controller/InvokeController.php @@ -10,8 +10,8 @@ * @Route("test/invoke", service="controller.invoke") * @Security(access=true) */ -class InvokeController -{ +class InvokeController { + public function __invoke() { return new Response('InvokeController::__invoke'); } diff --git a/tests/modules/controller_annotations_test/src/Controller/MethodController.php b/tests/modules/controller_annotations_test/src/Controller/MethodController.php index 30e0dfa..ba77101 100644 --- a/tests/modules/controller_annotations_test/src/Controller/MethodController.php +++ b/tests/modules/controller_annotations_test/src/Controller/MethodController.php @@ -8,8 +8,8 @@ use Drupal\controller_annotations\Configuration\Method; use Symfony\Component\HttpFoundation\Response; -class MethodController extends ControllerBase -{ +class MethodController extends ControllerBase { + /** * @Route("test/method") * @Method("GET") diff --git a/tests/modules/controller_annotations_test/src/Controller/ParamConverterController.php b/tests/modules/controller_annotations_test/src/Controller/ParamConverterController.php index 6c43be6..981e798 100644 --- a/tests/modules/controller_annotations_test/src/Controller/ParamConverterController.php +++ b/tests/modules/controller_annotations_test/src/Controller/ParamConverterController.php @@ -11,8 +11,7 @@ /** * @Route("test/param-converter/") */ -class ParamConverterController extends ControllerBase -{ +class ParamConverterController extends ControllerBase { /** * @Route("date/{start}") diff --git a/tests/modules/controller_annotations_test/src/Controller/PrefixedRouteController.php b/tests/modules/controller_annotations_test/src/Controller/PrefixedRouteController.php index ef9be63..5c07d16 100644 --- a/tests/modules/controller_annotations_test/src/Controller/PrefixedRouteController.php +++ b/tests/modules/controller_annotations_test/src/Controller/PrefixedRouteController.php @@ -10,8 +10,8 @@ /** * @Route("test/prefix") */ -class PrefixedRouteController extends ControllerBase -{ +class PrefixedRouteController extends ControllerBase { + /** * @Route * @Security(access=true) diff --git a/tests/modules/controller_annotations_test/src/Controller/SecurityController.php b/tests/modules/controller_annotations_test/src/Controller/SecurityController.php index fa4d223..1f88737 100644 --- a/tests/modules/controller_annotations_test/src/Controller/SecurityController.php +++ b/tests/modules/controller_annotations_test/src/Controller/SecurityController.php @@ -15,8 +15,8 @@ * @Route("test/security/") * @Method("GET") */ -class SecurityController extends ControllerBase -{ +class SecurityController extends ControllerBase { + /** * @Route("access") * @Security(access=true) diff --git a/tests/modules/controller_annotations_test/src/Controller/ServiceController.php b/tests/modules/controller_annotations_test/src/Controller/ServiceController.php index c2481c6..b837239 100644 --- a/tests/modules/controller_annotations_test/src/Controller/ServiceController.php +++ b/tests/modules/controller_annotations_test/src/Controller/ServiceController.php @@ -9,8 +9,8 @@ /** * @Route(service="controller.service") */ -class ServiceController -{ +class ServiceController { + /** * @Route("test/service") * @Security(access=true) diff --git a/tests/modules/controller_annotations_test/src/Controller/TemplateController.php b/tests/modules/controller_annotations_test/src/Controller/TemplateController.php index 6caa160..a6ba16b 100644 --- a/tests/modules/controller_annotations_test/src/Controller/TemplateController.php +++ b/tests/modules/controller_annotations_test/src/Controller/TemplateController.php @@ -10,8 +10,8 @@ /** * @Route("test/template/") */ -class TemplateController extends ControllerBase -{ +class TemplateController extends ControllerBase { + /** * @Route("empty") * @Security(access=true) diff --git a/tests/modules/controller_annotations_test/src/Controller/TitleController.php b/tests/modules/controller_annotations_test/src/Controller/TitleController.php index 4f66e02..f332fc3 100644 --- a/tests/modules/controller_annotations_test/src/Controller/TitleController.php +++ b/tests/modules/controller_annotations_test/src/Controller/TitleController.php @@ -10,8 +10,7 @@ /** * @Route("test/title/") */ -class TitleController extends ControllerBase -{ +class TitleController extends ControllerBase { /** * @Route("normal") diff --git a/tests/modules/controller_annotations_test/src/Security/Custom.php b/tests/modules/controller_annotations_test/src/Security/Custom.php index 92821aa..ffff0ac 100644 --- a/tests/modules/controller_annotations_test/src/Security/Custom.php +++ b/tests/modules/controller_annotations_test/src/Security/Custom.php @@ -5,8 +5,8 @@ use Drupal\Core\Access\AccessResult; use Drupal\Core\Session\AccountInterface; -class Custom -{ +class Custom { + /** * @param AccountInterface $account * @return AccessResult diff --git a/tests/modules/controller_annotations_test/src/Title/Custom.php b/tests/modules/controller_annotations_test/src/Title/Custom.php index 2cef320..505bc18 100644 --- a/tests/modules/controller_annotations_test/src/Title/Custom.php +++ b/tests/modules/controller_annotations_test/src/Title/Custom.php @@ -2,8 +2,7 @@ namespace Drupal\controller_annotations_test\Title; -class Custom -{ +class Custom { /** * @return string diff --git a/tests/src/Kernel/AnnotationsTest.php b/tests/src/Kernel/AnnotationsTest.php index a480ef3..97f345c 100644 --- a/tests/src/Kernel/AnnotationsTest.php +++ b/tests/src/Kernel/AnnotationsTest.php @@ -8,8 +8,8 @@ /** * @group controller_annotations */ -class AnnotationsTest extends KernelTestBase -{ +class AnnotationsTest extends KernelTestBase { + public function testRouting() { $response = $this->request(Request::create('/test/basic')); $this->assertEquals('BasicController::basicAction', $response->getContent()); diff --git a/tests/src/Kernel/DrupalTestKernel.php b/tests/src/Kernel/DrupalTestKernel.php index 9664a2a..5be1df5 100644 --- a/tests/src/Kernel/DrupalTestKernel.php +++ b/tests/src/Kernel/DrupalTestKernel.php @@ -6,8 +6,8 @@ use Drupal\Core\Site\Settings; use Symfony\Component\HttpFoundation\Request; -class DrupalTestKernel extends DrupalKernel -{ +class DrupalTestKernel extends DrupalKernel { + /** * {@inheritdoc} */ diff --git a/tests/src/Kernel/KernelTestBase.php b/tests/src/Kernel/KernelTestBase.php index 6f615ba..57eca7c 100644 --- a/tests/src/Kernel/KernelTestBase.php +++ b/tests/src/Kernel/KernelTestBase.php @@ -11,8 +11,8 @@ use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\StreamedResponse; -abstract class KernelTestBase extends BaseKernelTestBase -{ +abstract class KernelTestBase extends BaseKernelTestBase { + /** * @var DrupalKernel */ diff --git a/tests/src/Kernel/TestUserSession.php b/tests/src/Kernel/TestUserSession.php index e86f4fe..4e97ebe 100644 --- a/tests/src/Kernel/TestUserSession.php +++ b/tests/src/Kernel/TestUserSession.php @@ -4,8 +4,8 @@ use Drupal\Core\Session\UserSession; -class TestUserSession extends UserSession -{ +class TestUserSession extends UserSession { + /** * @var array */ diff --git a/tests/src/Unit/Cache/DrupalCacheTest.php b/tests/src/Unit/Cache/DrupalCacheTest.php index 9850b20..a85d2ea 100644 --- a/tests/src/Unit/Cache/DrupalCacheTest.php +++ b/tests/src/Unit/Cache/DrupalCacheTest.php @@ -8,8 +8,8 @@ use Mockery as m; use StdClass; -class DrupalCacheTest extends UnitTestCase -{ +class DrupalCacheTest extends UnitTestCase { + public function testDoFetch() { $drupalCache = $this->getDrupalCacheMock(); $drupalCache->shouldReceive('get')->once()->withArgs(['[foo][1]'])->andReturn($this->getCacheData('bar')); diff --git a/tests/src/Unit/Configuration/CacheTest.php b/tests/src/Unit/Configuration/CacheTest.php index f686de7..c0099f0 100644 --- a/tests/src/Unit/Configuration/CacheTest.php +++ b/tests/src/Unit/Configuration/CacheTest.php @@ -5,8 +5,8 @@ use Drupal\controller_annotations\Configuration\Cache; use Drupal\Tests\UnitTestCase; -class CacheTest extends UnitTestCase -{ +class CacheTest extends UnitTestCase { + public function testProperties() { $cache = new Cache([]); diff --git a/tests/src/Unit/Configuration/MethodTest.php b/tests/src/Unit/Configuration/MethodTest.php index fe9d4a9..f56085e 100644 --- a/tests/src/Unit/Configuration/MethodTest.php +++ b/tests/src/Unit/Configuration/MethodTest.php @@ -7,8 +7,8 @@ use Mockery as m; use Symfony\Component\Routing\Route; -class MethodTest extends UnitTestCase -{ +class MethodTest extends UnitTestCase { + public function testModifyRouteClass() { $route = m::mock(Route::class); $route->shouldReceive('setMethods')->once()->withArgs([['GET', 'POST']]); diff --git a/tests/src/Unit/Configuration/RouteTest.php b/tests/src/Unit/Configuration/RouteTest.php index 26bf7d4..52a62a7 100644 --- a/tests/src/Unit/Configuration/RouteTest.php +++ b/tests/src/Unit/Configuration/RouteTest.php @@ -7,8 +7,8 @@ use Mockery as m; use Symfony\Component\Routing\Route; -class RouteTest extends UnitTestCase -{ +class RouteTest extends UnitTestCase { + public function testModifyRouteClass() { $route = m::mock(Route::class); $route->shouldReceive('setOption')->once()->withArgs(['_admin_route', true]); diff --git a/tests/src/Unit/Configuration/SecurityTest.php b/tests/src/Unit/Configuration/SecurityTest.php index 68c0ad9..7eb5a9d 100644 --- a/tests/src/Unit/Configuration/SecurityTest.php +++ b/tests/src/Unit/Configuration/SecurityTest.php @@ -7,8 +7,8 @@ use Mockery as m; use Symfony\Component\Routing\Route; -class SecurityTest extends UnitTestCase -{ +class SecurityTest extends UnitTestCase { + public function testModifyRouteMethod() { $route = m::mock(Route::class); $route->shouldReceive('setRequirement')->once()->withArgs(['_access', true]); diff --git a/tests/src/Unit/Configuration/TitleTest.php b/tests/src/Unit/Configuration/TitleTest.php index 3e4b138..b3ca7b4 100644 --- a/tests/src/Unit/Configuration/TitleTest.php +++ b/tests/src/Unit/Configuration/TitleTest.php @@ -7,8 +7,8 @@ use Mockery as m; use Symfony\Component\Routing\Route; -class TitleTest extends UnitTestCase -{ +class TitleTest extends UnitTestCase { + public function testModifyRouteMethod() { $route = m::mock(Route::class); $route->shouldReceive('setDefault')->once()->withArgs(['_title', 'Hello World']); diff --git a/tests/src/Unit/EventSubscriber/ControllerEventSubscriberTest.php b/tests/src/Unit/EventSubscriber/ControllerEventSubscriberTest.php index 4e3ac66..36beca6 100644 --- a/tests/src/Unit/EventSubscriber/ControllerEventSubscriberTest.php +++ b/tests/src/Unit/EventSubscriber/ControllerEventSubscriberTest.php @@ -14,8 +14,8 @@ /** * @group controller_annotations */ -class ControllerEventSubscriberTest extends UnitTestCase -{ +class ControllerEventSubscriberTest extends UnitTestCase { + public function testOnKernelController() { $reader = m::mock(Reader::class); @@ -110,8 +110,8 @@ public function testMergeConfigurationsMismatch() { } } -class ControllerInvokableController -{ +class ControllerInvokableController { + public function __invoke() { } } diff --git a/tests/src/Unit/EventSubscriber/HttpCacheListenerTest.php b/tests/src/Unit/EventSubscriber/HttpCacheListenerTest.php index e85eff1..6eba28e 100644 --- a/tests/src/Unit/EventSubscriber/HttpCacheListenerTest.php +++ b/tests/src/Unit/EventSubscriber/HttpCacheListenerTest.php @@ -10,8 +10,8 @@ use Symfony\Component\HttpKernel\Event\FilterControllerEvent; use Symfony\Component\HttpKernel\Event\FilterResponseEvent; -class HttpCacheListenerTest extends UnitTestCase -{ +class HttpCacheListenerTest extends UnitTestCase { + public function setUp() { $this->listener = new HttpCacheEventSubscriber(); $this->response = new Response(); @@ -229,8 +229,8 @@ private function getKernel() { } } -class TestEntity -{ +class TestEntity { + public function getDate() { return new \DateTime('Fri, 23 Aug 2013 00:00:00 GMT'); } diff --git a/tests/src/Unit/EventSubscriber/ParamConverterEventSubscriberTest.php b/tests/src/Unit/EventSubscriber/ParamConverterEventSubscriberTest.php index de8e240..037ec9e 100644 --- a/tests/src/Unit/EventSubscriber/ParamConverterEventSubscriberTest.php +++ b/tests/src/Unit/EventSubscriber/ParamConverterEventSubscriberTest.php @@ -12,8 +12,7 @@ use Symfony\Component\HttpKernel\HttpKernelInterface; use Mockery as m; -class ParamConverterEventSubscriberTest extends UnitTestCase -{ +class ParamConverterEventSubscriberTest extends UnitTestCase { /** * @dataProvider getControllerWithNoArgsFixtures @@ -171,8 +170,7 @@ public function testPredefinedConfigurations() { } } -class ParamConverterTestController -{ +class ParamConverterTestController { public function noArgAction(Request $request) { } @@ -181,15 +179,13 @@ public function dateAction(\DateTime $date) { } } -class ParamConverterInvokableNoArgController -{ +class ParamConverterInvokableNoArgController { public function __invoke(Request $request) { } } -class ParamConverterInvokableController -{ +class ParamConverterInvokableController { public function __invoke(\DateTime $date) { } diff --git a/tests/src/Unit/EventSubscriber/RouteEventSubscriberTest.php b/tests/src/Unit/EventSubscriber/RouteEventSubscriberTest.php index 8d0e3b6..fbad8e1 100644 --- a/tests/src/Unit/EventSubscriber/RouteEventSubscriberTest.php +++ b/tests/src/Unit/EventSubscriber/RouteEventSubscriberTest.php @@ -13,8 +13,8 @@ /** * @group controller_annotations */ -class RouteEventSubscriberTest extends UnitTestCase -{ +class RouteEventSubscriberTest extends UnitTestCase { + /** * @var RouteCollection */ diff --git a/tests/src/Unit/EventSubscriber/TemplateEventSubscriberTest.php b/tests/src/Unit/EventSubscriber/TemplateEventSubscriberTest.php index 6795bac..1b19c25 100644 --- a/tests/src/Unit/EventSubscriber/TemplateEventSubscriberTest.php +++ b/tests/src/Unit/EventSubscriber/TemplateEventSubscriberTest.php @@ -17,8 +17,8 @@ /** * @group controller_annotations */ -class TemplateEventSubscriberTest extends UnitTestCase -{ +class TemplateEventSubscriberTest extends UnitTestCase { + public function testOnKernelControllerWithoutTemplate() { $twig = m::mock(\Twig_Environment::class); $templateResolver = m::mock(TemplateResolver::class); diff --git a/tests/src/Unit/Fixture/FooControllerNullableParameter.php b/tests/src/Unit/Fixture/FooControllerNullableParameter.php index f030056..9aae13a 100644 --- a/tests/src/Unit/Fixture/FooControllerNullableParameter.php +++ b/tests/src/Unit/Fixture/FooControllerNullableParameter.php @@ -2,8 +2,8 @@ namespace Drupal\Tests\controller_annotations\Unit\Fixture; -class FooControllerNullableParameter -{ +class FooControllerNullableParameter { + public function requiredParamAction(\DateTime $param) { } diff --git a/tests/src/Unit/Fixture/FooControllerParamConverterAtClassAndMethod.php b/tests/src/Unit/Fixture/FooControllerParamConverterAtClassAndMethod.php index 2845ea0..df286cd 100644 --- a/tests/src/Unit/Fixture/FooControllerParamConverterAtClassAndMethod.php +++ b/tests/src/Unit/Fixture/FooControllerParamConverterAtClassAndMethod.php @@ -7,8 +7,8 @@ /** * @ParamConverter("test") */ -class FooControllerParamConverterAtClassAndMethod -{ +class FooControllerParamConverterAtClassAndMethod { + /** * @ParamConverter("test2") */ diff --git a/tests/src/Unit/Helper.php b/tests/src/Unit/Helper.php index 1f22bcb..5f599ea 100644 --- a/tests/src/Unit/Helper.php +++ b/tests/src/Unit/Helper.php @@ -2,8 +2,8 @@ namespace Drupal\Tests\controller_annotations\Unit; -class Helper -{ +class Helper { + public static function getProtectedMethod($class, $name) { $class = new \ReflectionClass($class); $method = $class->getMethod($name); diff --git a/tests/src/Unit/Request/ParamConverter/DateTimeParamConverterTest.php b/tests/src/Unit/Request/ParamConverter/DateTimeParamConverterTest.php index 4668f53..6f07302 100644 --- a/tests/src/Unit/Request/ParamConverter/DateTimeParamConverterTest.php +++ b/tests/src/Unit/Request/ParamConverter/DateTimeParamConverterTest.php @@ -10,8 +10,7 @@ /** * @group controller_annotations */ -class DateTimeParamConverterTest extends UnitTestCase -{ +class DateTimeParamConverterTest extends UnitTestCase { private $converter; diff --git a/tests/src/Unit/Request/ParamConverter/EntityParamConverterTest.php b/tests/src/Unit/Request/ParamConverter/EntityParamConverterTest.php index f48c20f..9bd202f 100644 --- a/tests/src/Unit/Request/ParamConverter/EntityParamConverterTest.php +++ b/tests/src/Unit/Request/ParamConverter/EntityParamConverterTest.php @@ -15,8 +15,8 @@ /** * @group controller_annotations */ -class EntityParamConverterTest extends UnitTestCase -{ +class EntityParamConverterTest extends UnitTestCase { + private function getEntityParamConverter() { $node = m::mock(Node::class); diff --git a/tests/src/Unit/Request/ParamConverter/ParamConverterManagerTest.php b/tests/src/Unit/Request/ParamConverter/ParamConverterManagerTest.php index 19232b9..be62b03 100644 --- a/tests/src/Unit/Request/ParamConverter/ParamConverterManagerTest.php +++ b/tests/src/Unit/Request/ParamConverter/ParamConverterManagerTest.php @@ -11,8 +11,8 @@ /** * @group controller_annotations */ -class ParamConverterManagerTest extends UnitTestCase -{ +class ParamConverterManagerTest extends UnitTestCase { + public function testPriorities() { $manager = new ParamConverterManager(); $this->assertEquals(array(), $manager->all()); diff --git a/tests/src/Unit/Routing/AnnotatedRouteControllerLoaderTest.php b/tests/src/Unit/Routing/AnnotatedRouteControllerLoaderTest.php index 7462fa9..8872299 100644 --- a/tests/src/Unit/Routing/AnnotatedRouteControllerLoaderTest.php +++ b/tests/src/Unit/Routing/AnnotatedRouteControllerLoaderTest.php @@ -13,8 +13,8 @@ /** * @group controller_annotations */ -class AnnotatedRouteControllerLoaderTest extends UnitTestCase -{ +class AnnotatedRouteControllerLoaderTest extends UnitTestCase { + public function testConfigureRoute() { $routeConfiguration = m::mock(\Drupal\controller_annotations\Configuration\Route::class); $routeConfiguration->shouldReceive('getService')->andReturn(false); diff --git a/tests/src/Unit/Templating/TemplateResolverTest.php b/tests/src/Unit/Templating/TemplateResolverTest.php index 35c8299..808303f 100644 --- a/tests/src/Unit/Templating/TemplateResolverTest.php +++ b/tests/src/Unit/Templating/TemplateResolverTest.php @@ -10,8 +10,8 @@ /** * @group controller_annotations */ -class TemplateResolverTest extends UnitTestCase -{ +class TemplateResolverTest extends UnitTestCase { + /** * @var TemplateResolver */ From 5187c4053ada995af8d7441479d17b7219be0e45 Mon Sep 17 00:00:00 2001 From: Andreas Hennings <andreas@dqxtech.net> Date: Sat, 11 Jan 2020 23:26:02 +0100 Subject: [PATCH 04/23] (CS) Put else/elseif on new line. --- src/Cache/DrupalCache.php | 3 ++- src/EventSubscriber/ControllerEventSubscriber.php | 15 ++++++++++----- src/EventSubscriber/RouteEventSubscriber.php | 6 ++++-- src/EventSubscriber/TemplateEventSubscriber.php | 9 ++++++--- .../ParamConverter/DateTimeParamConverter.php | 3 ++- src/Templating/TemplateResolver.php | 3 ++- 6 files changed, 26 insertions(+), 13 deletions(-) diff --git a/src/Cache/DrupalCache.php b/src/Cache/DrupalCache.php index 5c98dae..b5c4e13 100644 --- a/src/Cache/DrupalCache.php +++ b/src/Cache/DrupalCache.php @@ -43,7 +43,8 @@ protected function doContains($id) { protected function doSave($id, $data, $lifeTime = 0) { if ($lifeTime === 0) { $this->cache->set($id, $data); - } else { + } + else { $this->cache->set($id, $data, time() + $lifeTime); } diff --git a/src/EventSubscriber/ControllerEventSubscriber.php b/src/EventSubscriber/ControllerEventSubscriber.php index 6ce4ad6..0b8ab6a 100644 --- a/src/EventSubscriber/ControllerEventSubscriber.php +++ b/src/EventSubscriber/ControllerEventSubscriber.php @@ -77,9 +77,11 @@ protected function mergeConfigurations(array $classConfigurations, array $method foreach (array_merge(array_keys($classConfigurations), array_keys($methodConfigurations)) as $key) { if (!array_key_exists($key, $classConfigurations)) { $configurations[$key] = $methodConfigurations[$key]; - } elseif (!array_key_exists($key, $methodConfigurations)) { + } + elseif (!array_key_exists($key, $methodConfigurations)) { $configurations[$key] = $classConfigurations[$key]; - } else { + } + else { if (is_array($classConfigurations[$key])) { if (!is_array($methodConfigurations[$key])) { throw new \UnexpectedValueException( @@ -87,7 +89,8 @@ protected function mergeConfigurations(array $classConfigurations, array $method ); } $configurations[$key] = array_merge($classConfigurations[$key], $methodConfigurations[$key]); - } else { + } + else { // method configuration overrides class configuration $configurations[$key] = $methodConfigurations[$key]; } @@ -108,9 +111,11 @@ protected function getConfigurations(array $annotations) { if ($configuration instanceof ConfigurationInterface) { if ($configuration->allowArray()) { $configurations['_'.$configuration->getAliasName()][] = $configuration; - } elseif (!isset($configurations['_'.$configuration->getAliasName()])) { + } + elseif (!isset($configurations['_'.$configuration->getAliasName()])) { $configurations['_'.$configuration->getAliasName()] = $configuration; - } else { + } + else { throw new \LogicException( sprintf('Multiple "%s" annotations are not allowed.', $configuration->getAliasName()) ); diff --git a/src/EventSubscriber/RouteEventSubscriber.php b/src/EventSubscriber/RouteEventSubscriber.php index d840095..0a11e20 100644 --- a/src/EventSubscriber/RouteEventSubscriber.php +++ b/src/EventSubscriber/RouteEventSubscriber.php @@ -78,9 +78,11 @@ public static function getSubscribedEvents() { protected function getRoutePath(Route $route) { if ($route->hasOption('path')) { $path = $route->getOption('path'); - } elseif ($route->hasOption('module')) { + } + elseif ($route->hasOption('module')) { $path = sprintf('/%s/src/Controller', drupal_get_path('module', $route->getOption('module'))); - } else { + } + else { throw new \Exception( 'Either the "resource" or "module" option is required to load from annotations' ); diff --git a/src/EventSubscriber/TemplateEventSubscriber.php b/src/EventSubscriber/TemplateEventSubscriber.php index 098f5df..4894ed1 100644 --- a/src/EventSubscriber/TemplateEventSubscriber.php +++ b/src/EventSubscriber/TemplateEventSubscriber.php @@ -82,7 +82,8 @@ private function normalizeTemplate(Template $template) { get_class($template->getOwner()[0]), $template->getOwner()[1] ); - } else { + } + else { $templateFile = $this->resolver->normalize($template->getTemplate()); } @@ -104,7 +105,8 @@ private function setResponse(GetResponseForControllerResultEvent $event, Templat }; $event->setResponse(new StreamedResponse($callback)); - } else { + } + else { $event->setResponse(new Response($this->twig->render($template->getTemplate(), $parameters))); } } @@ -168,7 +170,8 @@ private function resolveParametersWithReflection(Request $request, array $argume && $argument->isDefaultValueAvailable() ? $argument->getDefaultValue() : $request->attributes->get($name); - } else { + } + else { $parameters[$argument] = $request->attributes->get($argument); } } diff --git a/src/Request/ParamConverter/DateTimeParamConverter.php b/src/Request/ParamConverter/DateTimeParamConverter.php index 2b15067..c6c6591 100644 --- a/src/Request/ParamConverter/DateTimeParamConverter.php +++ b/src/Request/ParamConverter/DateTimeParamConverter.php @@ -50,7 +50,8 @@ protected function getDateTime(ParamConverter $configuration, $value, $param) { if (isset($options['format'])) { $date = DateTime::createFromFormat($options['format'], $value); - } elseif (false !== strtotime($value)) { + } + elseif (false !== strtotime($value)) { $date = new DateTime($value); } diff --git a/src/Templating/TemplateResolver.php b/src/Templating/TemplateResolver.php index e68c179..0919c69 100644 --- a/src/Templating/TemplateResolver.php +++ b/src/Templating/TemplateResolver.php @@ -21,7 +21,8 @@ public function resolveByControllerAndAction(string $controllerClass, string $ac if (!empty($data)) { $module = $data[1]; $controller = $data[2]; - } else { + } + else { throw new \InvalidArgumentException( sprintf('Controller class "%s" not supported', $controllerClass) ); From 5dbf01ed7feed6a8e468a6da5c5636bf42e649ae Mon Sep 17 00:00:00 2001 From: Andreas Hennings <andreas@dqxtech.net> Date: Sat, 11 Jan 2020 21:51:33 +0100 Subject: [PATCH 05/23] (CS) Add blank line after last method in class. --- src/Cache/DrupalCache.php | 1 + src/Configuration/Cache.php | 1 + src/Configuration/ConfigurationAnnotation.php | 1 + src/Configuration/ConfigurationInterface.php | 1 + src/Configuration/Method.php | 1 + src/Configuration/ParamConverter.php | 1 + src/Configuration/Route.php | 1 + src/Configuration/RouteModifierClassInterface.php | 1 + src/Configuration/RouteModifierMethodInterface.php | 1 + src/Configuration/Security.php | 1 + src/Configuration/Template.php | 1 + src/Configuration/Title.php | 1 + src/EventSubscriber/ControllerEventSubscriber.php | 1 + src/EventSubscriber/HttpCacheEventSubscriber.php | 1 + src/EventSubscriber/ParamConverterEventSubscriber.php | 1 + src/EventSubscriber/RouteEventSubscriber.php | 1 + src/EventSubscriber/TemplateEventSubscriber.php | 1 + src/Request/ParamConverter/DateTimeParamConverter.php | 1 + src/Request/ParamConverter/EntityParamConverter.php | 1 + src/Request/ParamConverter/ParamConverterInterface.php | 1 + src/Request/ParamConverter/ParamConverterManager.php | 1 + src/Routing/AnnotatedRouteControllerLoader.php | 1 + src/Templating/TemplateResolver.php | 1 + .../src/Controller/AdminController.php | 1 + .../src/Controller/BasicController.php | 1 + .../src/Controller/InvokeController.php | 1 + .../src/Controller/MethodController.php | 1 + .../src/Controller/ParamConverterController.php | 1 + .../src/Controller/PrefixedRouteController.php | 1 + .../src/Controller/SecurityController.php | 1 + .../src/Controller/ServiceController.php | 1 + .../src/Controller/TemplateController.php | 1 + .../src/Controller/TitleController.php | 1 + .../controller_annotations_test/src/Security/Custom.php | 1 + .../modules/controller_annotations_test/src/Title/Custom.php | 1 + tests/src/Kernel/AnnotationsTest.php | 1 + tests/src/Kernel/DrupalTestKernel.php | 1 + tests/src/Kernel/KernelTestBase.php | 1 + tests/src/Kernel/TestUserSession.php | 1 + tests/src/Unit/Cache/DrupalCacheTest.php | 1 + tests/src/Unit/Configuration/CacheTest.php | 1 + tests/src/Unit/Configuration/MethodTest.php | 1 + tests/src/Unit/Configuration/RouteTest.php | 1 + tests/src/Unit/Configuration/SecurityTest.php | 1 + tests/src/Unit/Configuration/TitleTest.php | 1 + .../Unit/EventSubscriber/ControllerEventSubscriberTest.php | 2 ++ tests/src/Unit/EventSubscriber/HttpCacheListenerTest.php | 2 ++ .../EventSubscriber/ParamConverterEventSubscriberTest.php | 4 ++++ tests/src/Unit/EventSubscriber/RouteEventSubscriberTest.php | 1 + .../src/Unit/EventSubscriber/TemplateEventSubscriberTest.php | 1 + tests/src/Unit/Fixture/FooControllerNullableParameter.php | 1 + .../Fixture/FooControllerParamConverterAtClassAndMethod.php | 1 + tests/src/Unit/Helper.php | 1 + .../Request/ParamConverter/DateTimeParamConverterTest.php | 1 + .../Unit/Request/ParamConverter/EntityParamConverterTest.php | 1 + .../Unit/Request/ParamConverter/ParamConverterManagerTest.php | 1 + tests/src/Unit/Routing/AnnotatedRouteControllerLoaderTest.php | 1 + tests/src/Unit/Templating/TemplateResolverTest.php | 1 + 58 files changed, 63 insertions(+) diff --git a/src/Cache/DrupalCache.php b/src/Cache/DrupalCache.php index b5c4e13..d54095f 100644 --- a/src/Cache/DrupalCache.php +++ b/src/Cache/DrupalCache.php @@ -75,4 +75,5 @@ protected function doFlush() { protected function doGetStats() { return; } + } diff --git a/src/Configuration/Cache.php b/src/Configuration/Cache.php index b722d3d..e79a501 100644 --- a/src/Configuration/Cache.php +++ b/src/Configuration/Cache.php @@ -216,4 +216,5 @@ public function getAliasName() { public function allowArray() { return false; } + } diff --git a/src/Configuration/ConfigurationAnnotation.php b/src/Configuration/ConfigurationAnnotation.php index ecd281b..3432e22 100644 --- a/src/Configuration/ConfigurationAnnotation.php +++ b/src/Configuration/ConfigurationAnnotation.php @@ -18,4 +18,5 @@ public function __construct(array $values) { $this->$name($v); } } + } diff --git a/src/Configuration/ConfigurationInterface.php b/src/Configuration/ConfigurationInterface.php index a648cc8..4e5097d 100644 --- a/src/Configuration/ConfigurationInterface.php +++ b/src/Configuration/ConfigurationInterface.php @@ -22,4 +22,5 @@ public function getAliasName(); * @return bool */ public function allowArray(); + } diff --git a/src/Configuration/Method.php b/src/Configuration/Method.php index eeb3c51..5f41fb9 100644 --- a/src/Configuration/Method.php +++ b/src/Configuration/Method.php @@ -92,4 +92,5 @@ public function modifyRouteMethod(RoutingRoute $route, \ReflectionClass $class, protected function modifyRoute(RoutingRoute $route) { $route->setMethods($this->getMethods()); } + } diff --git a/src/Configuration/ParamConverter.php b/src/Configuration/ParamConverter.php index affb0ca..07a2ef5 100644 --- a/src/Configuration/ParamConverter.php +++ b/src/Configuration/ParamConverter.php @@ -165,4 +165,5 @@ public function getAliasName() { public function allowArray() { return true; } + } diff --git a/src/Configuration/Route.php b/src/Configuration/Route.php index 42bdfcd..e09d155 100644 --- a/src/Configuration/Route.php +++ b/src/Configuration/Route.php @@ -95,4 +95,5 @@ protected function modifyRoute(RoutingRoute $route, \ReflectionClass $class, \Re $route->setOption('_admin_route', true); } } + } diff --git a/src/Configuration/RouteModifierClassInterface.php b/src/Configuration/RouteModifierClassInterface.php index d0cf6d7..d25deaa 100644 --- a/src/Configuration/RouteModifierClassInterface.php +++ b/src/Configuration/RouteModifierClassInterface.php @@ -12,4 +12,5 @@ interface RouteModifierClassInterface extends RouteModifierInterface { * @param \ReflectionMethod $method */ public function modifyRouteClass(RoutingRoute $route, \ReflectionClass $class, \ReflectionMethod $method); + } diff --git a/src/Configuration/RouteModifierMethodInterface.php b/src/Configuration/RouteModifierMethodInterface.php index c87c775..1502555 100644 --- a/src/Configuration/RouteModifierMethodInterface.php +++ b/src/Configuration/RouteModifierMethodInterface.php @@ -12,4 +12,5 @@ interface RouteModifierMethodInterface extends RouteModifierInterface { * @param \ReflectionMethod $method */ public function modifyRouteMethod(RoutingRoute $route, \ReflectionClass $class, \ReflectionMethod $method); + } diff --git a/src/Configuration/Security.php b/src/Configuration/Security.php index 7458b60..f4ec4f6 100644 --- a/src/Configuration/Security.php +++ b/src/Configuration/Security.php @@ -231,4 +231,5 @@ protected function setCustomSecurity(RoutingRoute $route, \ReflectionClass $clas $route->setRequirement('_custom_access', $this->getCustom()); } } + } diff --git a/src/Configuration/Template.php b/src/Configuration/Template.php index 92d2488..4fbb08c 100644 --- a/src/Configuration/Template.php +++ b/src/Configuration/Template.php @@ -131,4 +131,5 @@ public function setOwner(array $owner) { public function getOwner() { return $this->owner; } + } diff --git a/src/Configuration/Title.php b/src/Configuration/Title.php index a9a3540..af556fb 100644 --- a/src/Configuration/Title.php +++ b/src/Configuration/Title.php @@ -182,4 +182,5 @@ protected function registerCallback(RoutingRoute $route, \ReflectionClass $class $route->setDefault('_title_callback', $this->getCallback()); } } + } diff --git a/src/EventSubscriber/ControllerEventSubscriber.php b/src/EventSubscriber/ControllerEventSubscriber.php index 0b8ab6a..f4021b7 100644 --- a/src/EventSubscriber/ControllerEventSubscriber.php +++ b/src/EventSubscriber/ControllerEventSubscriber.php @@ -136,4 +136,5 @@ public static function getSubscribedEvents() { ], ]; } + } diff --git a/src/EventSubscriber/HttpCacheEventSubscriber.php b/src/EventSubscriber/HttpCacheEventSubscriber.php index c0e9729..4fd13c4 100644 --- a/src/EventSubscriber/HttpCacheEventSubscriber.php +++ b/src/EventSubscriber/HttpCacheEventSubscriber.php @@ -273,4 +273,5 @@ public static function getSubscribedEvents() { ], ]; } + } diff --git a/src/EventSubscriber/ParamConverterEventSubscriber.php b/src/EventSubscriber/ParamConverterEventSubscriber.php index c9b4d01..a10e199 100644 --- a/src/EventSubscriber/ParamConverterEventSubscriber.php +++ b/src/EventSubscriber/ParamConverterEventSubscriber.php @@ -128,4 +128,5 @@ public static function getSubscribedEvents() { ], ]; } + } diff --git a/src/EventSubscriber/RouteEventSubscriber.php b/src/EventSubscriber/RouteEventSubscriber.php index 0a11e20..285c5f5 100644 --- a/src/EventSubscriber/RouteEventSubscriber.php +++ b/src/EventSubscriber/RouteEventSubscriber.php @@ -90,4 +90,5 @@ protected function getRoutePath(Route $route) { return $path; } + } diff --git a/src/EventSubscriber/TemplateEventSubscriber.php b/src/EventSubscriber/TemplateEventSubscriber.php index 4894ed1..450db6f 100644 --- a/src/EventSubscriber/TemplateEventSubscriber.php +++ b/src/EventSubscriber/TemplateEventSubscriber.php @@ -188,4 +188,5 @@ public static function getSubscribedEvents() { KernelEvents::VIEW => ['onKernelView', 10], ]; } + } diff --git a/src/Request/ParamConverter/DateTimeParamConverter.php b/src/Request/ParamConverter/DateTimeParamConverter.php index c6c6591..3c42d2e 100644 --- a/src/Request/ParamConverter/DateTimeParamConverter.php +++ b/src/Request/ParamConverter/DateTimeParamConverter.php @@ -70,4 +70,5 @@ protected function getDateTime(ParamConverter $configuration, $value, $param) { public function supports(ParamConverter $configuration) { return \DateTime::class === $configuration->getClass(); } + } diff --git a/src/Request/ParamConverter/EntityParamConverter.php b/src/Request/ParamConverter/EntityParamConverter.php index 5dddb37..e57fd90 100644 --- a/src/Request/ParamConverter/EntityParamConverter.php +++ b/src/Request/ParamConverter/EntityParamConverter.php @@ -105,4 +105,5 @@ public function supports(ParamConverter $configuration) { ] ); } + } diff --git a/src/Request/ParamConverter/ParamConverterInterface.php b/src/Request/ParamConverter/ParamConverterInterface.php index e433cc8..c007dbf 100644 --- a/src/Request/ParamConverter/ParamConverterInterface.php +++ b/src/Request/ParamConverter/ParamConverterInterface.php @@ -31,4 +31,5 @@ public function apply(Request $request, ParamConverter $configuration); * @return bool True if the object is supported, else false */ public function supports(ParamConverter $configuration); + } diff --git a/src/Request/ParamConverter/ParamConverterManager.php b/src/Request/ParamConverter/ParamConverterManager.php index e50065e..1f960de 100644 --- a/src/Request/ParamConverter/ParamConverterManager.php +++ b/src/Request/ParamConverter/ParamConverterManager.php @@ -142,4 +142,5 @@ public function all() { return $converters; } + } diff --git a/src/Routing/AnnotatedRouteControllerLoader.php b/src/Routing/AnnotatedRouteControllerLoader.php index 5460dd7..528185e 100644 --- a/src/Routing/AnnotatedRouteControllerLoader.php +++ b/src/Routing/AnnotatedRouteControllerLoader.php @@ -87,4 +87,5 @@ protected function getControllerName(\ReflectionClass $class, \ReflectionMethod return sprintf('%s::%s', $class->getName(), $method->getName()); } + } diff --git a/src/Templating/TemplateResolver.php b/src/Templating/TemplateResolver.php index 0919c69..d6170c0 100644 --- a/src/Templating/TemplateResolver.php +++ b/src/Templating/TemplateResolver.php @@ -94,4 +94,5 @@ private function format(string $module, string $controller, string $action = nul private function normalizeString(string $value): string { return str_replace('\\', '-', mb_strtolower($value)); } + } diff --git a/tests/modules/controller_annotations_test/src/Controller/AdminController.php b/tests/modules/controller_annotations_test/src/Controller/AdminController.php index 48fd285..8f43803 100644 --- a/tests/modules/controller_annotations_test/src/Controller/AdminController.php +++ b/tests/modules/controller_annotations_test/src/Controller/AdminController.php @@ -26,4 +26,5 @@ public function adminAction() { public function normalAction() { return []; } + } diff --git a/tests/modules/controller_annotations_test/src/Controller/BasicController.php b/tests/modules/controller_annotations_test/src/Controller/BasicController.php index 32ac58a..35f392c 100644 --- a/tests/modules/controller_annotations_test/src/Controller/BasicController.php +++ b/tests/modules/controller_annotations_test/src/Controller/BasicController.php @@ -18,4 +18,5 @@ class BasicController extends ControllerBase { public function basicAction() { return new Response('BasicController::basicAction'); } + } diff --git a/tests/modules/controller_annotations_test/src/Controller/InvokeController.php b/tests/modules/controller_annotations_test/src/Controller/InvokeController.php index a9824fb..95680f9 100644 --- a/tests/modules/controller_annotations_test/src/Controller/InvokeController.php +++ b/tests/modules/controller_annotations_test/src/Controller/InvokeController.php @@ -15,4 +15,5 @@ class InvokeController { public function __invoke() { return new Response('InvokeController::__invoke'); } + } diff --git a/tests/modules/controller_annotations_test/src/Controller/MethodController.php b/tests/modules/controller_annotations_test/src/Controller/MethodController.php index ba77101..46d9494 100644 --- a/tests/modules/controller_annotations_test/src/Controller/MethodController.php +++ b/tests/modules/controller_annotations_test/src/Controller/MethodController.php @@ -36,4 +36,5 @@ public function postAction() { public function getAndPostAction() { return new Response('ClassRouteController::getAndPostAction'); } + } diff --git a/tests/modules/controller_annotations_test/src/Controller/ParamConverterController.php b/tests/modules/controller_annotations_test/src/Controller/ParamConverterController.php index 981e798..3fc2f9d 100644 --- a/tests/modules/controller_annotations_test/src/Controller/ParamConverterController.php +++ b/tests/modules/controller_annotations_test/src/Controller/ParamConverterController.php @@ -51,4 +51,5 @@ public function optionalDateAction(\DateTime $start = null) { } return new Response($start->format('Y-m-d')); } + } diff --git a/tests/modules/controller_annotations_test/src/Controller/PrefixedRouteController.php b/tests/modules/controller_annotations_test/src/Controller/PrefixedRouteController.php index 5c07d16..134267f 100644 --- a/tests/modules/controller_annotations_test/src/Controller/PrefixedRouteController.php +++ b/tests/modules/controller_annotations_test/src/Controller/PrefixedRouteController.php @@ -27,4 +27,5 @@ public function emptyRouteAction() { public function namedRouteAction() { return new Response('PrefixedBasicController::namedRouteAction'); } + } diff --git a/tests/modules/controller_annotations_test/src/Controller/SecurityController.php b/tests/modules/controller_annotations_test/src/Controller/SecurityController.php index 1f88737..31945fc 100644 --- a/tests/modules/controller_annotations_test/src/Controller/SecurityController.php +++ b/tests/modules/controller_annotations_test/src/Controller/SecurityController.php @@ -80,4 +80,5 @@ public function csrfAction() { public function access(AccountInterface $account) { return AccessResult::allowedIf($account->id() === 1337); } + } diff --git a/tests/modules/controller_annotations_test/src/Controller/ServiceController.php b/tests/modules/controller_annotations_test/src/Controller/ServiceController.php index b837239..933c451 100644 --- a/tests/modules/controller_annotations_test/src/Controller/ServiceController.php +++ b/tests/modules/controller_annotations_test/src/Controller/ServiceController.php @@ -18,4 +18,5 @@ class ServiceController { public function getAction() { return new Response('ServiceController::getAction'); } + } diff --git a/tests/modules/controller_annotations_test/src/Controller/TemplateController.php b/tests/modules/controller_annotations_test/src/Controller/TemplateController.php index a6ba16b..62f38d5 100644 --- a/tests/modules/controller_annotations_test/src/Controller/TemplateController.php +++ b/tests/modules/controller_annotations_test/src/Controller/TemplateController.php @@ -68,4 +68,5 @@ public function streamableAction() { */ public function varsAction($name = 'World') { } + } diff --git a/tests/modules/controller_annotations_test/src/Controller/TitleController.php b/tests/modules/controller_annotations_test/src/Controller/TitleController.php index f332fc3..fc771bf 100644 --- a/tests/modules/controller_annotations_test/src/Controller/TitleController.php +++ b/tests/modules/controller_annotations_test/src/Controller/TitleController.php @@ -54,4 +54,5 @@ public function callbackInlineAction() { public function title() { return 'Hello Callback Inline'; } + } diff --git a/tests/modules/controller_annotations_test/src/Security/Custom.php b/tests/modules/controller_annotations_test/src/Security/Custom.php index ffff0ac..892c1a8 100644 --- a/tests/modules/controller_annotations_test/src/Security/Custom.php +++ b/tests/modules/controller_annotations_test/src/Security/Custom.php @@ -14,4 +14,5 @@ class Custom { public function access(AccountInterface $account) { return AccessResult::allowedIf($account->id() === 1337); } + } diff --git a/tests/modules/controller_annotations_test/src/Title/Custom.php b/tests/modules/controller_annotations_test/src/Title/Custom.php index 505bc18..df7dab0 100644 --- a/tests/modules/controller_annotations_test/src/Title/Custom.php +++ b/tests/modules/controller_annotations_test/src/Title/Custom.php @@ -10,4 +10,5 @@ class Custom { public function title() { return 'Hello Callback'; } + } diff --git a/tests/src/Kernel/AnnotationsTest.php b/tests/src/Kernel/AnnotationsTest.php index 97f345c..b8c3d41 100644 --- a/tests/src/Kernel/AnnotationsTest.php +++ b/tests/src/Kernel/AnnotationsTest.php @@ -146,4 +146,5 @@ public function testParamConverter() { $this->assertResponseContents(Request::create('/test/param-converter/date-optional/03-04-1985'), '1985-04-03'); $this->assertResponseContents(Request::create('/test/param-converter/date-optional'), 'empty'); } + } diff --git a/tests/src/Kernel/DrupalTestKernel.php b/tests/src/Kernel/DrupalTestKernel.php index 5be1df5..bba03b4 100644 --- a/tests/src/Kernel/DrupalTestKernel.php +++ b/tests/src/Kernel/DrupalTestKernel.php @@ -25,4 +25,5 @@ protected function initializeSettings(Request $request) { parent::initializeSettings($request); new Settings($settings); } + } diff --git a/tests/src/Kernel/KernelTestBase.php b/tests/src/Kernel/KernelTestBase.php index 57eca7c..cb41624 100644 --- a/tests/src/Kernel/KernelTestBase.php +++ b/tests/src/Kernel/KernelTestBase.php @@ -137,4 +137,5 @@ protected function setAdministratorAccount() { protected function setAccount(AccountInterface $account) { $this->kernel->getContainer()->get('current_user')->setAccount($account); } + } diff --git a/tests/src/Kernel/TestUserSession.php b/tests/src/Kernel/TestUserSession.php index 4e97ebe..c21b00d 100644 --- a/tests/src/Kernel/TestUserSession.php +++ b/tests/src/Kernel/TestUserSession.php @@ -22,4 +22,5 @@ public function hasPermission($permission) { return in_array($permission, $this->permissions); } + } diff --git a/tests/src/Unit/Cache/DrupalCacheTest.php b/tests/src/Unit/Cache/DrupalCacheTest.php index a85d2ea..3beafe5 100644 --- a/tests/src/Unit/Cache/DrupalCacheTest.php +++ b/tests/src/Unit/Cache/DrupalCacheTest.php @@ -93,4 +93,5 @@ protected function tearDown() { parent::tearDown(); } + } diff --git a/tests/src/Unit/Configuration/CacheTest.php b/tests/src/Unit/Configuration/CacheTest.php index c0099f0..107de7a 100644 --- a/tests/src/Unit/Configuration/CacheTest.php +++ b/tests/src/Unit/Configuration/CacheTest.php @@ -51,4 +51,5 @@ public function testAllowArray() { $this->assertFalse($cache->allowArray()); } + } diff --git a/tests/src/Unit/Configuration/MethodTest.php b/tests/src/Unit/Configuration/MethodTest.php index f56085e..6c24253 100644 --- a/tests/src/Unit/Configuration/MethodTest.php +++ b/tests/src/Unit/Configuration/MethodTest.php @@ -51,4 +51,5 @@ public function testModify() { m::close(); } + } diff --git a/tests/src/Unit/Configuration/RouteTest.php b/tests/src/Unit/Configuration/RouteTest.php index 52a62a7..9b24dc5 100644 --- a/tests/src/Unit/Configuration/RouteTest.php +++ b/tests/src/Unit/Configuration/RouteTest.php @@ -57,4 +57,5 @@ public function testUnknownProperty() { $this->setExpectedException(\BadMethodCallException::class); new RouteConfiguration(['foo' => 'bar']); } + } diff --git a/tests/src/Unit/Configuration/SecurityTest.php b/tests/src/Unit/Configuration/SecurityTest.php index 7eb5a9d..84deaff 100644 --- a/tests/src/Unit/Configuration/SecurityTest.php +++ b/tests/src/Unit/Configuration/SecurityTest.php @@ -50,4 +50,5 @@ public function testModifyRouteMethodInlineAccess() { m::close(); } + } diff --git a/tests/src/Unit/Configuration/TitleTest.php b/tests/src/Unit/Configuration/TitleTest.php index b3ca7b4..cc3343c 100644 --- a/tests/src/Unit/Configuration/TitleTest.php +++ b/tests/src/Unit/Configuration/TitleTest.php @@ -51,4 +51,5 @@ public function testUnknownProperty() { $this->setExpectedException(\RuntimeException::class); new Title(['foo' => 'bar']); } + } diff --git a/tests/src/Unit/EventSubscriber/ControllerEventSubscriberTest.php b/tests/src/Unit/EventSubscriber/ControllerEventSubscriberTest.php index 36beca6..7c1f91b 100644 --- a/tests/src/Unit/EventSubscriber/ControllerEventSubscriberTest.php +++ b/tests/src/Unit/EventSubscriber/ControllerEventSubscriberTest.php @@ -108,10 +108,12 @@ public function testMergeConfigurationsMismatch() { $eventSubscriber = new ControllerEventSubscriber($reader); $method->invokeArgs($eventSubscriber, [$classConfigurations, $methodConfigurations]); } + } class ControllerInvokableController { public function __invoke() { } + } diff --git a/tests/src/Unit/EventSubscriber/HttpCacheListenerTest.php b/tests/src/Unit/EventSubscriber/HttpCacheListenerTest.php index 6eba28e..f121346 100644 --- a/tests/src/Unit/EventSubscriber/HttpCacheListenerTest.php +++ b/tests/src/Unit/EventSubscriber/HttpCacheListenerTest.php @@ -227,6 +227,7 @@ private function createEventMock(Request $request, Response $response) { private function getKernel() { return $this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernelInterface')->getMock(); } + } class TestEntity { @@ -238,4 +239,5 @@ public function getDate() { public function getId() { return '12345'; } + } diff --git a/tests/src/Unit/EventSubscriber/ParamConverterEventSubscriberTest.php b/tests/src/Unit/EventSubscriber/ParamConverterEventSubscriberTest.php index 037ec9e..ca1b37f 100644 --- a/tests/src/Unit/EventSubscriber/ParamConverterEventSubscriberTest.php +++ b/tests/src/Unit/EventSubscriber/ParamConverterEventSubscriberTest.php @@ -168,6 +168,7 @@ public function testPredefinedConfigurations() { $this->assertNull(m::close()); } + } class ParamConverterTestController { @@ -177,16 +178,19 @@ public function noArgAction(Request $request) { public function dateAction(\DateTime $date) { } + } class ParamConverterInvokableNoArgController { public function __invoke(Request $request) { } + } class ParamConverterInvokableController { public function __invoke(\DateTime $date) { } + } diff --git a/tests/src/Unit/EventSubscriber/RouteEventSubscriberTest.php b/tests/src/Unit/EventSubscriber/RouteEventSubscriberTest.php index fbad8e1..348e888 100644 --- a/tests/src/Unit/EventSubscriber/RouteEventSubscriberTest.php +++ b/tests/src/Unit/EventSubscriber/RouteEventSubscriberTest.php @@ -113,4 +113,5 @@ public function testOnRoutesWithoutRequiredOptions() { $this->triggerOnRoutes(); } + } diff --git a/tests/src/Unit/EventSubscriber/TemplateEventSubscriberTest.php b/tests/src/Unit/EventSubscriber/TemplateEventSubscriberTest.php index 1b19c25..f344ef5 100644 --- a/tests/src/Unit/EventSubscriber/TemplateEventSubscriberTest.php +++ b/tests/src/Unit/EventSubscriber/TemplateEventSubscriberTest.php @@ -179,4 +179,5 @@ public function testOnKernelViewStreamed() { public function tearDown() { m::close(); } + } diff --git a/tests/src/Unit/Fixture/FooControllerNullableParameter.php b/tests/src/Unit/Fixture/FooControllerNullableParameter.php index 9aae13a..4f6d7a4 100644 --- a/tests/src/Unit/Fixture/FooControllerNullableParameter.php +++ b/tests/src/Unit/Fixture/FooControllerNullableParameter.php @@ -12,4 +12,5 @@ public function defaultParamAction(\DateTime $param = null) { public function nullableParamAction(?\DateTime $param) { } + } diff --git a/tests/src/Unit/Fixture/FooControllerParamConverterAtClassAndMethod.php b/tests/src/Unit/Fixture/FooControllerParamConverterAtClassAndMethod.php index df286cd..0c8ff33 100644 --- a/tests/src/Unit/Fixture/FooControllerParamConverterAtClassAndMethod.php +++ b/tests/src/Unit/Fixture/FooControllerParamConverterAtClassAndMethod.php @@ -14,4 +14,5 @@ class FooControllerParamConverterAtClassAndMethod { */ public function barAction($test, $test2) { } + } diff --git a/tests/src/Unit/Helper.php b/tests/src/Unit/Helper.php index 5f599ea..01b1497 100644 --- a/tests/src/Unit/Helper.php +++ b/tests/src/Unit/Helper.php @@ -11,4 +11,5 @@ public static function getProtectedMethod($class, $name) { return $method; } + } diff --git a/tests/src/Unit/Request/ParamConverter/DateTimeParamConverterTest.php b/tests/src/Unit/Request/ParamConverter/DateTimeParamConverterTest.php index 6f07302..7f575ac 100644 --- a/tests/src/Unit/Request/ParamConverter/DateTimeParamConverterTest.php +++ b/tests/src/Unit/Request/ParamConverter/DateTimeParamConverterTest.php @@ -114,4 +114,5 @@ public function createConfiguration($class = null, $name = null) { return $config; } + } diff --git a/tests/src/Unit/Request/ParamConverter/EntityParamConverterTest.php b/tests/src/Unit/Request/ParamConverter/EntityParamConverterTest.php index 9bd202f..1b69a4f 100644 --- a/tests/src/Unit/Request/ParamConverter/EntityParamConverterTest.php +++ b/tests/src/Unit/Request/ParamConverter/EntityParamConverterTest.php @@ -245,4 +245,5 @@ public function testOptionalEmptyAttribute() { public function tearDown() { m::close(); } + } diff --git a/tests/src/Unit/Request/ParamConverter/ParamConverterManagerTest.php b/tests/src/Unit/Request/ParamConverter/ParamConverterManagerTest.php index be62b03..049e638 100644 --- a/tests/src/Unit/Request/ParamConverter/ParamConverterManagerTest.php +++ b/tests/src/Unit/Request/ParamConverter/ParamConverterManagerTest.php @@ -185,4 +185,5 @@ public function testApplyWithoutArray() { protected function createParamConverterMock() { return $this->getMockBuilder(ParamConverterInterface::class)->getMock(); } + } diff --git a/tests/src/Unit/Routing/AnnotatedRouteControllerLoaderTest.php b/tests/src/Unit/Routing/AnnotatedRouteControllerLoaderTest.php index 8872299..0e6a897 100644 --- a/tests/src/Unit/Routing/AnnotatedRouteControllerLoaderTest.php +++ b/tests/src/Unit/Routing/AnnotatedRouteControllerLoaderTest.php @@ -52,4 +52,5 @@ public function testConfigureRoute() { m::close(); } + } diff --git a/tests/src/Unit/Templating/TemplateResolverTest.php b/tests/src/Unit/Templating/TemplateResolverTest.php index 808303f..6ec34f8 100644 --- a/tests/src/Unit/Templating/TemplateResolverTest.php +++ b/tests/src/Unit/Templating/TemplateResolverTest.php @@ -97,4 +97,5 @@ public function testResolveByControllerAndActionWithInvalidController() { $this->setExpectedException(\InvalidArgumentException::class); $this->templateResolver->resolveByControllerAndAction('Foo', 'fooAction'); } + } From 0162911cbe5b4de35f11ef776e40f0b5866b7639 Mon Sep 17 00:00:00 2001 From: Andreas Hennings <andreas@dqxtech.net> Date: Sat, 11 Jan 2020 21:52:17 +0100 Subject: [PATCH 06/23] (CS) Add blank lines around function. --- tests/src/polyfill.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/src/polyfill.php b/tests/src/polyfill.php index ff28eb8..bded969 100644 --- a/tests/src/polyfill.php +++ b/tests/src/polyfill.php @@ -1,6 +1,7 @@ <?php if (!function_exists('drupal_get_path')) { + function drupal_get_path($type, $name) { switch ($type) { case 'module': @@ -11,4 +12,5 @@ function drupal_get_path($type, $name) { sprintf('Type "%s" not implemented by this polyfill method', $type) ); } + } From bc07e6d5c662597a66e36cdb8b9be4500d01d3b9 Mon Sep 17 00:00:00 2001 From: Andreas Hennings <andreas@dqxtech.net> Date: Sat, 11 Jan 2020 21:54:47 +0100 Subject: [PATCH 07/23] (CS) Constants TRUE, FALSE, NULL in uppercase. --- src/Cache/DrupalCache.php | 10 ++++----- src/Configuration/Cache.php | 6 ++--- src/Configuration/Method.php | 2 +- src/Configuration/ParamConverter.php | 4 ++-- src/Configuration/Route.php | 6 ++--- src/Configuration/Security.php | 4 ++-- src/Configuration/Template.php | 4 ++-- src/Configuration/Title.php | 4 ++-- .../HttpCacheEventSubscriber.php | 18 +++++++-------- .../ParamConverterEventSubscriber.php | 4 ++-- .../TemplateEventSubscriber.php | 2 +- .../ParamConverter/DateTimeParamConverter.php | 8 +++---- .../ParamConverter/EntityParamConverter.php | 8 +++---- .../ParamConverter/ParamConverterManager.php | 6 ++--- src/Templating/TemplateResolver.php | 2 +- .../Controller/ParamConverterController.php | 2 +- tests/src/Kernel/AnnotationsTest.php | 2 +- tests/src/Kernel/KernelTestBase.php | 4 ++-- tests/src/Kernel/TestUserSession.php | 2 +- tests/src/Unit/Cache/DrupalCacheTest.php | 2 +- tests/src/Unit/Configuration/CacheTest.php | 4 ++-- tests/src/Unit/Configuration/RouteTest.php | 4 ++-- tests/src/Unit/Configuration/SecurityTest.php | 8 +++---- tests/src/Unit/Configuration/TitleTest.php | 8 +++---- .../ControllerEventSubscriberTest.php | 4 ++-- .../EventSubscriber/HttpCacheListenerTest.php | 18 +++++++-------- .../ParamConverterEventSubscriberTest.php | 22 +++++++++---------- .../TemplateEventSubscriberTest.php | 14 ++++++------ .../FooControllerNullableParameter.php | 2 +- tests/src/Unit/Helper.php | 2 +- .../DateTimeParamConverterTest.php | 10 ++++----- .../EntityParamConverterTest.php | 16 +++++++------- .../ParamConverterManagerTest.php | 12 +++++----- .../AnnotatedRouteControllerLoaderTest.php | 8 +++---- 34 files changed, 116 insertions(+), 116 deletions(-) diff --git a/src/Cache/DrupalCache.php b/src/Cache/DrupalCache.php index d54095f..ab1ac21 100644 --- a/src/Cache/DrupalCache.php +++ b/src/Cache/DrupalCache.php @@ -27,14 +27,14 @@ protected function doFetch($id) { return $cache->data; } - return false; + return FALSE; } /** * @inheritdoc */ protected function doContains($id) { - return $this->doFetch($id) !== false; + return $this->doFetch($id) !== FALSE; } /** @@ -48,7 +48,7 @@ protected function doSave($id, $data, $lifeTime = 0) { $this->cache->set($id, $data, time() + $lifeTime); } - return true; + return TRUE; } /** @@ -57,7 +57,7 @@ protected function doSave($id, $data, $lifeTime = 0) { protected function doDelete($id) { $this->cache->delete($id); - return true; + return TRUE; } /** @@ -66,7 +66,7 @@ protected function doDelete($id) { protected function doFlush() { $this->cache->deleteAll(); - return true; + return TRUE; } /** diff --git a/src/Configuration/Cache.php b/src/Configuration/Cache.php index e79a501..98134a0 100644 --- a/src/Configuration/Cache.php +++ b/src/Configuration/Cache.php @@ -120,7 +120,7 @@ public function getSMaxAge() { * @return bool */ public function isPublic() { - return $this->public === true; + return $this->public === TRUE; } /** @@ -129,7 +129,7 @@ public function isPublic() { * @return bool */ public function isPrivate() { - return $this->public === false; + return $this->public === FALSE; } /** @@ -214,7 +214,7 @@ public function getAliasName() { * @see ConfigurationInterface */ public function allowArray() { - return false; + return FALSE; } } diff --git a/src/Configuration/Method.php b/src/Configuration/Method.php index 5f41fb9..18fed7b 100644 --- a/src/Configuration/Method.php +++ b/src/Configuration/Method.php @@ -62,7 +62,7 @@ public function getAliasName() { * @see ConfigurationInterface */ public function allowArray() { - return false; + return FALSE; } /** diff --git a/src/Configuration/ParamConverter.php b/src/Configuration/ParamConverter.php index 07a2ef5..e9bd53b 100644 --- a/src/Configuration/ParamConverter.php +++ b/src/Configuration/ParamConverter.php @@ -36,7 +36,7 @@ class ParamConverter extends ConfigurationAnnotation { * * @var bool */ - protected $optional = false; + protected $optional = FALSE; /** * Use explicitly named converter instead of iterating by priorities. @@ -163,7 +163,7 @@ public function getAliasName() { * @see ConfigurationInterface */ public function allowArray() { - return true; + return TRUE; } } diff --git a/src/Configuration/Route.php b/src/Configuration/Route.php index e09d155..6aac9ec 100644 --- a/src/Configuration/Route.php +++ b/src/Configuration/Route.php @@ -25,7 +25,7 @@ class Route extends BaseRoute implements RouteModifierMethodInterface, RouteModi */ public function setService($service) { // avoid a BC notice in case of @Route(service="") with sf ^2.7 - if (null === $this->getPath()) { + if (NULL === $this->getPath()) { $this->setPath(''); } $this->service = $service; @@ -60,7 +60,7 @@ public function setAdmin($admin) { * @see ConfigurationInterface */ public function allowArray() { - return true; + return TRUE; } /** @@ -92,7 +92,7 @@ public function modifyRouteMethod(RoutingRoute $route, \ReflectionClass $class, */ protected function modifyRoute(RoutingRoute $route, \ReflectionClass $class, \ReflectionMethod $method) { if ($this->isAdmin()) { - $route->setOption('_admin_route', true); + $route->setOption('_admin_route', TRUE); } } diff --git a/src/Configuration/Security.php b/src/Configuration/Security.php index f4ec4f6..355d85f 100644 --- a/src/Configuration/Security.php +++ b/src/Configuration/Security.php @@ -174,7 +174,7 @@ public function getAliasName() { } public function allowArray() { - return false; + return FALSE; } /** @@ -225,7 +225,7 @@ protected function modifyRoute(RoutingRoute $route, \ReflectionClass $class) { */ protected function setCustomSecurity(RoutingRoute $route, \ReflectionClass $class) { if ($this->hasCustom()) { - if (strpos($this->getCustom(), '::') === false && $class->hasMethod($this->getCustom())) { + if (strpos($this->getCustom(), '::') === FALSE && $class->hasMethod($this->getCustom())) { $this->setCustom(sprintf('%s::%s', $class->getName(), $this->getCustom())); } $route->setRequirement('_custom_access', $this->getCustom()); diff --git a/src/Configuration/Template.php b/src/Configuration/Template.php index 4fbb08c..69978d9 100644 --- a/src/Configuration/Template.php +++ b/src/Configuration/Template.php @@ -26,7 +26,7 @@ class Template extends ConfigurationAnnotation { * * @var bool */ - protected $streamable = false; + protected $streamable = FALSE; /** * The controller (+action) this annotation is set to. @@ -113,7 +113,7 @@ public function getAliasName() { * @see ConfigurationInterface */ public function allowArray() { - return false; + return FALSE; } /** diff --git a/src/Configuration/Title.php b/src/Configuration/Title.php index af556fb..70287e6 100644 --- a/src/Configuration/Title.php +++ b/src/Configuration/Title.php @@ -131,7 +131,7 @@ public function getAliasName() { * @return bool */ public function allowArray() { - return false; + return FALSE; } /** @@ -176,7 +176,7 @@ protected function modifyRoute(RoutingRoute $route, \ReflectionClass $class) { */ protected function registerCallback(RoutingRoute $route, \ReflectionClass $class) { if ($this->hasCallback()) { - if (strpos($this->getCallback(), '::') === false && $class->hasMethod($this->getCallback())) { + if (strpos($this->getCallback(), '::') === FALSE && $class->hasMethod($this->getCallback())) { $this->setCallback(sprintf('%s::%s', $class->getName(), $this->getCallback())); } $route->setDefault('_title_callback', $this->getCallback()); diff --git a/src/EventSubscriber/HttpCacheEventSubscriber.php b/src/EventSubscriber/HttpCacheEventSubscriber.php index 4fd13c4..eecffbf 100644 --- a/src/EventSubscriber/HttpCacheEventSubscriber.php +++ b/src/EventSubscriber/HttpCacheEventSubscriber.php @@ -138,7 +138,7 @@ protected function createETag(Request $request, Cache $configuration) { * @return float */ protected function calculateAge($age) { - $now = microtime(true); + $now = microtime(TRUE); return ceil(strtotime($age, $now) - $now); } @@ -151,7 +151,7 @@ protected function calculateAge($age) { protected function getConfiguration(Request $request) { $configuration = $request->attributes->get('_cache'); if (empty($configuration) || !$configuration instanceof Cache) { - return false; + return FALSE; } return $configuration; @@ -167,7 +167,7 @@ protected function setCacheProperties( Response $response, Cache $configuration ) { - if (null !== $age = $configuration->getSMaxAge()) { + if (NULL !== $age = $configuration->getSMaxAge()) { if (!is_numeric($age)) { $age = $this->calculateAge($configuration->getSMaxAge()); } @@ -175,7 +175,7 @@ protected function setCacheProperties( $response->setSharedMaxAge($age); } - if (null !== $age = $configuration->getMaxAge()) { + if (NULL !== $age = $configuration->getMaxAge()) { if (!is_numeric($age)) { $age = $this->calculateAge($configuration->getMaxAge()); } @@ -183,11 +183,11 @@ protected function setCacheProperties( $response->setMaxAge($age); } - if (null !== $configuration->getExpires()) { + if (NULL !== $configuration->getExpires()) { $response->setExpires($this->calculateExpires($configuration)); } - if (null !== $configuration->getVary()) { + if (NULL !== $configuration->getVary()) { $response->setVary($configuration->getVary()); } @@ -237,10 +237,10 @@ protected function hasUncachableStatusCode(Response $response) { $response->getStatusCode(), [200, 203, 300, 301, 302, 304, 404, 410] )) { - return true; + return TRUE; } - return false; + return FALSE; } /** @@ -248,7 +248,7 @@ protected function hasUncachableStatusCode(Response $response) { * @return ExpressionLanguage */ private function getExpressionLanguage() { - if (null === $this->expressionLanguage) { + if (NULL === $this->expressionLanguage) { if (!class_exists(ExpressionLanguage::class)) { throw new \RuntimeException( 'Unable to use expressions as the Symfony ExpressionLanguage component is not installed.' diff --git a/src/EventSubscriber/ParamConverterEventSubscriber.php b/src/EventSubscriber/ParamConverterEventSubscriber.php index a10e199..1c057ef 100644 --- a/src/EventSubscriber/ParamConverterEventSubscriber.php +++ b/src/EventSubscriber/ParamConverterEventSubscriber.php @@ -30,7 +30,7 @@ class ParamConverterEventSubscriber implements EventSubscriberInterface { * @param ParamConverterManager $manager A ParamConverterManager instance * @param bool $autoConvert Auto convert non-configured objects */ - public function __construct(ParamConverterManager $manager, $autoConvert = true) { + public function __construct(ParamConverterManager $manager, $autoConvert = TRUE) { $this->manager = $manager; $this->autoConvert = $autoConvert; $this->isParameterTypeSupported = method_exists('ReflectionParameter', 'getType'); @@ -101,7 +101,7 @@ private function autoConfigure(\ReflectionFunctionAbstract $r, Request $request, $configurations[$name] = $configuration; } - if ($class && null === $configurations[$name]->getClass()) { + if ($class && NULL === $configurations[$name]->getClass()) { $configurations[$name]->setClass($class->getName()); } } diff --git a/src/EventSubscriber/TemplateEventSubscriber.php b/src/EventSubscriber/TemplateEventSubscriber.php index 450db6f..0a80ba7 100644 --- a/src/EventSubscriber/TemplateEventSubscriber.php +++ b/src/EventSubscriber/TemplateEventSubscriber.php @@ -124,7 +124,7 @@ private function getParameters(GetResponseForControllerResultEvent $event, Templ // when the annotation declares no default vars and the action returns // null, all action method arguments are used as default vars - if (null === $parameters) { + if (NULL === $parameters) { $parameters = $this->resolveDefaultParameters($event->getRequest(), $template, $controller, $action); } diff --git a/src/Request/ParamConverter/DateTimeParamConverter.php b/src/Request/ParamConverter/DateTimeParamConverter.php index 3c42d2e..00fb719 100644 --- a/src/Request/ParamConverter/DateTimeParamConverter.php +++ b/src/Request/ParamConverter/DateTimeParamConverter.php @@ -22,12 +22,12 @@ class DateTimeParamConverter implements ParamConverterInterface { public function apply(Request $request, ParamConverter $configuration) { $param = $configuration->getName(); if (!$request->attributes->has($param)) { - return false; + return FALSE; } $value = $request->attributes->get($param); if (!$value && $configuration->isOptional()) { - return false; + return FALSE; } $request->attributes->set( @@ -35,7 +35,7 @@ public function apply(Request $request, ParamConverter $configuration) { $this->getDateTime($configuration, $value, $param) ); - return true; + return TRUE; } /** @@ -51,7 +51,7 @@ protected function getDateTime(ParamConverter $configuration, $value, $param) { if (isset($options['format'])) { $date = DateTime::createFromFormat($options['format'], $value); } - elseif (false !== strtotime($value)) { + elseif (FALSE !== strtotime($value)) { $date = new DateTime($value); } diff --git a/src/Request/ParamConverter/EntityParamConverter.php b/src/Request/ParamConverter/EntityParamConverter.php index e57fd90..940990c 100644 --- a/src/Request/ParamConverter/EntityParamConverter.php +++ b/src/Request/ParamConverter/EntityParamConverter.php @@ -36,12 +36,12 @@ public function __construct(EntityTypeManagerInterface $entityTypeManager) { public function apply(Request $request, ParamConverter $configuration) { $param = $configuration->getName(); if (!$request->attributes->has($param)) { - return false; + return FALSE; } $value = $request->attributes->get($param); if (!$value && $configuration->isOptional()) { - return false; + return FALSE; } $request->attributes->set( @@ -49,7 +49,7 @@ public function apply(Request $request, ParamConverter $configuration) { $this->getNode($value, $configuration) ); - return true; + return TRUE; } /** @@ -71,7 +71,7 @@ protected function getNode($value, ParamConverter $configuration) { */ protected function assertValidNode( ParamConverter $configuration, - EntityInterface $node = null + EntityInterface $node = NULL ) { if (is_null($node) && $configuration->isOptional()) { return; diff --git a/src/Request/ParamConverter/ParamConverterManager.php b/src/Request/ParamConverter/ParamConverterManager.php index 1f960de..3162794 100644 --- a/src/Request/ParamConverter/ParamConverterManager.php +++ b/src/Request/ParamConverter/ParamConverterManager.php @@ -113,8 +113,8 @@ protected function applyNamedConverter(Request $request, ParamConverter $configu * @param int $priority The priority (between -10 and 10). * @param string $name Name of the converter. */ - public function add(ParamConverterInterface $converter, $priority = 0, $name = null) { - if ($priority !== null) { + public function add(ParamConverterInterface $converter, $priority = 0, $name = NULL) { + if ($priority !== NULL) { if (!isset($this->converters[$priority])) { $this->converters[$priority] = []; } @@ -122,7 +122,7 @@ public function add(ParamConverterInterface $converter, $priority = 0, $name = n $this->converters[$priority][] = $converter; } - if (null !== $name) { + if (NULL !== $name) { $this->namedConverters[$name] = $converter; } } diff --git a/src/Templating/TemplateResolver.php b/src/Templating/TemplateResolver.php index d6170c0..c0ad203 100644 --- a/src/Templating/TemplateResolver.php +++ b/src/Templating/TemplateResolver.php @@ -68,7 +68,7 @@ public function normalize(string $template): string { * @param string $action * @return string */ - private function format(string $module, string $controller, string $action = null): string { + private function format(string $module, string $controller, string $action = NULL): string { $controller = $this->normalizeString($controller); $templateName = sprintf('%s-%s', $module, $controller); diff --git a/tests/modules/controller_annotations_test/src/Controller/ParamConverterController.php b/tests/modules/controller_annotations_test/src/Controller/ParamConverterController.php index 3fc2f9d..4589a09 100644 --- a/tests/modules/controller_annotations_test/src/Controller/ParamConverterController.php +++ b/tests/modules/controller_annotations_test/src/Controller/ParamConverterController.php @@ -45,7 +45,7 @@ public function dateMultipleAction(\DateTime $start, \DateTime $end) { * @Security(access=true) * @ParamConverter() */ - public function optionalDateAction(\DateTime $start = null) { + public function optionalDateAction(\DateTime $start = NULL) { if (empty($start)) { return new Response('empty'); } diff --git a/tests/src/Kernel/AnnotationsTest.php b/tests/src/Kernel/AnnotationsTest.php index b8c3d41..8b3fa89 100644 --- a/tests/src/Kernel/AnnotationsTest.php +++ b/tests/src/Kernel/AnnotationsTest.php @@ -63,7 +63,7 @@ private function setUpTemplate() { $destinationModule = $this->getDrupalRoot() . '/modules/controller_annotations_test/templates/'; if (!file_exists($destinationModule)) { - mkdir($destinationModule, 0777, true); + mkdir($destinationModule, 0777, TRUE); } foreach (new \DirectoryIterator($sourceModule) as $fileInfo) { if (!$fileInfo->isFile()) { diff --git a/tests/src/Kernel/KernelTestBase.php b/tests/src/Kernel/KernelTestBase.php index cb41624..c47ef4d 100644 --- a/tests/src/Kernel/KernelTestBase.php +++ b/tests/src/Kernel/KernelTestBase.php @@ -49,7 +49,7 @@ protected function assertResponseContents(Request $request, $contents) { protected function assertResponseContains(Request $request, $contents) { $response = $this->request($request); //echo $response->getContent(); - $this->assertTrue(strpos($response->getContent(), $contents) !== false); + $this->assertTrue(strpos($response->getContent(), $contents) !== FALSE); } /** @@ -58,7 +58,7 @@ protected function assertResponseContains(Request $request, $contents) { */ protected function assertResponseNotContains(Request $request, $contents) { $response = $this->request($request); - $this->assertTrue(strpos($response->getContent(), $contents) === false); + $this->assertTrue(strpos($response->getContent(), $contents) === FALSE); } /** diff --git a/tests/src/Kernel/TestUserSession.php b/tests/src/Kernel/TestUserSession.php index c21b00d..6b3f903 100644 --- a/tests/src/Kernel/TestUserSession.php +++ b/tests/src/Kernel/TestUserSession.php @@ -17,7 +17,7 @@ class TestUserSession extends UserSession { public function hasPermission($permission) { // User #1 has all privileges. if ((int) $this->id() === 1) { - return true; + return TRUE; } return in_array($permission, $this->permissions); diff --git a/tests/src/Unit/Cache/DrupalCacheTest.php b/tests/src/Unit/Cache/DrupalCacheTest.php index 3beafe5..fc305e4 100644 --- a/tests/src/Unit/Cache/DrupalCacheTest.php +++ b/tests/src/Unit/Cache/DrupalCacheTest.php @@ -22,7 +22,7 @@ public function testDoFetch() { public function testDoContains() { $drupalCache = $this->getDrupalCacheMock(); $drupalCache->shouldReceive('get')->once()->withArgs(['[foo][1]'])->andReturn($this->getCacheData('bar')); - $drupalCache->shouldReceive('get')->once()->withArgs(['[bar][1]'])->andReturn(false); + $drupalCache->shouldReceive('get')->once()->withArgs(['[bar][1]'])->andReturn(FALSE); $cache = new DrupalCache($drupalCache); $this->assertTrue($cache->contains('foo')); diff --git a/tests/src/Unit/Configuration/CacheTest.php b/tests/src/Unit/Configuration/CacheTest.php index 107de7a..8b586f2 100644 --- a/tests/src/Unit/Configuration/CacheTest.php +++ b/tests/src/Unit/Configuration/CacheTest.php @@ -22,11 +22,11 @@ public function testProperties() { $this->assertFalse($cache->isPublic()); $this->assertFalse($cache->isPrivate()); - $cache->setPublic(true); + $cache->setPublic(TRUE); $this->assertTrue($cache->isPublic()); $this->assertFalse($cache->isPrivate()); - $cache->setPublic(false); + $cache->setPublic(FALSE); $this->assertFalse($cache->isPublic()); $this->assertTrue($cache->isPrivate()); diff --git a/tests/src/Unit/Configuration/RouteTest.php b/tests/src/Unit/Configuration/RouteTest.php index 9b24dc5..aacad01 100644 --- a/tests/src/Unit/Configuration/RouteTest.php +++ b/tests/src/Unit/Configuration/RouteTest.php @@ -11,12 +11,12 @@ class RouteTest extends UnitTestCase { public function testModifyRouteClass() { $route = m::mock(Route::class); - $route->shouldReceive('setOption')->once()->withArgs(['_admin_route', true]); + $route->shouldReceive('setOption')->once()->withArgs(['_admin_route', TRUE]); $class = m::mock(\ReflectionClass::class); $method = m::mock(\ReflectionMethod::class); - $routeConfig = new RouteConfiguration(['admin' => true]); + $routeConfig = new RouteConfiguration(['admin' => TRUE]); $this->assertNull($routeConfig->modifyRouteClass($route, $class, $method)); m::close(); diff --git a/tests/src/Unit/Configuration/SecurityTest.php b/tests/src/Unit/Configuration/SecurityTest.php index 84deaff..3ac698c 100644 --- a/tests/src/Unit/Configuration/SecurityTest.php +++ b/tests/src/Unit/Configuration/SecurityTest.php @@ -11,22 +11,22 @@ class SecurityTest extends UnitTestCase { public function testModifyRouteMethod() { $route = m::mock(Route::class); - $route->shouldReceive('setRequirement')->once()->withArgs(['_access', true]); + $route->shouldReceive('setRequirement')->once()->withArgs(['_access', TRUE]); $route->shouldReceive('setRequirement')->once()->withArgs(['_permission', 'permission']); $route->shouldReceive('setRequirement')->once()->withArgs(['_role', 'role']); $route->shouldReceive('setRequirement')->once()->withArgs(['_entity_access', 'entity']); - $route->shouldReceive('setRequirement')->once()->withArgs(['_csrf_token', true]); + $route->shouldReceive('setRequirement')->once()->withArgs(['_csrf_token', TRUE]); $route->shouldReceive('setRequirement')->once()->withArgs(['_custom_access', 'foo::custom']); $class = m::mock(\ReflectionClass::class); $method = m::mock(\ReflectionMethod::class); $security = new Security([ - 'access' => true, + 'access' => TRUE, 'permission' => 'permission', 'role' => 'role', 'entity' => 'entity', - 'csrf' => true, + 'csrf' => TRUE, 'custom' => 'foo::custom' ]); $this->assertNull($security->modifyRouteMethod($route, $class, $method)); diff --git a/tests/src/Unit/Configuration/TitleTest.php b/tests/src/Unit/Configuration/TitleTest.php index cc3343c..715c880 100644 --- a/tests/src/Unit/Configuration/TitleTest.php +++ b/tests/src/Unit/Configuration/TitleTest.php @@ -12,8 +12,8 @@ class TitleTest extends UnitTestCase { public function testModifyRouteMethod() { $route = m::mock(Route::class); $route->shouldReceive('setDefault')->once()->withArgs(['_title', 'Hello World']); - $route->shouldReceive('setDefault')->once()->withArgs(['_title_arguments', ['arguments' => true]]); - $route->shouldReceive('setDefault')->once()->withArgs(['_title_context', ['context' => true]]); + $route->shouldReceive('setDefault')->once()->withArgs(['_title_arguments', ['arguments' => TRUE]]); + $route->shouldReceive('setDefault')->once()->withArgs(['_title_context', ['context' => TRUE]]); $route->shouldReceive('setDefault')->once()->withArgs(['_title_callback', 'foo::callback']); $class = m::mock(\ReflectionClass::class); @@ -21,8 +21,8 @@ public function testModifyRouteMethod() { $security = new Title([ 'value' => 'Hello World', - 'arguments' => ['arguments' => true], - 'context' => ['context' => true], + 'arguments' => ['arguments' => TRUE], + 'context' => ['context' => TRUE], 'callback' => 'foo::callback' ]); $this->assertNull($security->modifyRouteMethod($route, $class, $method)); diff --git a/tests/src/Unit/EventSubscriber/ControllerEventSubscriberTest.php b/tests/src/Unit/EventSubscriber/ControllerEventSubscriberTest.php index 7c1f91b..f674903 100644 --- a/tests/src/Unit/EventSubscriber/ControllerEventSubscriberTest.php +++ b/tests/src/Unit/EventSubscriber/ControllerEventSubscriberTest.php @@ -22,7 +22,7 @@ public function testOnKernelController() { $eventSubscriber = new ControllerEventSubscriber($reader); $event = m::mock(FilterControllerEvent::class); - $event->shouldReceive('getController')->once()->andReturn(null); + $event->shouldReceive('getController')->once()->andReturn(NULL); $this->assertNull($eventSubscriber->onKernelController($event)); } @@ -43,7 +43,7 @@ public function testControllerInvoke() { public function testMultipleConfigurations() { $configuration = m::mock(ConfigurationInterface::class); - $configuration->shouldReceive('allowArray')->andReturn(true); + $configuration->shouldReceive('allowArray')->andReturn(TRUE); $configuration->shouldReceive('getAliasName')->andReturn('foo'); $reader = m::mock(Reader::class); diff --git a/tests/src/Unit/EventSubscriber/HttpCacheListenerTest.php b/tests/src/Unit/EventSubscriber/HttpCacheListenerTest.php index f121346..3560610 100644 --- a/tests/src/Unit/EventSubscriber/HttpCacheListenerTest.php +++ b/tests/src/Unit/EventSubscriber/HttpCacheListenerTest.php @@ -44,7 +44,7 @@ public function testWontReassignResponseWhenNoConfigurationIsPresent() { public function testResponseIsPublicIfConfigurationIsPublicTrue() { $request = $this->createRequest(new Cache(array( - 'public' => true, + 'public' => TRUE, ))); $this->listener->onKernelResponse($this->createEventMock($request, $this->response)); @@ -55,7 +55,7 @@ public function testResponseIsPublicIfConfigurationIsPublicTrue() { public function testResponseIsPrivateIfConfigurationIsPublicFalse() { $request = $this->createRequest(new Cache(array( - 'public' => false, + 'public' => FALSE, ))); $this->listener->onKernelResponse($this->createEventMock($request, $this->response)); @@ -132,7 +132,7 @@ public function testLastModifiedNotModifiedResponse() { $listener = new HttpCacheEventSubscriber(); $controllerEvent = new FilterControllerEvent($this->getKernel(), function () { return new Response(500); - }, $request, null); + }, $request, NULL); $listener->onKernelController($controllerEvent); $response = call_user_func($controllerEvent->getController()); @@ -148,10 +148,10 @@ public function testLastModifiedHeader() { $listener = new HttpCacheEventSubscriber(); $controllerEvent = new FilterControllerEvent($this->getKernel(), function () { return new Response(); - }, $request, null); + }, $request, NULL); $listener->onKernelController($controllerEvent); - $responseEvent = new FilterResponseEvent($this->getKernel(), $request, null, call_user_func($controllerEvent->getController())); + $responseEvent = new FilterResponseEvent($this->getKernel(), $request, NULL, call_user_func($controllerEvent->getController())); $listener->onKernelResponse($responseEvent); $response = $responseEvent->getResponse(); @@ -169,7 +169,7 @@ public function testETagNotModifiedResponse() { $listener = new HttpCacheEventSubscriber(); $controllerEvent = new FilterControllerEvent($this->getKernel(), function () { return new Response(500); - }, $request, null); + }, $request, NULL); $listener->onKernelController($controllerEvent); $response = call_user_func($controllerEvent->getController()); @@ -185,10 +185,10 @@ public function testETagHeader() { $listener = new HttpCacheEventSubscriber(); $controllerEvent = new FilterControllerEvent($this->getKernel(), function () { return new Response(); - }, $request, null); + }, $request, NULL); $listener->onKernelController($controllerEvent); - $responseEvent = new FilterResponseEvent($this->getKernel(), $request, null, call_user_func($controllerEvent->getController())); + $responseEvent = new FilterResponseEvent($this->getKernel(), $request, NULL, call_user_func($controllerEvent->getController())); $listener->onKernelResponse($responseEvent); $response = $responseEvent->getResponse(); @@ -198,7 +198,7 @@ public function testETagHeader() { $this->assertContains(hash('sha256', $entity->getId()), $response->headers->get('ETag')); } - private function createRequest(Cache $cache = null) { + private function createRequest(Cache $cache = NULL) { return new Request(array(), array(), array( '_cache' => $cache, )); diff --git a/tests/src/Unit/EventSubscriber/ParamConverterEventSubscriberTest.php b/tests/src/Unit/EventSubscriber/ParamConverterEventSubscriberTest.php index ca1b37f..320f337 100644 --- a/tests/src/Unit/EventSubscriber/ParamConverterEventSubscriberTest.php +++ b/tests/src/Unit/EventSubscriber/ParamConverterEventSubscriberTest.php @@ -28,7 +28,7 @@ public function testRequestIsSkipped($controllerCallable) { $kernel, $controllerCallable, $request, - null + NULL ); $eventSubscriber->onKernelController($event); @@ -61,7 +61,7 @@ public function testAutoConvert($controllerCallable) { $kernel, $controllerCallable, $request, - null + NULL ); $eventSubscriber->onKernelController($event); @@ -82,7 +82,7 @@ public function testSettingOptionalParam($function, $isOptional) { $eventSubscriber = new ParamConverterEventSubscriber( $this->getParamConverterManager($request, ['param' => $converter]), - true + TRUE ); $event = new FilterControllerEvent( $kernel, @@ -91,7 +91,7 @@ public function testSettingOptionalParam($function, $isOptional) { $function, ], $request, - null + NULL ); $eventSubscriber->onKernelController($event); @@ -99,9 +99,9 @@ public function testSettingOptionalParam($function, $isOptional) { public function settingOptionalParamProvider() { return [ - ['requiredParamAction', false], - ['defaultParamAction', true], - ['nullableParamAction', true], + ['requiredParamAction', FALSE], + ['defaultParamAction', TRUE], + ['nullableParamAction', TRUE], ]; } @@ -114,13 +114,13 @@ public function testNoAutoConvert($controllerCallable) { $eventSubscriber = new ParamConverterEventSubscriber( $this->getParamConverterManager($request, []), - false + FALSE ); $event = new FilterControllerEvent( $kernel, $controllerCallable, $request, - null + NULL ); $eventSubscriber->onKernelController($event); @@ -157,13 +157,13 @@ public function testPredefinedConfigurations() { $kernel, 'time', $request, - null + NULL ); $manager = m::mock(ParamConverterManager::class); $manager->shouldReceive('apply')->once()->withArgs([$request, ['foo' => $configuration]]); - $eventSubscriber = new ParamConverterEventSubscriber($manager, false); + $eventSubscriber = new ParamConverterEventSubscriber($manager, FALSE); $eventSubscriber->onKernelController($event); $this->assertNull(m::close()); diff --git a/tests/src/Unit/EventSubscriber/TemplateEventSubscriberTest.php b/tests/src/Unit/EventSubscriber/TemplateEventSubscriberTest.php index f344ef5..b2f427f 100644 --- a/tests/src/Unit/EventSubscriber/TemplateEventSubscriberTest.php +++ b/tests/src/Unit/EventSubscriber/TemplateEventSubscriberTest.php @@ -123,15 +123,15 @@ public function testOnKernelView() { $template = m::mock(Template::class); $template->shouldReceive('getOwner')->andReturn(['controller', 'action']); - $template->shouldReceive('isStreamable')->andReturn(false); + $template->shouldReceive('isStreamable')->andReturn(FALSE); $template->shouldReceive('setOwner')->once()->withArgs([[]]); $template->shouldReceive('getTemplate')->once()->andReturn($templateName); $request = new Request(); $request->attributes->set('_template', $template); - $property = null; - $value = null; + $property = NULL; + $value = NULL; $kernel = m::mock(HttpKernelInterface::class); $event = new GetResponseForControllerResultEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST, []); @@ -153,15 +153,15 @@ public function testOnKernelViewStreamed() { $template = m::mock(Template::class); $template->shouldReceive('getOwner')->andReturn(['controller', 'action']); - $template->shouldReceive('isStreamable')->andReturn(true); + $template->shouldReceive('isStreamable')->andReturn(TRUE); $template->shouldReceive('setOwner')->once()->withArgs([[]]); $template->shouldReceive('getTemplate')->once()->andReturn($templateName); $request = new Request(); $request->attributes->set('_template', $template); - $property = null; - $value = null; + $property = NULL; + $value = NULL; $kernel = m::mock(HttpKernelInterface::class); $event = new GetResponseForControllerResultEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST, []); @@ -170,7 +170,7 @@ public function testOnKernelViewStreamed() { $eventSubscriber->onKernelView($event); $response = $event->getResponse(); - $this->assertEquals(false, $response->getContent()); + $this->assertEquals(FALSE, $response->getContent()); $this->assertInstanceOf(StreamedResponse::class, $response); $response->sendContent(); diff --git a/tests/src/Unit/Fixture/FooControllerNullableParameter.php b/tests/src/Unit/Fixture/FooControllerNullableParameter.php index 4f6d7a4..3c2482e 100644 --- a/tests/src/Unit/Fixture/FooControllerNullableParameter.php +++ b/tests/src/Unit/Fixture/FooControllerNullableParameter.php @@ -7,7 +7,7 @@ class FooControllerNullableParameter { public function requiredParamAction(\DateTime $param) { } - public function defaultParamAction(\DateTime $param = null) { + public function defaultParamAction(\DateTime $param = NULL) { } public function nullableParamAction(?\DateTime $param) { diff --git a/tests/src/Unit/Helper.php b/tests/src/Unit/Helper.php index 01b1497..3a4e5ce 100644 --- a/tests/src/Unit/Helper.php +++ b/tests/src/Unit/Helper.php @@ -7,7 +7,7 @@ class Helper { public static function getProtectedMethod($class, $name) { $class = new \ReflectionClass($class); $method = $class->getMethod($name); - $method->setAccessible(true); + $method->setAccessible(TRUE); return $method; } diff --git a/tests/src/Unit/Request/ParamConverter/DateTimeParamConverterTest.php b/tests/src/Unit/Request/ParamConverter/DateTimeParamConverterTest.php index 7f575ac..cd5702b 100644 --- a/tests/src/Unit/Request/ParamConverter/DateTimeParamConverterTest.php +++ b/tests/src/Unit/Request/ParamConverter/DateTimeParamConverterTest.php @@ -68,11 +68,11 @@ public function testApplyWithFormatInvalidDate404Exception() { } public function testApplyOptionalWithEmptyAttribute() { - $request = new Request([], [], ['start' => null]); + $request = new Request([], [], ['start' => NULL]); $config = $this->createConfiguration('DateTime', 'start'); $config->expects($this->once()) ->method('isOptional') - ->will($this->returnValue(true)); + ->will($this->returnValue(TRUE)); $this->assertFalse($this->converter->apply($request, $config)); $this->assertNull($request->attributes->get('start')); @@ -85,7 +85,7 @@ public function testApplyEmptyAttribute() { $this->assertFalse($this->converter->apply($request, $config)); } - public function createConfiguration($class = null, $name = null) { + public function createConfiguration($class = NULL, $name = NULL) { $config = $this ->getMockBuilder(ParamConverter::class) ->setMethods( @@ -101,12 +101,12 @@ public function createConfiguration($class = null, $name = null) { ->disableOriginalConstructor() ->getMock(); - if ($name !== null) { + if ($name !== NULL) { $config->expects($this->any()) ->method('getName') ->will($this->returnValue($name)); } - if ($class !== null) { + if ($class !== NULL) { $config->expects($this->any()) ->method('getClass') ->will($this->returnValue($class)); diff --git a/tests/src/Unit/Request/ParamConverter/EntityParamConverterTest.php b/tests/src/Unit/Request/ParamConverter/EntityParamConverterTest.php index 1b69a4f..9cd1005 100644 --- a/tests/src/Unit/Request/ParamConverter/EntityParamConverterTest.php +++ b/tests/src/Unit/Request/ParamConverter/EntityParamConverterTest.php @@ -76,7 +76,7 @@ public function testApplyNonExistingEntity() { $paramConverter = m::mock(ParamConverter::class); $paramConverter->shouldReceive('getClass')->once()->andReturn(Node::class); $paramConverter->shouldReceive('getName')->once()->andReturn($name); - $paramConverter->shouldReceive('isOptional')->once()->andReturn(false); + $paramConverter->shouldReceive('isOptional')->once()->andReturn(FALSE); $entityParamConverter = new EntityParamConverter($entityTypeManager); @@ -149,7 +149,7 @@ public function testApplyOptionalWhenEmpty() { $id = 1; $entityInterface = m::mock(EntityInterface::class); - $entityInterface->shouldReceive('load')->withArgs([$id])->andReturn(null); + $entityInterface->shouldReceive('load')->withArgs([$id])->andReturn(NULL); $entityTypeManager = m::mock(EntityTypeManager::class); $entityTypeManager->shouldReceive('getStorage')->withArgs(['node'])->andReturn($entityInterface); @@ -163,13 +163,13 @@ public function testApplyOptionalWhenEmpty() { $paramConverter = m::mock(ParamConverter::class); $paramConverter->shouldReceive('getClass')->once()->andReturn(Node::class); $paramConverter->shouldReceive('getName')->once()->andReturn($name); - $paramConverter->shouldReceive('isOptional')->once()->andReturn(true); + $paramConverter->shouldReceive('isOptional')->once()->andReturn(TRUE); $this->assertTrue($nodeParamConverter->supports($paramConverter)); $nodeParamConverter->apply($request, $paramConverter); $this->assertTrue($request->attributes->has($name)); - $this->assertEquals(null, $request->attributes->get($name)); + $this->assertEquals(NULL, $request->attributes->get($name)); } public function testApplyWithoutAttribute() { @@ -177,7 +177,7 @@ public function testApplyWithoutAttribute() { $bundle = 'article'; $entityInterface = m::mock(EntityInterface::class); - $entityInterface->shouldReceive('load')->withArgs([$id])->andReturn(null); + $entityInterface->shouldReceive('load')->withArgs([$id])->andReturn(NULL); $entityTypeManager = m::mock(EntityTypeManager::class); $entityTypeManager->shouldReceive('getStorage')->withArgs(['node'])->andReturn($entityInterface); @@ -201,7 +201,7 @@ public function testOptional() { $bundle = 'article'; $entityInterface = m::mock(EntityInterface::class); - $entityInterface->shouldReceive('load')->withArgs([$id])->andReturn(null); + $entityInterface->shouldReceive('load')->withArgs([$id])->andReturn(NULL); $entityTypeManager = m::mock(EntityTypeManager::class); $entityTypeManager->shouldReceive('getStorage')->withArgs(['node'])->andReturn($entityInterface); @@ -223,7 +223,7 @@ public function testOptionalEmptyAttribute() { $bundle = 'article'; $entityInterface = m::mock(EntityInterface::class); - $entityInterface->shouldReceive('load')->withArgs([$id])->andReturn(null); + $entityInterface->shouldReceive('load')->withArgs([$id])->andReturn(NULL); $entityTypeManager = m::mock(EntityTypeManager::class); $entityTypeManager->shouldReceive('getStorage')->withArgs(['node'])->andReturn($entityInterface); @@ -237,7 +237,7 @@ public function testOptionalEmptyAttribute() { $paramConverter = m::mock(ParamConverter::class); $paramConverter->shouldReceive('getName')->once()->andReturn($name); $paramConverter->shouldReceive('getOptions')->never()->andReturn(['bundle' => $bundle]); - $paramConverter->shouldReceive('isOptional')->once()->andReturn(true); + $paramConverter->shouldReceive('isOptional')->once()->andReturn(TRUE); $this->assertFalse($nodeParamConverter->apply($request, $paramConverter)); } diff --git a/tests/src/Unit/Request/ParamConverter/ParamConverterManagerTest.php b/tests/src/Unit/Request/ParamConverter/ParamConverterManagerTest.php index 049e638..39952bf 100644 --- a/tests/src/Unit/Request/ParamConverter/ParamConverterManagerTest.php +++ b/tests/src/Unit/Request/ParamConverter/ParamConverterManagerTest.php @@ -31,19 +31,19 @@ public function testApply() { $supported ->expects($this->once()) ->method('supports') - ->will($this->returnValue(true)) + ->will($this->returnValue(TRUE)) ; $supported ->expects($this->once()) ->method('apply') - ->will($this->returnValue(false)) + ->will($this->returnValue(FALSE)) ; $invalid = $this->createParamConverterMock(); $invalid ->expects($this->once()) ->method('supports') - ->will($this->returnValue(false)) + ->will($this->returnValue(FALSE)) ; $invalid ->expects($this->never()) @@ -67,7 +67,7 @@ public function testApplyNamedConverter() { $converter ->expects($this->any()) ->method('supports') - ->will($this->returnValue(true)) + ->will($this->returnValue(TRUE)) ; $converter @@ -98,7 +98,7 @@ public function testApplyNamedConverterNotSupportsParameter() { $converter ->expects($this->any()) ->method('supports') - ->will($this->returnValue(false)) + ->will($this->returnValue(FALSE)) ; $request = new Request(); @@ -163,7 +163,7 @@ public function testApplyWithoutArray() { $converter ->expects($this->any()) ->method('supports') - ->will($this->returnValue(false)) + ->will($this->returnValue(FALSE)) ; $converter diff --git a/tests/src/Unit/Routing/AnnotatedRouteControllerLoaderTest.php b/tests/src/Unit/Routing/AnnotatedRouteControllerLoaderTest.php index 0e6a897..ed7dd39 100644 --- a/tests/src/Unit/Routing/AnnotatedRouteControllerLoaderTest.php +++ b/tests/src/Unit/Routing/AnnotatedRouteControllerLoaderTest.php @@ -17,8 +17,8 @@ class AnnotatedRouteControllerLoaderTest extends UnitTestCase { public function testConfigureRoute() { $routeConfiguration = m::mock(\Drupal\controller_annotations\Configuration\Route::class); - $routeConfiguration->shouldReceive('getService')->andReturn(false); - $routeConfiguration->shouldReceive('isAdmin')->andReturn(true); + $routeConfiguration->shouldReceive('getService')->andReturn(FALSE); + $routeConfiguration->shouldReceive('isAdmin')->andReturn(TRUE); $routeConfiguration->shouldReceive('modifyRouteMethod')->andReturnNull(); $routeConfiguration->shouldReceive('modifyRouteClass')->andReturnNull(); @@ -46,9 +46,9 @@ public function testConfigureRoute() { $method = Helper::getProtectedMethod(AnnotatedRouteControllerLoader::class, 'configureRoute'); $annotatedRouteControllerLoader = new AnnotatedRouteControllerLoader($reader); - $method->invokeArgs($annotatedRouteControllerLoader, [$route, $reflectionClass, $reflectionMethod, null]); + $method->invokeArgs($annotatedRouteControllerLoader, [$route, $reflectionClass, $reflectionMethod, NULL]); - $this->assertTrue(true); + $this->assertTrue(TRUE); m::close(); } From 1a7712fe3133953c8181243589607b930e0489a8 Mon Sep 17 00:00:00 2001 From: Andreas Hennings <andreas@dqxtech.net> Date: Sat, 11 Jan 2020 21:56:20 +0100 Subject: [PATCH 08/23] (CS) Use FQCN in phpdoc. --- src/Cache/DrupalCache.php | 4 +- src/Configuration/Method.php | 6 +-- src/Configuration/Route.php | 6 +-- .../RouteModifierClassInterface.php | 2 +- .../RouteModifierMethodInterface.php | 2 +- src/Configuration/Security.php | 8 ++-- src/Configuration/Title.php | 8 ++-- .../ControllerEventSubscriber.php | 8 ++-- .../HttpCacheEventSubscriber.php | 38 +++++++++---------- .../ParamConverterEventSubscriber.php | 6 +-- src/EventSubscriber/RouteEventSubscriber.php | 8 ++-- .../TemplateEventSubscriber.php | 26 ++++++------- .../ParamConverter/DateTimeParamConverter.php | 4 +- .../ParamConverter/EntityParamConverter.php | 18 ++++----- .../ParamConverterInterface.php | 6 +-- .../ParamConverter/ParamConverterManager.php | 12 +++--- .../AnnotatedRouteControllerLoader.php | 8 ++-- .../src/Controller/SecurityController.php | 4 +- .../src/Security/Custom.php | 4 +- tests/src/Kernel/DrupalTestKernel.php | 2 +- tests/src/Kernel/KernelTestBase.php | 22 +++++------ tests/src/Unit/Cache/DrupalCacheTest.php | 4 +- .../RouteEventSubscriberTest.php | 10 ++--- .../Unit/Templating/TemplateResolverTest.php | 2 +- 24 files changed, 109 insertions(+), 109 deletions(-) diff --git a/src/Cache/DrupalCache.php b/src/Cache/DrupalCache.php index ab1ac21..1ad2c0d 100644 --- a/src/Cache/DrupalCache.php +++ b/src/Cache/DrupalCache.php @@ -8,12 +8,12 @@ class DrupalCache extends CacheProvider { /** - * @var CacheBackendInterface + * @var \Drupal\Core\Cache\CacheBackendInterface */ private $cache; /** - * @param CacheBackendInterface $cache + * @param \Drupal\Core\Cache\CacheBackendInterface $cache */ public function __construct(CacheBackendInterface $cache) { $this->cache = $cache; diff --git a/src/Configuration/Method.php b/src/Configuration/Method.php index 18fed7b..c1d7995 100644 --- a/src/Configuration/Method.php +++ b/src/Configuration/Method.php @@ -66,7 +66,7 @@ public function allowArray() { } /** - * @param RoutingRoute $route + * @param \Symfony\Component\Routing\Route $route * @param \ReflectionClass $class * @param \ReflectionMethod $method */ @@ -75,7 +75,7 @@ public function modifyRouteClass(RoutingRoute $route, \ReflectionClass $class, \ } /** - * @param RoutingRoute $route + * @param \Symfony\Component\Routing\Route $route * @param \ReflectionClass $class * @param \ReflectionMethod $method */ @@ -87,7 +87,7 @@ public function modifyRouteMethod(RoutingRoute $route, \ReflectionClass $class, * we need to make sure this is an array instead of a string which is different in Symfony Framework * otherwise the support for defining an array of methods will not work as expected * - * @param RoutingRoute $route + * @param \Symfony\Component\Routing\Route $route */ protected function modifyRoute(RoutingRoute $route) { $route->setMethods($this->getMethods()); diff --git a/src/Configuration/Route.php b/src/Configuration/Route.php index 6aac9ec..57d361e 100644 --- a/src/Configuration/Route.php +++ b/src/Configuration/Route.php @@ -64,7 +64,7 @@ public function allowArray() { } /** - * @param RoutingRoute $route + * @param \Symfony\Component\Routing\Route $route * @param \ReflectionClass $class * @param \ReflectionMethod $method */ @@ -73,7 +73,7 @@ public function modifyRouteClass(RoutingRoute $route, \ReflectionClass $class, \ } /** - * @param RoutingRoute $route + * @param \Symfony\Component\Routing\Route $route * @param \ReflectionClass $class * @param \ReflectionMethod $method */ @@ -86,7 +86,7 @@ public function modifyRouteMethod(RoutingRoute $route, \ReflectionClass $class, } /** - * @param RoutingRoute $route + * @param \Symfony\Component\Routing\Route $route * @param \ReflectionClass $class * @param \ReflectionMethod $method */ diff --git a/src/Configuration/RouteModifierClassInterface.php b/src/Configuration/RouteModifierClassInterface.php index d25deaa..74d9cc6 100644 --- a/src/Configuration/RouteModifierClassInterface.php +++ b/src/Configuration/RouteModifierClassInterface.php @@ -7,7 +7,7 @@ interface RouteModifierClassInterface extends RouteModifierInterface { /** - * @param RoutingRoute $route + * @param \Symfony\Component\Routing\Route $route * @param \ReflectionClass $class * @param \ReflectionMethod $method */ diff --git a/src/Configuration/RouteModifierMethodInterface.php b/src/Configuration/RouteModifierMethodInterface.php index 1502555..d81122c 100644 --- a/src/Configuration/RouteModifierMethodInterface.php +++ b/src/Configuration/RouteModifierMethodInterface.php @@ -7,7 +7,7 @@ interface RouteModifierMethodInterface extends RouteModifierInterface { /** - * @param RoutingRoute $route + * @param \Symfony\Component\Routing\Route $route * @param \ReflectionClass $class * @param \ReflectionMethod $method */ diff --git a/src/Configuration/Security.php b/src/Configuration/Security.php index 355d85f..c78ecd8 100644 --- a/src/Configuration/Security.php +++ b/src/Configuration/Security.php @@ -178,7 +178,7 @@ public function allowArray() { } /** - * @param RoutingRoute $route + * @param \Symfony\Component\Routing\Route $route * @param \ReflectionClass $class * @param \ReflectionMethod $method */ @@ -187,7 +187,7 @@ public function modifyRouteClass(RoutingRoute $route, \ReflectionClass $class, \ } /** - * @param RoutingRoute $route + * @param \Symfony\Component\Routing\Route $route * @param \ReflectionClass $class * @param \ReflectionMethod $method */ @@ -196,7 +196,7 @@ public function modifyRouteMethod(RoutingRoute $route, \ReflectionClass $class, } /** - * @param RoutingRoute $route + * @param \Symfony\Component\Routing\Route $route * @param \ReflectionClass $class */ protected function modifyRoute(RoutingRoute $route, \ReflectionClass $class) { @@ -220,7 +220,7 @@ protected function modifyRoute(RoutingRoute $route, \ReflectionClass $class) { } /** - * @param RoutingRoute $route + * @param \Symfony\Component\Routing\Route $route * @param \ReflectionClass $class */ protected function setCustomSecurity(RoutingRoute $route, \ReflectionClass $class) { diff --git a/src/Configuration/Title.php b/src/Configuration/Title.php index 70287e6..c3b5e1d 100644 --- a/src/Configuration/Title.php +++ b/src/Configuration/Title.php @@ -135,7 +135,7 @@ public function allowArray() { } /** - * @param RoutingRoute $route + * @param \Symfony\Component\Routing\Route $route * @param \ReflectionClass $class * @param \ReflectionMethod $method */ @@ -144,7 +144,7 @@ public function modifyRouteClass(RoutingRoute $route, \ReflectionClass $class, \ } /** - * @param RoutingRoute $route + * @param \Symfony\Component\Routing\Route $route * @param \ReflectionClass $class * @param \ReflectionMethod $method */ @@ -153,7 +153,7 @@ public function modifyRouteMethod(RoutingRoute $route, \ReflectionClass $class, } /** - * @param RoutingRoute $route + * @param \Symfony\Component\Routing\Route $route * @param \ReflectionClass $class */ protected function modifyRoute(RoutingRoute $route, \ReflectionClass $class) { @@ -171,7 +171,7 @@ protected function modifyRoute(RoutingRoute $route, \ReflectionClass $class) { } /** - * @param RoutingRoute $route + * @param \Symfony\Component\Routing\Route $route * @param \ReflectionClass $class */ protected function registerCallback(RoutingRoute $route, \ReflectionClass $class) { diff --git a/src/EventSubscriber/ControllerEventSubscriber.php b/src/EventSubscriber/ControllerEventSubscriber.php index f4021b7..c74720c 100644 --- a/src/EventSubscriber/ControllerEventSubscriber.php +++ b/src/EventSubscriber/ControllerEventSubscriber.php @@ -13,12 +13,12 @@ class ControllerEventSubscriber implements EventSubscriberInterface { /** - * @var Reader + * @var \Doctrine\Common\Annotations\Reader */ protected $reader; /** - * @param Reader $reader + * @param \Doctrine\Common\Annotations\Reader $reader */ public function __construct(Reader $reader) { $this->reader = $reader; @@ -29,7 +29,7 @@ public function __construct(Reader $reader) { * controllers annotations like the template to render or HTTP caching * configuration. * - * @param FilterControllerEvent $event + * @param \Symfony\Component\HttpKernel\Event\FilterControllerEvent $event * @throws \ReflectionException */ public function onKernelController(FilterControllerEvent $event) { @@ -57,7 +57,7 @@ public function onKernelController(FilterControllerEvent $event) { } /** - * @param Request $request + * @param \Symfony\Component\HttpFoundation\Request $request * @param array $configurations */ protected function setRequestAttributes(Request $request, array $configurations) { diff --git a/src/EventSubscriber/HttpCacheEventSubscriber.php b/src/EventSubscriber/HttpCacheEventSubscriber.php index eecffbf..106519b 100644 --- a/src/EventSubscriber/HttpCacheEventSubscriber.php +++ b/src/EventSubscriber/HttpCacheEventSubscriber.php @@ -24,7 +24,7 @@ class HttpCacheEventSubscriber implements EventSubscriberInterface { private $eTags; /** - * @var ExpressionLanguage + * @var \Symfony\Component\ExpressionLanguage\ExpressionLanguage */ private $expressionLanguage; @@ -38,7 +38,7 @@ public function __construct() { /** * Handles HTTP validation headers. * - * @param FilterControllerEvent $event + * @param \Symfony\Component\HttpKernel\Event\FilterControllerEvent $event */ public function onKernelController(FilterControllerEvent $event) { $request = $event->getRequest(); @@ -67,7 +67,7 @@ function () use ($response) { /** * Modifies the response to apply HTTP cache headers when needed. * - * @param FilterResponseEvent $event + * @param \Symfony\Component\HttpKernel\Event\FilterResponseEvent $event */ public function onKernelResponse(FilterResponseEvent $event) { $request = $event->getRequest(); @@ -84,9 +84,9 @@ public function onKernelResponse(FilterResponseEvent $event) { } /** - * @param Request $request - * @param Response $response - * @param Cache $configuration + * @param \Symfony\Component\HttpFoundation\Request $request + * @param \Symfony\Component\HttpFoundation\Response $response + * @param \Drupal\controller_annotations\Configuration\Cache $configuration */ protected function setLastModified( Request $request, @@ -102,9 +102,9 @@ protected function setLastModified( } /** - * @param Request $request - * @param Response $response - * @param Cache $configuration + * @param \Symfony\Component\HttpFoundation\Request $request + * @param \Symfony\Component\HttpFoundation\Response $response + * @param \Drupal\controller_annotations\Configuration\Cache $configuration */ protected function setETag( Request $request, @@ -117,8 +117,8 @@ protected function setETag( } /** - * @param Request $request - * @param Cache $configuration + * @param \Symfony\Component\HttpFoundation\Request $request + * @param \Drupal\controller_annotations\Configuration\Cache $configuration * * @return string */ @@ -144,9 +144,9 @@ protected function calculateAge($age) { } /** - * @param Request $request + * @param \Symfony\Component\HttpFoundation\Request $request * - * @return Cache|false + * @return \Drupal\controller_annotations\Configuration\Cache|false */ protected function getConfiguration(Request $request) { $configuration = $request->attributes->get('_cache'); @@ -158,9 +158,9 @@ protected function getConfiguration(Request $request) { } /** - * @param Request $request - * @param Response $response - * @param Cache $configuration + * @param \Symfony\Component\HttpFoundation\Request $request + * @param \Symfony\Component\HttpFoundation\Response $response + * @param \Drupal\controller_annotations\Configuration\Cache $configuration */ protected function setCacheProperties( Request $request, @@ -213,7 +213,7 @@ protected function setCacheProperties( } /** - * @param Cache $configuration + * @param \Drupal\controller_annotations\Configuration\Cache $configuration * * @return bool|\DateTime */ @@ -228,7 +228,7 @@ protected function calculateExpires(Cache $configuration) { /** * http://tools.ietf.org/html/draft-ietf-httpbis-p4-conditional-12#section-3.1 * - * @param Response $response + * @param \Symfony\Component\HttpFoundation\Response $response * * @return bool */ @@ -245,7 +245,7 @@ protected function hasUncachableStatusCode(Response $response) { /** * @codeCoverageIgnore - * @return ExpressionLanguage + * @return \Symfony\Component\ExpressionLanguage\ExpressionLanguage */ private function getExpressionLanguage() { if (NULL === $this->expressionLanguage) { diff --git a/src/EventSubscriber/ParamConverterEventSubscriber.php b/src/EventSubscriber/ParamConverterEventSubscriber.php index 1c057ef..a8efe25 100644 --- a/src/EventSubscriber/ParamConverterEventSubscriber.php +++ b/src/EventSubscriber/ParamConverterEventSubscriber.php @@ -12,7 +12,7 @@ class ParamConverterEventSubscriber implements EventSubscriberInterface { /** - * @var ParamConverterManager + * @var \Drupal\controller_annotations\Configuration\ParamConverterManager */ protected $manager; @@ -27,7 +27,7 @@ class ParamConverterEventSubscriber implements EventSubscriberInterface { private $isParameterTypeSupported; /** - * @param ParamConverterManager $manager A ParamConverterManager instance + * @param \Drupal\controller_annotations\Configuration\ParamConverterManager $manager A ParamConverterManager instance * @param bool $autoConvert Auto convert non-configured objects */ public function __construct(ParamConverterManager $manager, $autoConvert = TRUE) { @@ -39,7 +39,7 @@ public function __construct(ParamConverterManager $manager, $autoConvert = TRUE) /** * Modifies the ParamConverterManager instance. * - * @param FilterControllerEvent $event A FilterControllerEvent instance + * @param \Symfony\Component\HttpKernel\Event\FilterControllerEvent $event A FilterControllerEvent instance */ public function onKernelController(FilterControllerEvent $event) { $controller = $event->getController(); diff --git a/src/EventSubscriber/RouteEventSubscriber.php b/src/EventSubscriber/RouteEventSubscriber.php index 285c5f5..ec2991e 100644 --- a/src/EventSubscriber/RouteEventSubscriber.php +++ b/src/EventSubscriber/RouteEventSubscriber.php @@ -12,7 +12,7 @@ class RouteEventSubscriber implements EventSubscriberInterface { /** - * @var AnnotationDirectoryLoader + * @var \Symfony\Component\Routing\Loader\AnnotationDirectoryLoader */ private $annotationDirectoryLoader; @@ -22,7 +22,7 @@ class RouteEventSubscriber implements EventSubscriberInterface { private $rootPath; /** - * @param AnnotationDirectoryLoader $annotationDirectoryLoader + * @param \Symfony\Component\Routing\Loader\AnnotationDirectoryLoader $annotationDirectoryLoader * @param string $rootPath */ public function __construct(AnnotationDirectoryLoader $annotationDirectoryLoader, string $rootPath) { @@ -39,7 +39,7 @@ private function registerAnnotations() { } /** - * @param RouteBuildEvent $event + * @param \Drupal\Core\Routing\RouteBuildEvent $event * @throws \Exception */ public function onRoutes(RouteBuildEvent $event) { @@ -71,7 +71,7 @@ public static function getSubscribedEvents() { } /** - * @param Route $route + * @param \Symfony\Component\Routing\Route $route * @return string * @throws \Exception */ diff --git a/src/EventSubscriber/TemplateEventSubscriber.php b/src/EventSubscriber/TemplateEventSubscriber.php index 0a80ba7..17f277d 100644 --- a/src/EventSubscriber/TemplateEventSubscriber.php +++ b/src/EventSubscriber/TemplateEventSubscriber.php @@ -21,13 +21,13 @@ class TemplateEventSubscriber implements EventSubscriberInterface { private $twig; /** - * @var TemplateResolver + * @var \Drupal\controller_annotations\Configuration\TemplateResolver */ private $resolver; /** * @param \Twig_Environment $twig - * @param TemplateResolver $resolver + * @param \Drupal\controller_annotations\Configuration\TemplateResolver $resolver */ public function __construct(\Twig_Environment $twig, TemplateResolver $resolver) { $this->twig = $twig; @@ -38,7 +38,7 @@ public function __construct(\Twig_Environment $twig, TemplateResolver $resolver) * Guesses the template name to render and its variables and adds them to * the request object. * - * @param FilterControllerEvent $event A FilterControllerEvent instance + * @param \Symfony\Component\HttpKernel\Event\FilterControllerEvent $event A FilterControllerEvent instance */ public function onKernelController(FilterControllerEvent $event) { $template = $this->getTemplateFromRequest($event); @@ -54,7 +54,7 @@ public function onKernelController(FilterControllerEvent $event) { * Renders the template and initializes a new response object with the * rendered template content. * - * @param GetResponseForControllerResultEvent $event + * @param \Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent $event */ public function onKernelView(GetResponseForControllerResultEvent $event) { $template = $this->getTemplateFromRequest($event); @@ -66,7 +66,7 @@ public function onKernelView(GetResponseForControllerResultEvent $event) { } /** - * @param KernelEvent $event + * @param \Symfony\Component\HttpKernel\Event\KernelEvent $event * @return mixed */ private function getTemplateFromRequest(KernelEvent $event) { @@ -74,7 +74,7 @@ private function getTemplateFromRequest(KernelEvent $event) { } /** - * @param Template $template + * @param \Drupal\controller_annotations\Configuration\Template $template */ private function normalizeTemplate(Template $template) { if (is_null($template->getTemplate())) { @@ -91,8 +91,8 @@ private function normalizeTemplate(Template $template) { } /** - * @param GetResponseForControllerResultEvent $event - * @param Template $template + * @param \Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent $event + * @param \Drupal\controller_annotations\Configuration\Template $template * @param $parameters */ private function setResponse(GetResponseForControllerResultEvent $event, Template $template, $parameters) { @@ -112,8 +112,8 @@ private function setResponse(GetResponseForControllerResultEvent $event, Templat } /** - * @param GetResponseForControllerResultEvent $event - * @param Template $template + * @param \Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent $event + * @param \Drupal\controller_annotations\Configuration\Template $template * @return array|mixed */ private function getParameters(GetResponseForControllerResultEvent $event, Template $template) { @@ -132,8 +132,8 @@ private function getParameters(GetResponseForControllerResultEvent $event, Templ } /** - * @param Request $request - * @param Template $template + * @param \Symfony\Component\HttpFoundation\Request $request + * @param \Drupal\controller_annotations\Configuration\Template $template * @param object $controller * @param string $action * @return array @@ -157,7 +157,7 @@ private function resolveDefaultParameters(Request $request, Template $template, * fetch the arguments of @Template.vars or everything if desired * and assign them to the designated template * - * @param Request $request + * @param \Symfony\Component\HttpFoundation\Request $request * @param array $arguments * @return array */ diff --git a/src/Request/ParamConverter/DateTimeParamConverter.php b/src/Request/ParamConverter/DateTimeParamConverter.php index 00fb719..242b85e 100644 --- a/src/Request/ParamConverter/DateTimeParamConverter.php +++ b/src/Request/ParamConverter/DateTimeParamConverter.php @@ -17,7 +17,7 @@ class DateTimeParamConverter implements ParamConverterInterface { /** * {@inheritdoc} * - * @throws NotFoundHttpException When invalid date given + * @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException When invalid date given */ public function apply(Request $request, ParamConverter $configuration) { $param = $configuration->getName(); @@ -39,7 +39,7 @@ public function apply(Request $request, ParamConverter $configuration) { } /** - * @param ParamConverter $configuration + * @param \Drupal\controller_annotations\Configuration\ParamConverter $configuration * @param $value * @param $param * @return bool|DateTime diff --git a/src/Request/ParamConverter/EntityParamConverter.php b/src/Request/ParamConverter/EntityParamConverter.php index 940990c..f71a63c 100644 --- a/src/Request/ParamConverter/EntityParamConverter.php +++ b/src/Request/ParamConverter/EntityParamConverter.php @@ -16,20 +16,20 @@ class EntityParamConverter implements ParamConverterInterface { /** - * @var EntityTypeManagerInterface + * @var \Drupal\Core\Entity\EntityTypeManagerInterface */ private $entityTypeManager; /** - * @param EntityTypeManagerInterface $entityTypeManager + * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entityTypeManager */ public function __construct(EntityTypeManagerInterface $entityTypeManager) { $this->entityTypeManager = $entityTypeManager; } /** - * @param Request $request - * @param ParamConverter $configuration + * @param \Symfony\Component\HttpFoundation\Request $request + * @param \Drupal\controller_annotations\Configuration\ParamConverter $configuration * * @return bool */ @@ -54,9 +54,9 @@ public function apply(Request $request, ParamConverter $configuration) { /** * @param string $value - * @param ParamConverter $configuration + * @param \Drupal\controller_annotations\Configuration\ParamConverter $configuration * - * @return EntityInterface|null + * @return \Drupal\Core\Entity\EntityInterface|null */ protected function getNode($value, ParamConverter $configuration) { $node = $this->entityTypeManager->getStorage('node')->load($value); @@ -66,8 +66,8 @@ protected function getNode($value, ParamConverter $configuration) { } /** - * @param ParamConverter $configuration - * @param EntityInterface $node + * @param \Drupal\controller_annotations\Configuration\ParamConverter $configuration + * @param \Drupal\Core\Entity\EntityInterface $node */ protected function assertValidNode( ParamConverter $configuration, @@ -88,7 +88,7 @@ protected function assertValidNode( } /** - * @param ParamConverter $configuration + * @param \Drupal\controller_annotations\Configuration\ParamConverter $configuration * * @return bool */ diff --git a/src/Request/ParamConverter/ParamConverterInterface.php b/src/Request/ParamConverter/ParamConverterInterface.php index c007dbf..f546662 100644 --- a/src/Request/ParamConverter/ParamConverterInterface.php +++ b/src/Request/ParamConverter/ParamConverterInterface.php @@ -16,8 +16,8 @@ interface ParamConverterInterface { /** * Stores the object in the request. * - * @param Request $request The request - * @param ParamConverter $configuration Contains the name, class and options of the object + * @param \Symfony\Component\HttpFoundation\Request $request The request + * @param \Drupal\controller_annotations\Configuration\ParamConverter $configuration Contains the name, class and options of the object * * @return bool True if the object has been successfully set, else false */ @@ -26,7 +26,7 @@ public function apply(Request $request, ParamConverter $configuration); /** * Checks if the object is supported. * - * @param ParamConverter $configuration Should be an instance of ParamConverter + * @param \Drupal\controller_annotations\Configuration\ParamConverter $configuration Should be an instance of ParamConverter * * @return bool True if the object is supported, else false */ diff --git a/src/Request/ParamConverter/ParamConverterManager.php b/src/Request/ParamConverter/ParamConverterManager.php index 3162794..2699c24 100644 --- a/src/Request/ParamConverter/ParamConverterManager.php +++ b/src/Request/ParamConverter/ParamConverterManager.php @@ -26,7 +26,7 @@ class ParamConverterManager { * Applies all converters to the passed configurations and stops when a * converter is applied it will move on to the next configuration and so on. * - * @param Request $request + * @param \Symfony\Component\HttpFoundation\Request $request * @param array|object $configurations */ public function apply(Request $request, $configurations) { @@ -42,8 +42,8 @@ public function apply(Request $request, $configurations) { /** * Apply converter on request based on the given configuration. * - * @param Request $request - * @param ParamConverter $configuration + * @param \Symfony\Component\HttpFoundation\Request $request + * @param \Drupal\controller_annotations\Configuration\ParamConverter $configuration */ protected function applyConverter(Request $request, ParamConverter $configuration) { $value = $request->attributes->get($configuration->getName()); @@ -71,8 +71,8 @@ protected function applyConverter(Request $request, ParamConverter $configuratio } /** - * @param Request $request - * @param ParamConverter $configuration + * @param \Symfony\Component\HttpFoundation\Request $request + * @param \Drupal\controller_annotations\Configuration\ParamConverter $configuration */ protected function applyNamedConverter(Request $request, ParamConverter $configuration) { $converterName = $configuration->getConverter(); @@ -109,7 +109,7 @@ protected function applyNamedConverter(Request $request, ParamConverter $configu * added converter will not be part of the iteration chain and can only * be invoked explicitly. * - * @param ParamConverterInterface $converter A ParamConverterInterface instance + * @param \Drupal\controller_annotations\Configuration\ParamConverterInterface $converter A ParamConverterInterface instance * @param int $priority The priority (between -10 and 10). * @param string $name Name of the converter. */ diff --git a/src/Routing/AnnotatedRouteControllerLoader.php b/src/Routing/AnnotatedRouteControllerLoader.php index 528185e..cbea4fe 100644 --- a/src/Routing/AnnotatedRouteControllerLoader.php +++ b/src/Routing/AnnotatedRouteControllerLoader.php @@ -11,7 +11,7 @@ class AnnotatedRouteControllerLoader extends AnnotationClassLoader { /** - * @param Route $route + * @param \Symfony\Component\Routing\Route $route * @param \ReflectionClass $class * @param \ReflectionMethod $method * @param mixed $annotation @@ -39,7 +39,7 @@ protected function getGlobals(\ReflectionClass $class): array { } /** - * @param Route $route + * @param \Symfony\Component\Routing\Route $route * @param \ReflectionClass $class * @param \ReflectionMethod $method */ @@ -52,7 +52,7 @@ protected function configureClassAnnotations(Route $route, \ReflectionClass $cla } /** - * @param Route $route + * @param \Symfony\Component\Routing\Route $route * @param \ReflectionClass $class * @param \ReflectionMethod $method */ @@ -65,7 +65,7 @@ protected function configureMethodAnnotations(Route $route, \ReflectionClass $cl } /** - * @param Route $route + * @param \Symfony\Component\Routing\Route $route * @param \ReflectionClass $class * @param \ReflectionMethod $method */ diff --git a/tests/modules/controller_annotations_test/src/Controller/SecurityController.php b/tests/modules/controller_annotations_test/src/Controller/SecurityController.php index 31945fc..8188946 100644 --- a/tests/modules/controller_annotations_test/src/Controller/SecurityController.php +++ b/tests/modules/controller_annotations_test/src/Controller/SecurityController.php @@ -74,8 +74,8 @@ public function csrfAction() { } /** - * @param AccountInterface $account - * @return AccessResult + * @param \Drupal\Core\Session\AccountInterface $account + * @return \Drupal\Core\Access\AccessResult */ public function access(AccountInterface $account) { return AccessResult::allowedIf($account->id() === 1337); diff --git a/tests/modules/controller_annotations_test/src/Security/Custom.php b/tests/modules/controller_annotations_test/src/Security/Custom.php index 892c1a8..b039a62 100644 --- a/tests/modules/controller_annotations_test/src/Security/Custom.php +++ b/tests/modules/controller_annotations_test/src/Security/Custom.php @@ -8,8 +8,8 @@ class Custom { /** - * @param AccountInterface $account - * @return AccessResult + * @param \Drupal\Core\Session\AccountInterface $account + * @return \Drupal\Core\Access\AccessResult */ public function access(AccountInterface $account) { return AccessResult::allowedIf($account->id() === 1337); diff --git a/tests/src/Kernel/DrupalTestKernel.php b/tests/src/Kernel/DrupalTestKernel.php index bba03b4..cc82c48 100644 --- a/tests/src/Kernel/DrupalTestKernel.php +++ b/tests/src/Kernel/DrupalTestKernel.php @@ -18,7 +18,7 @@ public function setSitePath($path) { } /** - * @param Request $request + * @param \Symfony\Component\HttpFoundation\Request $request */ protected function initializeSettings(Request $request) { $settings = Settings::getAll(); diff --git a/tests/src/Kernel/KernelTestBase.php b/tests/src/Kernel/KernelTestBase.php index c47ef4d..f0d5711 100644 --- a/tests/src/Kernel/KernelTestBase.php +++ b/tests/src/Kernel/KernelTestBase.php @@ -14,7 +14,7 @@ abstract class KernelTestBase extends BaseKernelTestBase { /** - * @var DrupalKernel + * @var \Drupal\Core\DrupalKernel */ protected $kernel; @@ -24,7 +24,7 @@ abstract class KernelTestBase extends BaseKernelTestBase { public static $modules = ['controller_annotations', 'controller_annotations_test', 'user', 'system', 'node']; /** - * @param Request $request + * @param \Symfony\Component\HttpFoundation\Request $request * @param $contents */ protected function assertResponseContents(Request $request, $contents) { @@ -43,7 +43,7 @@ protected function assertResponseContents(Request $request, $contents) { } /** - * @param Request $request + * @param \Symfony\Component\HttpFoundation\Request $request * @param $contents */ protected function assertResponseContains(Request $request, $contents) { @@ -53,7 +53,7 @@ protected function assertResponseContains(Request $request, $contents) { } /** - * @param Request $request + * @param \Symfony\Component\HttpFoundation\Request $request * @param $contents */ protected function assertResponseNotContains(Request $request, $contents) { @@ -62,7 +62,7 @@ protected function assertResponseNotContains(Request $request, $contents) { } /** - * @param Request $request + * @param \Symfony\Component\HttpFoundation\Request $request */ protected function assertNotFound(Request $request) { $response = $this->request($request); @@ -70,7 +70,7 @@ protected function assertNotFound(Request $request) { } /** - * @param Request $request + * @param \Symfony\Component\HttpFoundation\Request $request */ protected function assertMethodNotAllowed(Request $request) { $response = $this->request($request); @@ -78,7 +78,7 @@ protected function assertMethodNotAllowed(Request $request) { } /** - * @param Request $request + * @param \Symfony\Component\HttpFoundation\Request $request */ protected function assertForbidden(Request $request) { $response = $this->request($request); @@ -86,15 +86,15 @@ protected function assertForbidden(Request $request) { } /** - * @param Request $request + * @param \Symfony\Component\HttpFoundation\Request $request */ protected function assertTitleStartsWith(Request $request, $title) { $this->assertResponseContains($request, '<title>'.$title); } /** - * @param Request $request - * @return Response + * @param \Symfony\Component\HttpFoundation\Request $request + * @return \Symfony\Component\HttpFoundation\Response */ protected function request(Request $request) { if (empty($this->kernel)) { @@ -132,7 +132,7 @@ protected function setAdministratorAccount() { } /** - * @param AccountInterface $account + * @param \Drupal\Core\Session\AccountInterface $account */ protected function setAccount(AccountInterface $account) { $this->kernel->getContainer()->get('current_user')->setAccount($account); diff --git a/tests/src/Unit/Cache/DrupalCacheTest.php b/tests/src/Unit/Cache/DrupalCacheTest.php index fc305e4..b63d21c 100644 --- a/tests/src/Unit/Cache/DrupalCacheTest.php +++ b/tests/src/Unit/Cache/DrupalCacheTest.php @@ -67,7 +67,7 @@ public function testGetStats() { } /** - * @return CacheBackendInterface + * @return \Drupal\Core\Cache\CacheBackendInterface */ protected function getDrupalCacheMock() { $drupalCache = m::mock(CacheBackendInterface::class); @@ -79,7 +79,7 @@ protected function getDrupalCacheMock() { /** * @param $data * - * @return StdClass + * @return \StdClass */ protected function getCacheData($data) { $cacheData = new StdClass(); diff --git a/tests/src/Unit/EventSubscriber/RouteEventSubscriberTest.php b/tests/src/Unit/EventSubscriber/RouteEventSubscriberTest.php index 348e888..dae9eb7 100644 --- a/tests/src/Unit/EventSubscriber/RouteEventSubscriberTest.php +++ b/tests/src/Unit/EventSubscriber/RouteEventSubscriberTest.php @@ -16,17 +16,17 @@ class RouteEventSubscriberTest extends UnitTestCase { /** - * @var RouteCollection + * @var \Symfony\Component\Routing\RouteCollection */ protected $routeCollection; /** - * @var RouteCollection + * @var \Symfony\Component\Routing\RouteCollection */ protected $annotatedRouteCollection; /** - * @var RouteEventSubscriber + * @var \Drupal\controller_annotations\EventSubscriber\RouteEventSubscriber */ protected $eventSubscriber; @@ -38,7 +38,7 @@ protected function setUpEventSubscriber() { } /** - * @return RouteCollection + * @return \Symfony\Component\Routing\RouteCollection */ protected function getRouteCollection() { if (empty($this->routeCollection)) { @@ -49,7 +49,7 @@ protected function getRouteCollection() { } /** - * @return RouteCollection + * @return \Symfony\Component\Routing\RouteCollection */ protected function getAnnotatedRouteCollection() { if (empty($this->annotatedRouteCollection)) { diff --git a/tests/src/Unit/Templating/TemplateResolverTest.php b/tests/src/Unit/Templating/TemplateResolverTest.php index 6ec34f8..8e9435e 100644 --- a/tests/src/Unit/Templating/TemplateResolverTest.php +++ b/tests/src/Unit/Templating/TemplateResolverTest.php @@ -13,7 +13,7 @@ class TemplateResolverTest extends UnitTestCase { /** - * @var TemplateResolver + * @var \Drupal\controller_annotations\Templating\TemplateResolver */ private $templateResolver; From b5ea94c7c1ad8020cbec1d5afa0e70005876b94d Mon Sep 17 00:00:00 2001 From: Andreas Hennings <andreas@dqxtech.net> Date: Sat, 11 Jan 2020 22:12:16 +0100 Subject: [PATCH 09/23] (CS) (doc) Standardize param description in docs. --- src/Configuration/Cache.php | 12 ++++++++---- src/Configuration/Method.php | 6 ++++-- src/Configuration/ParamConverter.php | 15 ++++++++++----- src/Configuration/Template.php | 9 ++++++--- .../ParamConverterEventSubscriber.php | 9 ++++++--- src/EventSubscriber/TemplateEventSubscriber.php | 3 ++- .../ParamConverter/ParamConverterInterface.php | 9 ++++++--- .../ParamConverter/ParamConverterManager.php | 9 ++++++--- 8 files changed, 48 insertions(+), 24 deletions(-) diff --git a/src/Configuration/Cache.php b/src/Configuration/Cache.php index 98134a0..49b6dea 100644 --- a/src/Configuration/Cache.php +++ b/src/Configuration/Cache.php @@ -70,7 +70,8 @@ public function getExpires() { /** * Sets the expiration date for the Expires header field. * - * @param string $expires A valid php date + * @param string $expires + * A valid php date. */ public function setExpires($expires) { $this->expires = $expires; @@ -79,7 +80,8 @@ public function setExpires($expires) { /** * Sets the number of seconds for the max-age cache-control header field. * - * @param int $maxage A number of seconds + * @param int $maxage + * A number of seconds. */ public function setMaxAge($maxage) { $this->maxage = $maxage; @@ -98,7 +100,8 @@ public function getMaxAge() { /** * Sets the number of seconds for the s-maxage cache-control header field. * - * @param int $smaxage A number of seconds + * @param int $smaxage + * A number of seconds. */ public function setSMaxAge($smaxage) { $this->smaxage = $smaxage; @@ -135,7 +138,8 @@ public function isPrivate() { /** * Sets a response public. * - * @param bool $public A boolean value + * @param bool $public + * A boolean value. */ public function setPublic($public) { $this->public = (bool)$public; diff --git a/src/Configuration/Method.php b/src/Configuration/Method.php index c1d7995..a560d1a 100644 --- a/src/Configuration/Method.php +++ b/src/Configuration/Method.php @@ -28,7 +28,8 @@ public function getMethods() { /** * Sets the HTTP methods. * - * @param array|string $methods An HTTP method or an array of HTTP methods + * @param array|string $methods + * An HTTP method or an array of HTTP methods. */ public function setMethods($methods) { $this->methods = is_array($methods) ? $methods : array($methods); @@ -37,7 +38,8 @@ public function setMethods($methods) { /** * Sets the HTTP methods. * - * @param array|string $methods An HTTP method or an array of HTTP methods + * @param array|string $methods + * An HTTP method or an array of HTTP methods. */ public function setValue($methods) { $this->setMethods($methods); diff --git a/src/Configuration/ParamConverter.php b/src/Configuration/ParamConverter.php index e9bd53b..4549bb3 100644 --- a/src/Configuration/ParamConverter.php +++ b/src/Configuration/ParamConverter.php @@ -57,7 +57,8 @@ public function getName() { /** * Sets the parameter name. * - * @param string $name The parameter name + * @param string $name + * The parameter name. */ public function setValue($name) { $this->setName($name); @@ -66,7 +67,8 @@ public function setValue($name) { /** * Sets the parameter name. * - * @param string $name The parameter name + * @param string $name + * The parameter name. */ public function setName($name) { $this->name = $name; @@ -84,7 +86,8 @@ public function getClass() { /** * Sets the parameter class name. * - * @param string $class The parameter class name + * @param string $class + * The parameter class name. */ public function setClass($class) { $this->class = $class; @@ -102,7 +105,8 @@ public function getOptions() { /** * Sets an array of options. * - * @param array $options An array of options + * @param array $options + * An array of options. */ public function setOptions($options) { $this->options = $options; @@ -111,7 +115,8 @@ public function setOptions($options) { /** * Sets whether or not the parameter is optional. * - * @param bool $optional Whether the parameter is optional + * @param bool $optional + * Whether the parameter is optional. */ public function setIsOptional($optional) { $this->optional = (bool)$optional; diff --git a/src/Configuration/Template.php b/src/Configuration/Template.php index 69978d9..59b8f41 100644 --- a/src/Configuration/Template.php +++ b/src/Configuration/Template.php @@ -61,7 +61,8 @@ public function isStreamable() { /** * Sets the template variables. * - * @param array $vars The template variables + * @param array $vars + * The template variables. */ public function setVars($vars) { $this->vars = $vars; @@ -70,7 +71,8 @@ public function setVars($vars) { /** * Sets the template logic name. * - * @param string $template The template logic name + * @param string $template + * The template logic name. */ public function setValue($template) { $this->setTemplate($template); @@ -88,7 +90,8 @@ public function getTemplate() { /** * Sets the template reference. * - * @param string $template The template reference + * @param string $template + * The template reference. */ public function setTemplate($template) { $this->template = $template; diff --git a/src/EventSubscriber/ParamConverterEventSubscriber.php b/src/EventSubscriber/ParamConverterEventSubscriber.php index a8efe25..b2ed993 100644 --- a/src/EventSubscriber/ParamConverterEventSubscriber.php +++ b/src/EventSubscriber/ParamConverterEventSubscriber.php @@ -27,8 +27,10 @@ class ParamConverterEventSubscriber implements EventSubscriberInterface { private $isParameterTypeSupported; /** - * @param \Drupal\controller_annotations\Configuration\ParamConverterManager $manager A ParamConverterManager instance - * @param bool $autoConvert Auto convert non-configured objects + * @param \Drupal\controller_annotations\Configuration\ParamConverterManager $manager + * A ParamConverterManager instance. + * @param bool $autoConvert + * Auto convert non-configured objects. */ public function __construct(ParamConverterManager $manager, $autoConvert = TRUE) { $this->manager = $manager; @@ -39,7 +41,8 @@ public function __construct(ParamConverterManager $manager, $autoConvert = TRUE) /** * Modifies the ParamConverterManager instance. * - * @param \Symfony\Component\HttpKernel\Event\FilterControllerEvent $event A FilterControllerEvent instance + * @param \Symfony\Component\HttpKernel\Event\FilterControllerEvent $event + * A FilterControllerEvent instance. */ public function onKernelController(FilterControllerEvent $event) { $controller = $event->getController(); diff --git a/src/EventSubscriber/TemplateEventSubscriber.php b/src/EventSubscriber/TemplateEventSubscriber.php index 17f277d..5188c96 100644 --- a/src/EventSubscriber/TemplateEventSubscriber.php +++ b/src/EventSubscriber/TemplateEventSubscriber.php @@ -38,7 +38,8 @@ public function __construct(\Twig_Environment $twig, TemplateResolver $resolver) * Guesses the template name to render and its variables and adds them to * the request object. * - * @param \Symfony\Component\HttpKernel\Event\FilterControllerEvent $event A FilterControllerEvent instance + * @param \Symfony\Component\HttpKernel\Event\FilterControllerEvent $event + * A FilterControllerEvent instance. */ public function onKernelController(FilterControllerEvent $event) { $template = $this->getTemplateFromRequest($event); diff --git a/src/Request/ParamConverter/ParamConverterInterface.php b/src/Request/ParamConverter/ParamConverterInterface.php index f546662..d713458 100644 --- a/src/Request/ParamConverter/ParamConverterInterface.php +++ b/src/Request/ParamConverter/ParamConverterInterface.php @@ -16,8 +16,10 @@ interface ParamConverterInterface { /** * Stores the object in the request. * - * @param \Symfony\Component\HttpFoundation\Request $request The request - * @param \Drupal\controller_annotations\Configuration\ParamConverter $configuration Contains the name, class and options of the object + * @param \Symfony\Component\HttpFoundation\Request $request + * The request. + * @param \Drupal\controller_annotations\Configuration\ParamConverter $configuration + * Contains the name, class and options of the object. * * @return bool True if the object has been successfully set, else false */ @@ -26,7 +28,8 @@ public function apply(Request $request, ParamConverter $configuration); /** * Checks if the object is supported. * - * @param \Drupal\controller_annotations\Configuration\ParamConverter $configuration Should be an instance of ParamConverter + * @param \Drupal\controller_annotations\Configuration\ParamConverter $configuration + * Should be an instance of ParamConverter. * * @return bool True if the object is supported, else false */ diff --git a/src/Request/ParamConverter/ParamConverterManager.php b/src/Request/ParamConverter/ParamConverterManager.php index 2699c24..783b1a7 100644 --- a/src/Request/ParamConverter/ParamConverterManager.php +++ b/src/Request/ParamConverter/ParamConverterManager.php @@ -109,9 +109,12 @@ protected function applyNamedConverter(Request $request, ParamConverter $configu * added converter will not be part of the iteration chain and can only * be invoked explicitly. * - * @param \Drupal\controller_annotations\Configuration\ParamConverterInterface $converter A ParamConverterInterface instance - * @param int $priority The priority (between -10 and 10). - * @param string $name Name of the converter. + * @param \Drupal\controller_annotations\Configuration\ParamConverterInterface $converter + * A ParamConverterInterface instance. + * @param int $priority + * The priority (between -10 and 10). + * @param string $name + * Name of the converter. */ public function add(ParamConverterInterface $converter, $priority = 0, $name = NULL) { if ($priority !== NULL) { From 6633372256a08957e8955d46196c75eb9a1520a4 Mon Sep 17 00:00:00 2001 From: Andreas Hennings <andreas@dqxtech.net> Date: Sat, 11 Jan 2020 22:43:13 +0100 Subject: [PATCH 10/23] (CS) Add inline spaces. --- src/Configuration/Cache.php | 2 +- src/Configuration/ConfigurationAnnotation.php | 2 +- src/Configuration/ParamConverter.php | 2 +- src/Configuration/Template.php | 2 +- src/EventSubscriber/ControllerEventSubscriber.php | 6 +++--- src/EventSubscriber/RouteEventSubscriber.php | 2 +- .../src/Controller/ParamConverterController.php | 2 +- tests/src/Kernel/KernelTestBase.php | 2 +- tests/src/Unit/Templating/TemplateResolverTest.php | 2 +- tests/src/polyfill.php | 2 +- 10 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/Configuration/Cache.php b/src/Configuration/Cache.php index 49b6dea..3c58dee 100644 --- a/src/Configuration/Cache.php +++ b/src/Configuration/Cache.php @@ -142,7 +142,7 @@ public function isPrivate() { * A boolean value. */ public function setPublic($public) { - $this->public = (bool)$public; + $this->public = (bool) $public; } /** diff --git a/src/Configuration/ConfigurationAnnotation.php b/src/Configuration/ConfigurationAnnotation.php index 3432e22..1d0fc93 100644 --- a/src/Configuration/ConfigurationAnnotation.php +++ b/src/Configuration/ConfigurationAnnotation.php @@ -11,7 +11,7 @@ abstract class ConfigurationAnnotation implements ConfigurationInterface { public function __construct(array $values) { foreach ($values as $k => $v) { - if (!method_exists($this, $name = 'set'.$k)) { + if (!method_exists($this, $name = 'set' . $k)) { throw new \RuntimeException(sprintf('Unknown key "%s" for annotation "@%s".', $k, get_class($this))); } diff --git a/src/Configuration/ParamConverter.php b/src/Configuration/ParamConverter.php index 4549bb3..8ee3a08 100644 --- a/src/Configuration/ParamConverter.php +++ b/src/Configuration/ParamConverter.php @@ -119,7 +119,7 @@ public function setOptions($options) { * Whether the parameter is optional. */ public function setIsOptional($optional) { - $this->optional = (bool)$optional; + $this->optional = (bool) $optional; } /** diff --git a/src/Configuration/Template.php b/src/Configuration/Template.php index 59b8f41..adfdcf8 100644 --- a/src/Configuration/Template.php +++ b/src/Configuration/Template.php @@ -55,7 +55,7 @@ public function setIsStreamable($streamable) { * @return bool */ public function isStreamable() { - return (bool)$this->streamable; + return (bool) $this->streamable; } /** diff --git a/src/EventSubscriber/ControllerEventSubscriber.php b/src/EventSubscriber/ControllerEventSubscriber.php index c74720c..a1e2d13 100644 --- a/src/EventSubscriber/ControllerEventSubscriber.php +++ b/src/EventSubscriber/ControllerEventSubscriber.php @@ -110,10 +110,10 @@ protected function getConfigurations(array $annotations) { foreach ($annotations as $configuration) { if ($configuration instanceof ConfigurationInterface) { if ($configuration->allowArray()) { - $configurations['_'.$configuration->getAliasName()][] = $configuration; + $configurations['_' . $configuration->getAliasName()][] = $configuration; } - elseif (!isset($configurations['_'.$configuration->getAliasName()])) { - $configurations['_'.$configuration->getAliasName()] = $configuration; + elseif (!isset($configurations['_' . $configuration->getAliasName()])) { + $configurations['_' . $configuration->getAliasName()] = $configuration; } else { throw new \LogicException( diff --git a/src/EventSubscriber/RouteEventSubscriber.php b/src/EventSubscriber/RouteEventSubscriber.php index ec2991e..680b6aa 100644 --- a/src/EventSubscriber/RouteEventSubscriber.php +++ b/src/EventSubscriber/RouteEventSubscriber.php @@ -50,7 +50,7 @@ public function onRoutes(RouteBuildEvent $event) { if ($route->hasOption('type') && $route->getOption('type') === 'annotation' ) { - $routeCollection = $this->annotationDirectoryLoader->load($this->rootPath.$this->getRoutePath($route)); + $routeCollection = $this->annotationDirectoryLoader->load($this->rootPath . $this->getRoutePath($route)); $routeCollection->addPrefix($route->getPath()); $event->getRouteCollection()->addCollection($routeCollection); diff --git a/tests/modules/controller_annotations_test/src/Controller/ParamConverterController.php b/tests/modules/controller_annotations_test/src/Controller/ParamConverterController.php index 4589a09..948d38c 100644 --- a/tests/modules/controller_annotations_test/src/Controller/ParamConverterController.php +++ b/tests/modules/controller_annotations_test/src/Controller/ParamConverterController.php @@ -37,7 +37,7 @@ public function dateFormatAction(\DateTime $start) { * @ParamConverter */ public function dateMultipleAction(\DateTime $start, \DateTime $end) { - return new Response($start->format('Y-m-d').'-'.$end->format('Y-m-d')); + return new Response($start->format('Y-m-d') . '-' . $end->format('Y-m-d')); } /** diff --git a/tests/src/Kernel/KernelTestBase.php b/tests/src/Kernel/KernelTestBase.php index f0d5711..27293ee 100644 --- a/tests/src/Kernel/KernelTestBase.php +++ b/tests/src/Kernel/KernelTestBase.php @@ -89,7 +89,7 @@ protected function assertForbidden(Request $request) { * @param \Symfony\Component\HttpFoundation\Request $request */ protected function assertTitleStartsWith(Request $request, $title) { - $this->assertResponseContains($request, '<title>'.$title); + $this->assertResponseContains($request, '<title>' . $title); } /** diff --git a/tests/src/Unit/Templating/TemplateResolverTest.php b/tests/src/Unit/Templating/TemplateResolverTest.php index 8e9435e..79b9d22 100644 --- a/tests/src/Unit/Templating/TemplateResolverTest.php +++ b/tests/src/Unit/Templating/TemplateResolverTest.php @@ -5,7 +5,7 @@ use Drupal\controller_annotations\Templating\TemplateResolver; use Drupal\Tests\UnitTestCase; -require_once __DIR__.'/../../polyfill.php'; +require_once __DIR__ . '/../../polyfill.php'; /** * @group controller_annotations diff --git a/tests/src/polyfill.php b/tests/src/polyfill.php index bded969..d262810 100644 --- a/tests/src/polyfill.php +++ b/tests/src/polyfill.php @@ -5,7 +5,7 @@ function drupal_get_path($type, $name) { switch ($type) { case 'module': - return 'modules/'.$name; + return 'modules/' . $name; } throw new \LogicException( From b25dc03549043aabb30f0d81afd09c8a4d8045a5 Mon Sep 17 00:00:00 2001 From: Andreas Hennings <andreas@dqxtech.net> Date: Sat, 11 Jan 2020 22:46:41 +0100 Subject: [PATCH 11/23] (CS) Use short array syntax. --- src/Configuration/Method.php | 4 +- .../ControllerEventSubscriber.php | 2 +- .../ParamConverter/ParamConverterManager.php | 2 +- .../EventSubscriber/HttpCacheListenerTest.php | 44 +++++++++---------- .../ParamConverterManagerTest.php | 40 ++++++++--------- 5 files changed, 46 insertions(+), 46 deletions(-) diff --git a/src/Configuration/Method.php b/src/Configuration/Method.php index a560d1a..25c0a80 100644 --- a/src/Configuration/Method.php +++ b/src/Configuration/Method.php @@ -14,7 +14,7 @@ class Method extends ConfigurationAnnotation implements RouteModifierMethodInter * * @var array */ - protected $methods = array(); + protected $methods = []; /** * Returns the array of HTTP methods. @@ -32,7 +32,7 @@ public function getMethods() { * An HTTP method or an array of HTTP methods. */ public function setMethods($methods) { - $this->methods = is_array($methods) ? $methods : array($methods); + $this->methods = is_array($methods) ? $methods : [$methods]; } /** diff --git a/src/EventSubscriber/ControllerEventSubscriber.php b/src/EventSubscriber/ControllerEventSubscriber.php index a1e2d13..ce197a6 100644 --- a/src/EventSubscriber/ControllerEventSubscriber.php +++ b/src/EventSubscriber/ControllerEventSubscriber.php @@ -36,7 +36,7 @@ public function onKernelController(FilterControllerEvent $event) { $controller = $event->getController(); if (!is_array($controller) && method_exists($controller, '__invoke')) { - $controller = array($controller, '__invoke'); + $controller = [$controller, '__invoke']; } if (!is_array($controller)) { diff --git a/src/Request/ParamConverter/ParamConverterManager.php b/src/Request/ParamConverter/ParamConverterManager.php index 783b1a7..f349883 100644 --- a/src/Request/ParamConverter/ParamConverterManager.php +++ b/src/Request/ParamConverter/ParamConverterManager.php @@ -138,7 +138,7 @@ public function add(ParamConverterInterface $converter, $priority = 0, $name = N public function all() { krsort($this->converters); - $converters = array(); + $converters = []; foreach ($this->converters as $all) { $converters = array_merge($converters, $all); } diff --git a/tests/src/Unit/EventSubscriber/HttpCacheListenerTest.php b/tests/src/Unit/EventSubscriber/HttpCacheListenerTest.php index 3560610..e33679e 100644 --- a/tests/src/Unit/EventSubscriber/HttpCacheListenerTest.php +++ b/tests/src/Unit/EventSubscriber/HttpCacheListenerTest.php @@ -15,7 +15,7 @@ class HttpCacheListenerTest extends UnitTestCase { public function setUp() { $this->listener = new HttpCacheEventSubscriber(); $this->response = new Response(); - $this->cache = new Cache(array()); + $this->cache = new Cache([]); $this->request = $this->createRequest($this->cache); $this->event = $this->createEventMock($this->request, $this->response); } @@ -43,9 +43,9 @@ public function testWontReassignResponseWhenNoConfigurationIsPresent() { } public function testResponseIsPublicIfConfigurationIsPublicTrue() { - $request = $this->createRequest(new Cache(array( + $request = $this->createRequest(new Cache([ 'public' => TRUE, - ))); + ])); $this->listener->onKernelResponse($this->createEventMock($request, $this->response)); @@ -54,9 +54,9 @@ public function testResponseIsPublicIfConfigurationIsPublicTrue() { } public function testResponseIsPrivateIfConfigurationIsPublicFalse() { - $request = $this->createRequest(new Cache(array( + $request = $this->createRequest(new Cache([ 'public' => FALSE, - ))); + ])); $this->listener->onKernelResponse($this->createEventMock($request, $this->response)); @@ -65,8 +65,8 @@ public function testResponseIsPrivateIfConfigurationIsPublicFalse() { } public function testResponseVary() { - $vary = array('foobar'); - $request = $this->createRequest(new Cache(array('vary' => $vary))); + $vary = ['foobar']; + $request = $this->createRequest(new Cache(['vary' => $vary])); $this->listener->onKernelResponse($this->createEventMock($request, $this->response)); $this->assertTrue($this->response->hasVary()); @@ -75,8 +75,8 @@ public function testResponseVary() { } public function testResponseVaryWhenVaryNotSet() { - $request = $this->createRequest(new Cache(array())); - $vary = array('foobar'); + $request = $this->createRequest(new Cache([])); + $vary = ['foobar']; $this->response->setVary($vary); $this->listener->onKernelResponse($this->createEventMock($request, $this->response)); @@ -87,7 +87,7 @@ public function testResponseVaryWhenVaryNotSet() { } public function testResponseIsPrivateIfConfigurationIsPublicNotSet() { - $request = $this->createRequest(new Cache(array())); + $request = $this->createRequest(new Cache([])); $this->listener->onKernelResponse($this->createEventMock($request, $this->response)); @@ -99,11 +99,11 @@ public function testConfigurationAttributesAreSetOnResponse() { $this->assertInternalType('null', $this->response->getExpires()); $this->assertFalse($this->response->headers->hasCacheControlDirective('s-maxage')); - $this->request->attributes->set('_cache', new Cache(array( + $this->request->attributes->set('_cache', new Cache([ 'expires' => 'tomorrow', 'smaxage' => '15', 'maxage' => '15', - ))); + ])); $this->listener->onKernelResponse($this->event); @@ -113,10 +113,10 @@ public function testConfigurationAttributesAreSetOnResponse() { } public function testCacheMaxAgeSupportsStrtotimeFormat() { - $this->request->attributes->set('_cache', new Cache(array( + $this->request->attributes->set('_cache', new Cache([ 'smaxage' => '1 day', 'maxage' => '1 day', - ))); + ])); $this->listener->onKernelResponse($this->event); @@ -125,9 +125,9 @@ public function testCacheMaxAgeSupportsStrtotimeFormat() { } public function testLastModifiedNotModifiedResponse() { - $request = $this->createRequest(new Cache(array('lastModified' => 'test.getDate()'))); + $request = $this->createRequest(new Cache(['lastModified' => 'test.getDate()'])); $request->attributes->set('test', new TestEntity()); - $request->headers->add(array('If-Modified-Since' => 'Fri, 23 Aug 2013 00:00:00 GMT')); + $request->headers->add(['If-Modified-Since' => 'Fri, 23 Aug 2013 00:00:00 GMT']); $listener = new HttpCacheEventSubscriber(); $controllerEvent = new FilterControllerEvent($this->getKernel(), function () { @@ -141,7 +141,7 @@ public function testLastModifiedNotModifiedResponse() { } public function testLastModifiedHeader() { - $request = $this->createRequest(new Cache(array('lastModified' => 'test.getDate()'))); + $request = $this->createRequest(new Cache(['lastModified' => 'test.getDate()'])); $request->attributes->set('test', new TestEntity()); $response = new Response(); @@ -162,9 +162,9 @@ public function testLastModifiedHeader() { } public function testETagNotModifiedResponse() { - $request = $this->createRequest(new Cache(array('etag' => 'test.getId()'))); + $request = $this->createRequest(new Cache(['etag' => 'test.getId()'])); $request->attributes->set('test', $entity = new TestEntity()); - $request->headers->add(array('If-None-Match' => sprintf('"%s"', hash('sha256', $entity->getId())))); + $request->headers->add(['If-None-Match' => sprintf('"%s"', hash('sha256', $entity->getId()))]); $listener = new HttpCacheEventSubscriber(); $controllerEvent = new FilterControllerEvent($this->getKernel(), function () { @@ -178,7 +178,7 @@ public function testETagNotModifiedResponse() { } public function testETagHeader() { - $request = $this->createRequest(new Cache(array('ETag' => 'test.getId()'))); + $request = $this->createRequest(new Cache(['ETag' => 'test.getId()'])); $request->attributes->set('test', $entity = new TestEntity()); $response = new Response(); @@ -199,9 +199,9 @@ public function testETagHeader() { } private function createRequest(Cache $cache = NULL) { - return new Request(array(), array(), array( + return new Request([], [], [ '_cache' => $cache, - )); + ]); } private function createEventMock(Request $request, Response $response) { diff --git a/tests/src/Unit/Request/ParamConverter/ParamConverterManagerTest.php b/tests/src/Unit/Request/ParamConverter/ParamConverterManagerTest.php index 39952bf..155b294 100644 --- a/tests/src/Unit/Request/ParamConverter/ParamConverterManagerTest.php +++ b/tests/src/Unit/Request/ParamConverter/ParamConverterManagerTest.php @@ -15,7 +15,7 @@ class ParamConverterManagerTest extends UnitTestCase { public function testPriorities() { $manager = new ParamConverterManager(); - $this->assertEquals(array(), $manager->all()); + $this->assertEquals([], $manager->all()); $high = $this->createParamConverterMock(); $low = $this->createParamConverterMock(); @@ -23,7 +23,7 @@ public function testPriorities() { $manager->add($low); $manager->add($high, 10); - $this->assertEquals(array($high, $low), $manager->all()); + $this->assertEquals([$high, $low], $manager->all()); } public function testApply() { @@ -50,11 +50,11 @@ public function testApply() { ->method('apply') ; - $configurations = array( - new Configuration\ParamConverter(array( + $configurations = [ + new Configuration\ParamConverter([ 'name' => 'var', - )), - ); + ]), + ]; $manager = new ParamConverterManager(); $manager->add($supported); @@ -78,15 +78,15 @@ public function testApplyNamedConverter() { $request = new Request(); $request->attributes->set('param', '1234'); - $configuration = new Configuration\ParamConverter(array( + $configuration = new Configuration\ParamConverter([ 'name' => 'param', 'class' => 'stdClass', 'converter' => 'test', - )); + ]); $manager = new ParamConverterManager(); $manager->add($converter, 0, 'test'); - $this->assertNull($manager->apply($request, array($configuration))); + $this->assertNull($manager->apply($request, [$configuration])); } /** @@ -104,15 +104,15 @@ public function testApplyNamedConverterNotSupportsParameter() { $request = new Request(); $request->attributes->set('param', '1234'); - $configuration = new Configuration\ParamConverter(array( + $configuration = new Configuration\ParamConverter([ 'name' => 'param', 'class' => 'stdClass', 'converter' => 'test', - )); + ]); $manager = new ParamConverterManager(); $manager->add($converter, 0, 'test'); - $manager->apply($request, array($configuration)); + $manager->apply($request, [$configuration]); } /** @@ -123,14 +123,14 @@ public function testApplyNamedConverterNoConverter() { $request = new Request(); $request->attributes->set('param', '1234'); - $configuration = new Configuration\ParamConverter(array( + $configuration = new Configuration\ParamConverter([ 'name' => 'param', 'class' => 'stdClass', 'converter' => 'test', - )); + ]); $manager = new ParamConverterManager(); - $manager->apply($request, array($configuration)); + $manager->apply($request, [$configuration]); } public function testApplyNotCalledOnAlreadyConvertedObjects() { @@ -148,14 +148,14 @@ public function testApplyNotCalledOnAlreadyConvertedObjects() { $request = new Request(); $request->attributes->set('converted', new \stdClass()); - $configuration = new Configuration\ParamConverter(array( + $configuration = new Configuration\ParamConverter([ 'name' => 'converted', 'class' => 'stdClass', - )); + ]); $manager = new ParamConverterManager(); $manager->add($converter); - $manager->apply($request, array($configuration)); + $manager->apply($request, [$configuration]); } public function testApplyWithoutArray() { @@ -173,9 +173,9 @@ public function testApplyWithoutArray() { $request = new Request(); - $configuration = new Configuration\ParamConverter(array( + $configuration = new Configuration\ParamConverter([ 'name' => 'var', - )); + ]); $manager = new ParamConverterManager(); $manager->add($converter); From d0ec311734d247bbe7065ebc3922fa41713ed734 Mon Sep 17 00:00:00 2001 From: Andreas Hennings <andreas@dqxtech.net> Date: Sat, 11 Jan 2020 22:51:19 +0100 Subject: [PATCH 12/23] (CS) Fix line breaks in condition. --- src/Routing/AnnotatedRouteControllerLoader.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Routing/AnnotatedRouteControllerLoader.php b/src/Routing/AnnotatedRouteControllerLoader.php index cbea4fe..ea70b22 100644 --- a/src/Routing/AnnotatedRouteControllerLoader.php +++ b/src/Routing/AnnotatedRouteControllerLoader.php @@ -80,8 +80,9 @@ protected function setController(Route $route, \ReflectionClass $class, \Reflect */ protected function getControllerName(\ReflectionClass $class, \ReflectionMethod $method) { $annotation = $this->reader->getClassAnnotation($class, $this->routeAnnotationClass); - if ($annotation instanceof \Drupal\controller_annotations\Configuration\Route && $service = $annotation->getService( - )) { + if ($annotation instanceof \Drupal\controller_annotations\Configuration\Route + && $service = $annotation->getService() + ) { return sprintf('%s:%s', $service, $method->getName()); } From ee4c1445ea7d4b0c37ebf2df08ad537455f65502 Mon Sep 17 00:00:00 2001 From: Andreas Hennings <andreas@dqxtech.net> Date: Sat, 11 Jan 2020 22:52:42 +0100 Subject: [PATCH 13/23] (CS) (doc) Add blank lines within docs. --- src/EventSubscriber/ControllerEventSubscriber.php | 1 + src/EventSubscriber/TemplateEventSubscriber.php | 1 + src/Templating/TemplateResolver.php | 2 ++ 3 files changed, 4 insertions(+) diff --git a/src/EventSubscriber/ControllerEventSubscriber.php b/src/EventSubscriber/ControllerEventSubscriber.php index ce197a6..c774bc7 100644 --- a/src/EventSubscriber/ControllerEventSubscriber.php +++ b/src/EventSubscriber/ControllerEventSubscriber.php @@ -30,6 +30,7 @@ public function __construct(Reader $reader) { * configuration. * * @param \Symfony\Component\HttpKernel\Event\FilterControllerEvent $event + * * @throws \ReflectionException */ public function onKernelController(FilterControllerEvent $event) { diff --git a/src/EventSubscriber/TemplateEventSubscriber.php b/src/EventSubscriber/TemplateEventSubscriber.php index 5188c96..05f03d7 100644 --- a/src/EventSubscriber/TemplateEventSubscriber.php +++ b/src/EventSubscriber/TemplateEventSubscriber.php @@ -160,6 +160,7 @@ private function resolveDefaultParameters(Request $request, Template $template, * * @param \Symfony\Component\HttpFoundation\Request $request * @param array $arguments + * * @return array */ private function resolveParametersWithReflection(Request $request, array $arguments) { diff --git a/src/Templating/TemplateResolver.php b/src/Templating/TemplateResolver.php index c0ad203..1ee3196 100644 --- a/src/Templating/TemplateResolver.php +++ b/src/Templating/TemplateResolver.php @@ -14,6 +14,7 @@ class TemplateResolver { * * @param string $controllerClass * @param string $action + * * @return string */ public function resolveByControllerAndAction(string $controllerClass, string $action): string { @@ -47,6 +48,7 @@ public function resolveByControllerAndAction(string $controllerClass, string $ac * "modules/<module>/templates/<module>-<controller>(-<action>).html.twig" * * @param string $template + * * @return string */ public function normalize(string $template): string { From 47d1df535174df313a17c1c7020bebed8ee50bbb Mon Sep 17 00:00:00 2001 From: Andreas Hennings <andreas@dqxtech.net> Date: Sat, 11 Jan 2020 22:55:02 +0100 Subject: [PATCH 14/23] (CS) Semicolon on same line. --- .../EventSubscriber/HttpCacheListenerTest.php | 12 +++---- .../ParamConverterManagerTest.php | 33 +++++++------------ 2 files changed, 15 insertions(+), 30 deletions(-) diff --git a/tests/src/Unit/EventSubscriber/HttpCacheListenerTest.php b/tests/src/Unit/EventSubscriber/HttpCacheListenerTest.php index e33679e..faf5769 100644 --- a/tests/src/Unit/EventSubscriber/HttpCacheListenerTest.php +++ b/tests/src/Unit/EventSubscriber/HttpCacheListenerTest.php @@ -23,8 +23,7 @@ public function setUp() { public function testWontReassignResponseWhenResponseIsUnsuccessful() { $this->event ->expects($this->never()) - ->method('setResponse') - ; + ->method('setResponse'); $this->response->setStatusCode(500); @@ -34,8 +33,7 @@ public function testWontReassignResponseWhenResponseIsUnsuccessful() { public function testWontReassignResponseWhenNoConfigurationIsPresent() { $this->event ->expects($this->never()) - ->method('setResponse') - ; + ->method('setResponse'); $this->request->attributes->remove('_cache'); @@ -212,14 +210,12 @@ private function createEventMock(Request $request, Response $response) { $event ->expects($this->any()) ->method('getRequest') - ->will($this->returnValue($request)) - ; + ->will($this->returnValue($request)); $event ->expects($this->any()) ->method('getResponse') - ->will($this->returnValue($response)) - ; + ->will($this->returnValue($response)); return $event; } diff --git a/tests/src/Unit/Request/ParamConverter/ParamConverterManagerTest.php b/tests/src/Unit/Request/ParamConverter/ParamConverterManagerTest.php index 155b294..e52237f 100644 --- a/tests/src/Unit/Request/ParamConverter/ParamConverterManagerTest.php +++ b/tests/src/Unit/Request/ParamConverter/ParamConverterManagerTest.php @@ -31,24 +31,20 @@ public function testApply() { $supported ->expects($this->once()) ->method('supports') - ->will($this->returnValue(TRUE)) - ; + ->will($this->returnValue(TRUE)); $supported ->expects($this->once()) ->method('apply') - ->will($this->returnValue(FALSE)) - ; + ->will($this->returnValue(FALSE)); $invalid = $this->createParamConverterMock(); $invalid ->expects($this->once()) ->method('supports') - ->will($this->returnValue(FALSE)) - ; + ->will($this->returnValue(FALSE)); $invalid ->expects($this->never()) - ->method('apply') - ; + ->method('apply'); $configurations = [ new Configuration\ParamConverter([ @@ -67,13 +63,11 @@ public function testApplyNamedConverter() { $converter ->expects($this->any()) ->method('supports') - ->will($this->returnValue(TRUE)) - ; + ->will($this->returnValue(TRUE)); $converter ->expects($this->any()) - ->method('apply') - ; + ->method('apply'); $request = new Request(); $request->attributes->set('param', '1234'); @@ -98,8 +92,7 @@ public function testApplyNamedConverterNotSupportsParameter() { $converter ->expects($this->any()) ->method('supports') - ->will($this->returnValue(FALSE)) - ; + ->will($this->returnValue(FALSE)); $request = new Request(); $request->attributes->set('param', '1234'); @@ -137,13 +130,11 @@ public function testApplyNotCalledOnAlreadyConvertedObjects() { $converter = $this->createParamConverterMock(); $converter ->expects($this->never()) - ->method('supports') - ; + ->method('supports'); $converter ->expects($this->never()) - ->method('apply') - ; + ->method('apply'); $request = new Request(); $request->attributes->set('converted', new \stdClass()); @@ -163,13 +154,11 @@ public function testApplyWithoutArray() { $converter ->expects($this->any()) ->method('supports') - ->will($this->returnValue(FALSE)) - ; + ->will($this->returnValue(FALSE)); $converter ->expects($this->never()) - ->method('apply') - ; + ->method('apply'); $request = new Request(); From 628aad8e61e0c3e1f939dd8a8fcf9860babfcd1e Mon Sep 17 00:00:00 2001 From: Andreas Hennings <andreas@dqxtech.net> Date: Sat, 11 Jan 2020 22:56:43 +0100 Subject: [PATCH 15/23] (CS) Comma after last array element. --- tests/src/Kernel/AnnotationsTest.php | 10 +++++----- tests/src/Kernel/KernelTestBase.php | 4 ++-- tests/src/Unit/Configuration/SecurityTest.php | 4 ++-- tests/src/Unit/Configuration/TitleTest.php | 4 ++-- .../ControllerEventSubscriberTest.php | 14 +++++++------- .../TemplateEventSubscriberTest.php | 2 +- .../Routing/AnnotatedRouteControllerLoaderTest.php | 2 +- 7 files changed, 20 insertions(+), 20 deletions(-) diff --git a/tests/src/Kernel/AnnotationsTest.php b/tests/src/Kernel/AnnotationsTest.php index 8b3fa89..2dd6c73 100644 --- a/tests/src/Kernel/AnnotationsTest.php +++ b/tests/src/Kernel/AnnotationsTest.php @@ -81,12 +81,12 @@ public function testSecurity() { $this->assertForbidden(Request::create('/test/security/permission')); $this->setAccount(new UserSession([ 'uid' => 2, - 'permissions' => ['foo'] + 'permissions' => ['foo'], ])); $this->assertForbidden(Request::create('/test/security/permission')); $this->setAccount(new UserSession([ 'uid' => 2, - 'permissions' => ['access content'] + 'permissions' => ['access content'], ])); $this->assertResponseContents(Request::create('/test/security/permission'), 'OK'); @@ -109,7 +109,7 @@ public function testSecurity() { $this->setAdministratorAccount(); $this->assertForbidden(Request::create('/test/security/custom')); $this->setAccount(new UserSession([ - 'uid' => 1337 + 'uid' => 1337, ])); $this->assertResponseContents(Request::create('/test/security/custom'), 'OK'); @@ -121,14 +121,14 @@ public function testSecurity() { $this->setAdministratorAccount(); $this->assertForbidden(Request::create('/test/security/custom-inline')); $this->setAccount(new UserSession([ - 'uid' => 1337 + 'uid' => 1337, ])); $this->assertResponseContents(Request::create('/test/security/custom-inline'), 'OK'); // csrf $this->assertForbidden(Request::create('/test/security/csrf')); $this->assertResponseContents(Request::create('/test/security/csrf', 'GET', [ - 'token' => $this->kernel->getContainer()->get('csrf_token')->get('test/security/csrf') + 'token' => $this->kernel->getContainer()->get('csrf_token')->get('test/security/csrf'), ]), 'OK'); } diff --git a/tests/src/Kernel/KernelTestBase.php b/tests/src/Kernel/KernelTestBase.php index 27293ee..67b5bdf 100644 --- a/tests/src/Kernel/KernelTestBase.php +++ b/tests/src/Kernel/KernelTestBase.php @@ -117,7 +117,7 @@ protected function setAnonymousAccount() { protected function setAuthenticatedAccount() { $this->setAccount(new UserSession([ 'uid' => 2, - 'roles' => ['authenticated'] + 'roles' => ['authenticated'], ])); } @@ -127,7 +127,7 @@ protected function setAuthenticatedAccount() { protected function setAdministratorAccount() { $this->setAccount(new UserSession([ 'uid' => 1, - 'roles' => ['administrator', 'authenticated'] + 'roles' => ['administrator', 'authenticated'], ])); } diff --git a/tests/src/Unit/Configuration/SecurityTest.php b/tests/src/Unit/Configuration/SecurityTest.php index 3ac698c..e1217c5 100644 --- a/tests/src/Unit/Configuration/SecurityTest.php +++ b/tests/src/Unit/Configuration/SecurityTest.php @@ -27,7 +27,7 @@ public function testModifyRouteMethod() { 'role' => 'role', 'entity' => 'entity', 'csrf' => TRUE, - 'custom' => 'foo::custom' + 'custom' => 'foo::custom', ]); $this->assertNull($security->modifyRouteMethod($route, $class, $method)); @@ -44,7 +44,7 @@ public function testModifyRouteMethodInlineAccess() { $method = m::mock(\ReflectionMethod::class); $security = new Security([ - 'custom' => 'custom' + 'custom' => 'custom', ]); $this->assertNull($security->modifyRouteMethod($route, $class, $method)); diff --git a/tests/src/Unit/Configuration/TitleTest.php b/tests/src/Unit/Configuration/TitleTest.php index 715c880..8fb9689 100644 --- a/tests/src/Unit/Configuration/TitleTest.php +++ b/tests/src/Unit/Configuration/TitleTest.php @@ -23,7 +23,7 @@ public function testModifyRouteMethod() { 'value' => 'Hello World', 'arguments' => ['arguments' => TRUE], 'context' => ['context' => TRUE], - 'callback' => 'foo::callback' + 'callback' => 'foo::callback', ]); $this->assertNull($security->modifyRouteMethod($route, $class, $method)); @@ -40,7 +40,7 @@ public function testModifyRouteMethodInlineAccess() { $method = m::mock(\ReflectionMethod::class); $security = new Title([ - 'callback' => 'callback' + 'callback' => 'callback', ]); $this->assertNull($security->modifyRouteClass($route, $class, $method)); diff --git a/tests/src/Unit/EventSubscriber/ControllerEventSubscriberTest.php b/tests/src/Unit/EventSubscriber/ControllerEventSubscriberTest.php index f674903..f56558f 100644 --- a/tests/src/Unit/EventSubscriber/ControllerEventSubscriberTest.php +++ b/tests/src/Unit/EventSubscriber/ControllerEventSubscriberTest.php @@ -49,7 +49,7 @@ public function testMultipleConfigurations() { $reader = m::mock(Reader::class); $reader->shouldReceive('getClassAnnotations')->andReturn([ $configuration, - $configuration + $configuration, ]); $reader->shouldReceive('getMethodAnnotations')->andReturn([]); @@ -64,10 +64,10 @@ public function testMultipleConfigurations() { public function testMergeConfigurations() { $classConfigurations = [ - 'foo' => 'bar' + 'foo' => 'bar', ]; $methodConfigurations = [ - 'foo' => 'bar' + 'foo' => 'bar', ]; $reader = m::mock(Reader::class); @@ -79,10 +79,10 @@ public function testMergeConfigurations() { public function testMergeConfigurationsArray() { $classConfigurations = [ - 'foo' => ['bar'] + 'foo' => ['bar'], ]; $methodConfigurations = [ - 'foo' => ['baz'] + 'foo' => ['baz'], ]; $reader = m::mock(Reader::class); @@ -97,10 +97,10 @@ public function testMergeConfigurationsMismatch() { $this->setExpectedException(\UnexpectedValueException::class); $classConfigurations = [ - 'foo' => ['bar'] + 'foo' => ['bar'], ]; $methodConfigurations = [ - 'foo' => 'bar' + 'foo' => 'bar', ]; $reader = m::mock(Reader::class); diff --git a/tests/src/Unit/EventSubscriber/TemplateEventSubscriberTest.php b/tests/src/Unit/EventSubscriber/TemplateEventSubscriberTest.php index b2f427f..4f27c42 100644 --- a/tests/src/Unit/EventSubscriber/TemplateEventSubscriberTest.php +++ b/tests/src/Unit/EventSubscriber/TemplateEventSubscriberTest.php @@ -92,7 +92,7 @@ public function testOnKernelControllerWithTemplateName() { $templateResolver->shouldReceive('normalize')->once()->andReturn($templateName); $template = new Template([ - 'template' => $templateName + 'template' => $templateName, ]); $request = new Request(); diff --git a/tests/src/Unit/Routing/AnnotatedRouteControllerLoaderTest.php b/tests/src/Unit/Routing/AnnotatedRouteControllerLoaderTest.php index ed7dd39..6bce74a 100644 --- a/tests/src/Unit/Routing/AnnotatedRouteControllerLoaderTest.php +++ b/tests/src/Unit/Routing/AnnotatedRouteControllerLoaderTest.php @@ -31,7 +31,7 @@ public function testConfigureRoute() { $reader->shouldReceive('getClassAnnotation')->andReturn($routeConfiguration); $reader->shouldReceive('getMethodAnnotations')->andReturn([ $routeConfiguration, - $methodConfiguration + $methodConfiguration, ]); $reader->shouldReceive('getClassAnnotations')->andReturn([]); From a2facbcf3d3ffd6faca92a8cedbeb85292a583f1 Mon Sep 17 00:00:00 2001 From: Andreas Hennings <andreas@dqxtech.net> Date: Sat, 11 Jan 2020 22:57:59 +0100 Subject: [PATCH 16/23] (CS) Fix indentation. --- tests/src/Unit/EventSubscriber/HttpCacheListenerTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/src/Unit/EventSubscriber/HttpCacheListenerTest.php b/tests/src/Unit/EventSubscriber/HttpCacheListenerTest.php index faf5769..2d48502 100644 --- a/tests/src/Unit/EventSubscriber/HttpCacheListenerTest.php +++ b/tests/src/Unit/EventSubscriber/HttpCacheListenerTest.php @@ -53,8 +53,8 @@ public function testResponseIsPublicIfConfigurationIsPublicTrue() { public function testResponseIsPrivateIfConfigurationIsPublicFalse() { $request = $this->createRequest(new Cache([ - 'public' => FALSE, - ])); + 'public' => FALSE, + ])); $this->listener->onKernelResponse($this->createEventMock($request, $this->response)); From 847c05524c425a129f8b4ef7d7052b5791a57468 Mon Sep 17 00:00:00 2001 From: Andreas Hennings <andreas@dqxtech.net> Date: Sat, 11 Jan 2020 22:58:58 +0100 Subject: [PATCH 17/23] (CS) Parentheses after constructor call. --- .../EventSubscriber/ControllerEventSubscriberTest.php | 8 ++++---- .../src/Unit/EventSubscriber/RouteEventSubscriberTest.php | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/src/Unit/EventSubscriber/ControllerEventSubscriberTest.php b/tests/src/Unit/EventSubscriber/ControllerEventSubscriberTest.php index f56558f..dc36e43 100644 --- a/tests/src/Unit/EventSubscriber/ControllerEventSubscriberTest.php +++ b/tests/src/Unit/EventSubscriber/ControllerEventSubscriberTest.php @@ -35,8 +35,8 @@ public function testControllerInvoke() { $eventSubscriber = new ControllerEventSubscriber($reader); $event = m::mock(FilterControllerEvent::class); - $event->shouldReceive('getController')->once()->andReturn(new ControllerInvokableController); - $event->shouldReceive('getRequest')->once()->andReturn(new Request); + $event->shouldReceive('getController')->once()->andReturn(new ControllerInvokableController()); + $event->shouldReceive('getRequest')->once()->andReturn(new Request()); $this->assertNull($eventSubscriber->onKernelController($event)); } @@ -56,8 +56,8 @@ public function testMultipleConfigurations() { $eventSubscriber = new ControllerEventSubscriber($reader); $event = m::mock(FilterControllerEvent::class); - $event->shouldReceive('getController')->once()->andReturn(new ControllerInvokableController); - $event->shouldReceive('getRequest')->once()->andReturn(new Request); + $event->shouldReceive('getController')->once()->andReturn(new ControllerInvokableController()); + $event->shouldReceive('getRequest')->once()->andReturn(new Request()); $this->assertNull($eventSubscriber->onKernelController($event)); } diff --git a/tests/src/Unit/EventSubscriber/RouteEventSubscriberTest.php b/tests/src/Unit/EventSubscriber/RouteEventSubscriberTest.php index dae9eb7..f2ab9b0 100644 --- a/tests/src/Unit/EventSubscriber/RouteEventSubscriberTest.php +++ b/tests/src/Unit/EventSubscriber/RouteEventSubscriberTest.php @@ -42,7 +42,7 @@ protected function setUpEventSubscriber() { */ protected function getRouteCollection() { if (empty($this->routeCollection)) { - $this->routeCollection = new RouteCollection; + $this->routeCollection = new RouteCollection(); } return $this->routeCollection; @@ -53,7 +53,7 @@ protected function getRouteCollection() { */ protected function getAnnotatedRouteCollection() { if (empty($this->annotatedRouteCollection)) { - $this->annotatedRouteCollection = new RouteCollection; + $this->annotatedRouteCollection = new RouteCollection(); } return $this->annotatedRouteCollection; From f4a49cc6326f4b62f3a935c8f69c8028f5626422 Mon Sep 17 00:00:00 2001 From: Andreas Hennings <andreas@dqxtech.net> Date: Sat, 11 Jan 2020 23:02:39 +0100 Subject: [PATCH 18/23] (CS) Remove unused imports. --- src/Request/ParamConverter/ParamConverterManager.php | 1 - tests/src/Kernel/KernelTestBase.php | 1 - 2 files changed, 2 deletions(-) diff --git a/src/Request/ParamConverter/ParamConverterManager.php b/src/Request/ParamConverter/ParamConverterManager.php index f349883..854af0a 100644 --- a/src/Request/ParamConverter/ParamConverterManager.php +++ b/src/Request/ParamConverter/ParamConverterManager.php @@ -2,7 +2,6 @@ namespace Drupal\controller_annotations\Request\ParamConverter; -use Drupal\controller_annotations\Configuration\ConfigurationInterface; use Drupal\controller_annotations\Configuration\ParamConverter; use Symfony\Component\HttpFoundation\Request; diff --git a/tests/src/Kernel/KernelTestBase.php b/tests/src/Kernel/KernelTestBase.php index 67b5bdf..8272fca 100644 --- a/tests/src/Kernel/KernelTestBase.php +++ b/tests/src/Kernel/KernelTestBase.php @@ -2,7 +2,6 @@ namespace Drupal\Tests\controller_annotations\Kernel; -use Drupal\Core\DrupalKernel; use Drupal\Core\Session\AccountInterface; use Drupal\Core\Session\AnonymousUserSession; use Drupal\Tests\controller_annotations\Kernel\TestUserSession as UserSession; From 9bd45256f0300bf4a1e325e1af80767344b7ed85 Mon Sep 17 00:00:00 2001 From: Andreas Hennings <andreas@dqxtech.net> Date: Sat, 11 Jan 2020 23:02:53 +0100 Subject: [PATCH 19/23] (CS) Normalize imports order. --- tests/src/Kernel/KernelTestBase.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/src/Kernel/KernelTestBase.php b/tests/src/Kernel/KernelTestBase.php index 8272fca..8e89e5f 100644 --- a/tests/src/Kernel/KernelTestBase.php +++ b/tests/src/Kernel/KernelTestBase.php @@ -4,8 +4,8 @@ use Drupal\Core\Session\AccountInterface; use Drupal\Core\Session\AnonymousUserSession; -use Drupal\Tests\controller_annotations\Kernel\TestUserSession as UserSession; use Drupal\KernelTests\KernelTestBase as BaseKernelTestBase; +use Drupal\Tests\controller_annotations\Kernel\TestUserSession as UserSession; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\StreamedResponse; From 18c4add4d6c7e2bd46683ab3ddd32ed73fce29d7 Mon Sep 17 00:00:00 2001 From: Andreas Hennings <andreas@dqxtech.net> Date: Sat, 11 Jan 2020 23:11:16 +0100 Subject: [PATCH 20/23] (CS) (doc) throws tag on new line. --- src/Request/ParamConverter/DateTimeParamConverter.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Request/ParamConverter/DateTimeParamConverter.php b/src/Request/ParamConverter/DateTimeParamConverter.php index 242b85e..9252e48 100644 --- a/src/Request/ParamConverter/DateTimeParamConverter.php +++ b/src/Request/ParamConverter/DateTimeParamConverter.php @@ -17,7 +17,8 @@ class DateTimeParamConverter implements ParamConverterInterface { /** * {@inheritdoc} * - * @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException When invalid date given + * @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException + * When invalid date given. */ public function apply(Request $request, ParamConverter $configuration) { $param = $configuration->getName(); From 47bbb1430aa7ab015bb3664dacd355ac526e2a2b Mon Sep 17 00:00:00 2001 From: Andreas Hennings <andreas@dqxtech.net> Date: Sat, 11 Jan 2020 23:14:24 +0100 Subject: [PATCH 21/23] (CS) Remove commented-out leftover code. --- tests/src/Kernel/KernelTestBase.php | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/src/Kernel/KernelTestBase.php b/tests/src/Kernel/KernelTestBase.php index 8e89e5f..bf841df 100644 --- a/tests/src/Kernel/KernelTestBase.php +++ b/tests/src/Kernel/KernelTestBase.php @@ -47,7 +47,6 @@ protected function assertResponseContents(Request $request, $contents) { */ protected function assertResponseContains(Request $request, $contents) { $response = $this->request($request); - //echo $response->getContent(); $this->assertTrue(strpos($response->getContent(), $contents) !== FALSE); } From 72469a32b0e228305bb9c11fe99ffae92ca8fefd Mon Sep 17 00:00:00 2001 From: Andreas Hennings <andreas@dqxtech.net> Date: Sat, 11 Jan 2020 23:19:18 +0100 Subject: [PATCH 22/23] (CS) Explicit return NULL. --- src/Cache/DrupalCache.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Cache/DrupalCache.php b/src/Cache/DrupalCache.php index 1ad2c0d..8b6eaac 100644 --- a/src/Cache/DrupalCache.php +++ b/src/Cache/DrupalCache.php @@ -73,7 +73,7 @@ protected function doFlush() { * @inheritdoc */ protected function doGetStats() { - return; + return NULL; } } From 07fb7a5f0e7edb1522ebcc6432a88ab53f4ea774 Mon Sep 17 00:00:00 2001 From: Andreas Hennings <andreas@dqxtech.net> Date: Sat, 11 Jan 2020 23:21:22 +0100 Subject: [PATCH 23/23] Add phpcs.xml to suppress remaining inspections. --- phpcs.xml | 86 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 phpcs.xml diff --git a/phpcs.xml b/phpcs.xml new file mode 100644 index 0000000..8b8d8cc --- /dev/null +++ b/phpcs.xml @@ -0,0 +1,86 @@ +<?xml version="1.0"?> +<!-- + See http://pear.php.net/manual/en/package.php.php-codesniffer.annotated-ruleset.php + See https://github.com/squizlabs/PHP_CodeSniffer/wiki/Annotated-Ruleset +--> +<ruleset name="DrupalFeatures"> + <description>Drupal coding standard, relaxed for Features module</description> + + <!-- Inherit everything from "Drupal" coding standard. --> + <rule ref="Drupal"> + + <!-- Ignore violations that we don't intend to fix any time soon. --> + <!-- Let's not touch .txt files for now. --> + <exclude name="Drupal.Files.TxtFileLineLength.TooLong"/> + <!-- Let's not add native 'array' type hints for now. --> + <exclude name="Drupal.Commenting.FunctionComment.TypeHintMissing"/> + <exclude name="Drupal.Commenting.FunctionComment.ParamCommentFullStop"/> + <exclude name="Drupal.Commenting.DocComment.MissingShort"/> + <exclude name="Drupal.Commenting.InlineComment.NotCapital"/> + <exclude name="Drupal.Commenting.FunctionComment.MissingParamComment"/> + <exclude name="Drupal.Commenting.ClassComment.Missing"/> + <exclude name="Drupal.Commenting.InlineComment.InvalidEndChar"/> + <exclude name="Drupal.Commenting.DocComment.ShortFullStop"/> + <exclude name="Drupal.Commenting.DocComment.ShortNotCapital"/> + <exclude name="Drupal.NamingConventions.ValidFunctionName.ScopeNotCamelCaps"/> + <exclude name="Drupal.Commenting.DocComment.ShortSingleLine"/> + <exclude name="Drupal.Files.LineLength.TooLong"/> + <exclude name="Drupal.Arrays.Array.LongLineDeclaration"/> + <exclude name="Drupal.Commenting.VariableComment.Missing"/> + <exclude name="Drupal.Commenting.FileComment.Missing"/> + <!-- This would require a named alias, which we better avoid. --> + <exclude name="Drupal.Classes.FullyQualifiedNamespace.UseStatementMissing"/> + <!-- False positives for annotation classes. --> + <exclude name="Drupal.Classes.UnusedUseStatement.UnusedUse"/> + <!-- + <exclude name=""/> + <exclude name=""/> + <exclude name=""/> + --> + + <!-- add later! --> + <exclude name="Drupal.Commenting.FunctionComment.Missing"/> + <exclude name="Drupal.Commenting.FunctionComment.MissingReturnComment"/> + <exclude name="Drupal.Commenting.FunctionComment.MissingParamType"/> + <exclude name="Drupal.Commenting.DocComment.Empty"/> + <exclude name="Drupal.Commenting.FunctionComment.ParamMissingDefinition"/> + <!-- + <exclude name=""/> + <exclude name=""/> + <exclude name=""/> + <exclude name=""/> + <exclude name=""/> + <exclude name=""/> + <exclude name=""/> + --> + + <!-- Ignore some rules that produce false positives. --> + <!-- This rule expects the wrong indentation for multiline expressions as + array values. --> + <exclude name="Drupal.Arrays.Array.ArrayIndentation"/> + <!-- Some strings for l() should not be translated. --> + <exclude name="Drupal.Semantics.LStringTranslatable.LArg"/> + + <!-- More customizations for features. --> + + <!-- Ignore some rules by choice. --> + <!-- Inline @var docs for local variables are very useful. --> + <exclude name="Drupal.Commenting.InlineComment.DocBlock"/> + <!-- Class names like "What_How" are preferable to "HowWhat". --> + <exclude name="Drupal.NamingConventions.ValidClassName.NoUnderscores"/> + <!-- Param and return docs on hooks may be redundant, but they are empowering + for the IDE. --> + <exclude name="Drupal.Commenting.HookComment.HookParamDoc"/> + <exclude name="Drupal.Commenting.HookComment.HookReturnDoc"/> + </rule> + + <rule ref="Drupal.NamingConventions.ValidFunctionName.ScopeNotCamelCaps"> + <exclude-pattern>tests/features.test</exclude-pattern> + </rule> + + <rule ref="Drupal.Files.LineLength.TooLong"> + <!-- Two function docs have too long lines that cannot be shortened. --> + <exclude-pattern>includes/features.ctools.inc</exclude-pattern> + </rule> + +</ruleset>