diff --git a/src/Http/Literal.php b/src/Http/Literal.php index c05e153..3b8a18c 100644 --- a/src/Http/Literal.php +++ b/src/Http/Literal.php @@ -20,13 +20,6 @@ */ class Literal implements RouteInterface { - /** - * RouteInterface to match. - * - * @var string - */ - protected $route; - /** * Default values. * @@ -48,9 +41,13 @@ class Literal implements RouteInterface * @param string $route * @param array $defaults */ - public function __construct($route, array $defaults = []) - { - $this->route = $route; + public function __construct( + /** + * RouteInterface to match. + */ + protected $route, + array $defaults = [] + ) { $this->defaults = $defaults; } diff --git a/src/Http/Method.php b/src/Http/Method.php index 25f1ae7..17d8493 100644 --- a/src/Http/Method.php +++ b/src/Http/Method.php @@ -22,13 +22,6 @@ */ class Method implements RouteInterface { - /** - * Verb to match. - * - * @var string - */ - protected $verb; - /** * Default values. * @@ -50,9 +43,13 @@ class Method implements RouteInterface * @param string $verb * @param array $defaults */ - public function __construct($verb, array $defaults = []) - { - $this->verb = $verb; + public function __construct( + /** + * Verb to match. + */ + protected $verb, + array $defaults = [] + ) { $this->defaults = $defaults; } diff --git a/src/Http/Part.php b/src/Http/Part.php index 0334653..7cdf75c 100644 --- a/src/Http/Part.php +++ b/src/Http/Part.php @@ -32,13 +32,6 @@ class Part extends TreeRouteStack implements RouteInterface */ protected $route; - /** - * Whether the route may terminate. - * - * @var bool - */ - protected $mayTerminate; - /** * Child routes. * @@ -58,7 +51,10 @@ class Part extends TreeRouteStack implements RouteInterface */ public function __construct( $route, - $mayTerminate, + /** + * Whether the route may terminate. + */ + protected $mayTerminate, RoutePluginManager $routePlugins, ?array $childRoutes = null, ?ArrayObject $prototypes = null @@ -73,10 +69,9 @@ public function __construct( throw new Exception\InvalidArgumentException('Base route may not be a part route'); } - $this->route = $route; - $this->mayTerminate = $mayTerminate; - $this->childRoutes = $childRoutes; - $this->prototypes = $prototypes; + $this->route = $route; + $this->childRoutes = $childRoutes; + $this->prototypes = $prototypes; /** @var PriorityList $this->routes */ $this->routes = new PriorityList(); } diff --git a/src/Http/Placeholder.php b/src/Http/Placeholder.php index 1847b41..72802cd 100644 --- a/src/Http/Placeholder.php +++ b/src/Http/Placeholder.php @@ -17,8 +17,6 @@ */ class Placeholder implements RouteInterface { - private array $defaults; - /** * @internal * @deprecated Since 3.9.0 This property will be removed or made private in version 4.0 @@ -27,9 +25,8 @@ class Placeholder implements RouteInterface */ public $priority; - public function __construct(array $defaults) + public function __construct(private readonly array $defaults) { - $this->defaults = $defaults; } /** diff --git a/src/Http/Regex.php b/src/Http/Regex.php index dad19c3..b8669b3 100644 --- a/src/Http/Regex.php +++ b/src/Http/Regex.php @@ -19,22 +19,15 @@ use function rawurldecode; use function rawurlencode; use function sprintf; +use function str_contains; use function str_replace; use function strlen; -use function strpos; /** * Regex route. */ class Regex implements RouteInterface { - /** - * Regex to match. - * - * @var string - */ - protected $regex; - /** * Default values. * @@ -42,15 +35,6 @@ class Regex implements RouteInterface */ protected $defaults; - /** - * Specification for URL assembly. - * - * Parameters accepting substitutions should be denoted as "%key%" - * - * @var string - */ - protected $spec; - /** * List of assembled parameters. * @@ -73,10 +57,19 @@ class Regex implements RouteInterface * @param string $spec * @param array $defaults */ - public function __construct($regex, $spec, array $defaults = []) - { - $this->regex = $regex; - $this->spec = $spec; + public function __construct( + /** + * Regex to match. + */ + protected $regex, + /** + * Specification for URL assembly. + * + * Parameters accepting substitutions should be denoted as "%key%" + */ + protected $spec, + array $defaults = [] + ) { $this->defaults = $defaults; } @@ -171,7 +164,7 @@ public function assemble(array $params = [], array $options = []) foreach ($mergedParams as $key => $value) { $spec = '%' . $key . '%'; - if (strpos($url, $spec) !== false) { + if (str_contains($url, $spec)) { $url = str_replace($spec, rawurlencode((string) $value), $url); $this->assembledParams[] = $key; diff --git a/src/Http/RouteMatch.php b/src/Http/RouteMatch.php index 6bd7c9a..a33ef0c 100644 --- a/src/Http/RouteMatch.php +++ b/src/Http/RouteMatch.php @@ -13,24 +13,20 @@ */ class RouteMatch extends BaseRouteMatch { - /** - * Length of the matched path. - * - * @var int - */ - protected $length; - /** * Create a part RouteMatch with given parameters and length. * * @param array $params * @param int $length */ - public function __construct(array $params, $length = 0) - { + public function __construct( + array $params, + /** + * Length of the matched path. + */ + protected $length = 0 + ) { parent::__construct($params); - - $this->length = $length; } /** diff --git a/src/Http/Scheme.php b/src/Http/Scheme.php index 95a148e..36648fe 100644 --- a/src/Http/Scheme.php +++ b/src/Http/Scheme.php @@ -18,13 +18,6 @@ */ class Scheme implements RouteInterface { - /** - * Scheme to match. - * - * @var string - */ - protected $scheme; - /** * Default values. * @@ -46,9 +39,13 @@ class Scheme implements RouteInterface * @param string $scheme * @param array $defaults */ - public function __construct($scheme, array $defaults = []) - { - $this->scheme = $scheme; + public function __construct( + /** + * Scheme to match. + */ + protected $scheme, + array $defaults = [] + ) { $this->defaults = $defaults; } diff --git a/src/Http/TreeRouteStack.php b/src/Http/TreeRouteStack.php index 708f049..92aee7d 100644 --- a/src/Http/TreeRouteStack.php +++ b/src/Http/TreeRouteStack.php @@ -284,11 +284,7 @@ public function addPrototype($name, $route) */ public function getPrototype($name) { - if (isset($this->prototypes[$name])) { - return $this->prototypes[$name]; - } - - return null; + return $this->prototypes[$name] ?? null; } /** diff --git a/src/Http/Wildcard.php b/src/Http/Wildcard.php index 3dbe625..1787121 100644 --- a/src/Http/Wildcard.php +++ b/src/Http/Wildcard.php @@ -33,20 +33,6 @@ */ class Wildcard implements RouteInterface { - /** - * Delimiter between keys and values. - * - * @var string - */ - protected $keyValueDelimiter; - - /** - * Delimiter before parameters. - * - * @var string - */ - protected $paramDelimiter; - /** * Default values. * @@ -68,11 +54,18 @@ class Wildcard implements RouteInterface * @param string $paramDelimiter * @param array $defaults */ - public function __construct($keyValueDelimiter = '/', $paramDelimiter = '/', array $defaults = []) - { - $this->keyValueDelimiter = $keyValueDelimiter; - $this->paramDelimiter = $paramDelimiter; - $this->defaults = $defaults; + public function __construct( + /** + * Delimiter between keys and values. + */ + protected $keyValueDelimiter = '/', + /** + * Delimiter before parameters. + */ + protected $paramDelimiter = '/', + array $defaults = [] + ) { + $this->defaults = $defaults; } /** diff --git a/src/RouteInvokableFactory.php b/src/RouteInvokableFactory.php index 733488b..4042fe7 100644 --- a/src/RouteInvokableFactory.php +++ b/src/RouteInvokableFactory.php @@ -83,7 +83,7 @@ public function canCreateServiceWithName(ServiceLocatorInterface $container, $no */ public function __invoke(ContainerInterface $container, $routeName, ?array $options = null) { - $options = $options ?? []; + $options ??= []; if (! class_exists($routeName)) { throw new ServiceNotCreatedException(sprintf( @@ -134,7 +134,7 @@ public function createServiceWithName(ServiceLocatorInterface $container, $norma */ public function createService(ServiceLocatorInterface $container, $normalizedName = null, $routeName = null) { - $routeName = $routeName ?? RouteInterface::class; + $routeName ??= RouteInterface::class; return $this($container, $routeName, $this->creationOptions); } diff --git a/src/RoutePluginManager.php b/src/RoutePluginManager.php index ef1309b..6c543d8 100644 --- a/src/RoutePluginManager.php +++ b/src/RoutePluginManager.php @@ -11,8 +11,7 @@ use Psr\Container\ContainerInterface; use function array_merge; -use function gettype; -use function is_object; +use function get_debug_type; use function sprintf; /** @@ -81,7 +80,7 @@ public function validate(mixed $instance) if (! $instance instanceof $this->instanceOf) { throw new InvalidServiceException(sprintf( 'Plugin of type %s is invalid; must implement %s', - is_object($instance) ? $instance::class : gettype($instance), + get_debug_type($instance), RouteInterface::class )); } diff --git a/src/RoutePluginManagerFactory.php b/src/RoutePluginManagerFactory.php index f1576ba..3796091 100644 --- a/src/RoutePluginManagerFactory.php +++ b/src/RoutePluginManagerFactory.php @@ -19,7 +19,7 @@ class RoutePluginManagerFactory implements FactoryInterface */ public function __invoke(ContainerInterface $container, $name, ?array $options = null) { - $options = $options ?? []; + $options ??= []; return new RoutePluginManager($container, $options); } diff --git a/src/RouterFactory.php b/src/RouterFactory.php index 3de5af7..83aa972 100644 --- a/src/RouterFactory.php +++ b/src/RouterFactory.php @@ -37,7 +37,7 @@ public function __invoke(ContainerInterface $container, $name, ?array $options = */ public function createService(ServiceLocatorInterface $container, $normalizedName = null, $requestedName = null) { - $requestedName = $requestedName ?? 'Router'; + $requestedName ??= 'Router'; return $this($container, $requestedName); } } diff --git a/test/Http/TestAsset/DummyRouteWithParam.php b/test/Http/TestAsset/DummyRouteWithParam.php index d96579f..e6ae989 100644 --- a/test/Http/TestAsset/DummyRouteWithParam.php +++ b/test/Http/TestAsset/DummyRouteWithParam.php @@ -36,10 +36,6 @@ public function match(RequestInterface $request, $pathOffset = null) */ public function assemble(?array $params = null, ?array $options = null) { - if (isset($params['foo'])) { - return $params['foo']; - } - - return ''; + return $params['foo'] ?? ''; } } diff --git a/test/TestAsset/DummyRouteWithParam.php b/test/TestAsset/DummyRouteWithParam.php index 463072c..677c9e8 100644 --- a/test/TestAsset/DummyRouteWithParam.php +++ b/test/TestAsset/DummyRouteWithParam.php @@ -35,10 +35,6 @@ public function match(RequestInterface $request) */ public function assemble(?array $params = null, ?array $options = null) { - if (isset($params['foo'])) { - return $params['foo']; - } - - return ''; + return $params['foo'] ?? ''; } }