From 1f5234e8457164a3a0038a4c0a4ba27876a9c670 Mon Sep 17 00:00:00 2001 From: wkania Date: Sun, 27 Apr 2025 18:08:38 +0200 Subject: [PATCH 1/2] Fix return type is non-nullable --- Tests/Loader/ObjectLoaderTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/Loader/ObjectLoaderTest.php b/Tests/Loader/ObjectLoaderTest.php index f3536f1f..18d8c919 100644 --- a/Tests/Loader/ObjectLoaderTest.php +++ b/Tests/Loader/ObjectLoaderTest.php @@ -104,7 +104,7 @@ public function supports(mixed $resource, ?string $type = null): bool protected function getObject(string $id): object { - return $this->loaderMap[$id] ?? null; + return $this->loaderMap[$id]; } } From b51fb6b50eb0dd883263994b42b9cacf4377103a Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Thu, 10 Jul 2025 09:12:18 +0200 Subject: [PATCH 2/2] CS fixes --- Attribute/Route.php | 2 +- .../MissingMandatoryParametersException.php | 2 +- Exception/RouteCircularReferenceException.php | 2 +- Generator/CompiledUrlGenerator.php | 2 +- .../Dumper/CompiledUrlGeneratorDumper.php | 6 ++-- Generator/UrlGenerator.php | 2 +- Loader/AttributeClassLoader.php | 20 ++++++------- Loader/AttributeFileLoader.php | 2 +- .../Configurator/CollectionConfigurator.php | 4 +-- Loader/Configurator/Traits/HostTrait.php | 2 +- .../Traits/LocalizedRouteTrait.php | 4 +-- Loader/Configurator/Traits/PrefixTrait.php | 2 +- Loader/ObjectLoader.php | 8 ++--- Loader/XmlFileLoader.php | 30 +++++++++---------- Loader/YamlFileLoader.php | 30 +++++++++---------- Matcher/Dumper/CompiledUrlMatcherDumper.php | 8 ++--- Matcher/Dumper/CompiledUrlMatcherTrait.php | 4 +-- Matcher/ExpressionLanguageProvider.php | 2 +- Matcher/TraceableUrlMatcher.php | 16 +++++----- Matcher/UrlMatcher.php | 4 +-- Requirement/EnumRequirement.php | 6 ++-- Route.php | 2 +- RouteCollection.php | 2 +- RouteCompiler.php | 22 +++++++------- Router.php | 6 ++-- Tests/Loader/AttributeClassLoaderTestCase.php | 4 +-- Tests/Loader/ObjectLoaderTest.php | 2 +- Tests/Loader/PhpFileLoaderTest.php | 4 +-- Tests/Loader/Psr4DirectoryLoaderTest.php | 2 +- Tests/Loader/XmlFileLoaderTest.php | 4 +-- Tests/Loader/YamlFileLoaderTest.php | 10 +++---- .../Dumper/StaticPrefixCollectionTest.php | 14 ++++----- Tests/RouteCompilerTest.php | 8 ++--- Tests/RouteTest.php | 16 +++++----- 34 files changed, 127 insertions(+), 127 deletions(-) diff --git a/Attribute/Route.php b/Attribute/Route.php index a1d86fe6..32ee18e8 100644 --- a/Attribute/Route.php +++ b/Attribute/Route.php @@ -49,7 +49,7 @@ public function __construct( ?string $format = null, ?bool $utf8 = null, ?bool $stateless = null, - private ?string $env = null + private ?string $env = null, ) { if (\is_array($path)) { $this->localizedPaths = $path; diff --git a/Exception/MissingMandatoryParametersException.php b/Exception/MissingMandatoryParametersException.php index 72d063ab..b64d6d84 100644 --- a/Exception/MissingMandatoryParametersException.php +++ b/Exception/MissingMandatoryParametersException.php @@ -31,7 +31,7 @@ public function __construct(string $routeName = '', $missingParameters = null, $ if (\is_array($missingParameters)) { $this->routeName = $routeName; $this->missingParameters = $missingParameters; - $message = sprintf('Some mandatory parameters are missing ("%s") to generate a URL for route "%s".', implode('", "', $missingParameters), $routeName); + $message = \sprintf('Some mandatory parameters are missing ("%s") to generate a URL for route "%s".', implode('", "', $missingParameters), $routeName); } else { trigger_deprecation('symfony/routing', '6.1', 'Construction of "%s" with an exception message is deprecated, provide the route name and an array of missing parameters instead.', __CLASS__); $message = $routeName; diff --git a/Exception/RouteCircularReferenceException.php b/Exception/RouteCircularReferenceException.php index 841e3598..3e20cbcb 100644 --- a/Exception/RouteCircularReferenceException.php +++ b/Exception/RouteCircularReferenceException.php @@ -15,6 +15,6 @@ class RouteCircularReferenceException extends RuntimeException { public function __construct(string $routeId, array $path) { - parent::__construct(sprintf('Circular reference detected for route "%s", path: "%s".', $routeId, implode(' -> ', $path))); + parent::__construct(\sprintf('Circular reference detected for route "%s", path: "%s".', $routeId, implode(' -> ', $path))); } } diff --git a/Generator/CompiledUrlGenerator.php b/Generator/CompiledUrlGenerator.php index de209cdc..b7429d1f 100644 --- a/Generator/CompiledUrlGenerator.php +++ b/Generator/CompiledUrlGenerator.php @@ -47,7 +47,7 @@ public function generate(string $name, array $parameters = [], int $referenceTyp } if (!isset($this->compiledRoutes[$name])) { - throw new RouteNotFoundException(sprintf('Unable to generate a URL for the named route "%s" as such route does not exist.', $name)); + throw new RouteNotFoundException(\sprintf('Unable to generate a URL for the named route "%s" as such route does not exist.', $name)); } [$variables, $defaults, $requirements, $tokens, $hostTokens, $requiredSchemes, $deprecations] = $this->compiledRoutes[$name] + [6 => []]; diff --git a/Generator/Dumper/CompiledUrlGeneratorDumper.php b/Generator/Dumper/CompiledUrlGeneratorDumper.php index 1144fed5..555c5bfb 100644 --- a/Generator/Dumper/CompiledUrlGeneratorDumper.php +++ b/Generator/Dumper/CompiledUrlGeneratorDumper.php @@ -69,7 +69,7 @@ public function getCompiledAliases(): array } if (null === $target = $routes->get($currentId)) { - throw new RouteNotFoundException(sprintf('Target route "%s" for alias "%s" does not exist.', $currentId, $name)); + throw new RouteNotFoundException(\sprintf('Target route "%s" for alias "%s" does not exist.', $currentId, $name)); } $compiledTarget = $target->compile(); @@ -109,11 +109,11 @@ private function generateDeclaredRoutes(): string { $routes = ''; foreach ($this->getCompiledRoutes() as $name => $properties) { - $routes .= sprintf("\n '%s' => %s,", $name, CompiledUrlMatcherDumper::export($properties)); + $routes .= \sprintf("\n '%s' => %s,", $name, CompiledUrlMatcherDumper::export($properties)); } foreach ($this->getCompiledAliases() as $alias => $properties) { - $routes .= sprintf("\n '%s' => %s,", $alias, CompiledUrlMatcherDumper::export($properties)); + $routes .= \sprintf("\n '%s' => %s,", $alias, CompiledUrlMatcherDumper::export($properties)); } return $routes; diff --git a/Generator/UrlGenerator.php b/Generator/UrlGenerator.php index 28f30d61..4c8f8f74 100644 --- a/Generator/UrlGenerator.php +++ b/Generator/UrlGenerator.php @@ -131,7 +131,7 @@ public function generate(string $name, array $parameters = [], int $referenceTyp } if (null === $route ??= $this->routes->get($name)) { - throw new RouteNotFoundException(sprintf('Unable to generate a URL for the named route "%s" as such route does not exist.', $name)); + throw new RouteNotFoundException(\sprintf('Unable to generate a URL for the named route "%s" as such route does not exist.', $name)); } // the Route has a cache of its own and is not recompiled as long as it does not get modified diff --git a/Loader/AttributeClassLoader.php b/Loader/AttributeClassLoader.php index 132da802..6506feae 100644 --- a/Loader/AttributeClassLoader.php +++ b/Loader/AttributeClassLoader.php @@ -94,7 +94,7 @@ public function __construct($env = null) } elseif ($env instanceof \Stringable || \is_scalar($env)) { $this->env = (string) $env; } else { - throw new \TypeError(__METHOD__.sprintf(': Parameter $env was expected to be a string or null, "%s" given.', get_debug_type($env))); + throw new \TypeError(__METHOD__.\sprintf(': Parameter $env was expected to be a string or null, "%s" given.', get_debug_type($env))); } } @@ -114,12 +114,12 @@ public function setRouteAnnotationClass(string $class) public function load(mixed $class, ?string $type = null): RouteCollection { if (!class_exists($class)) { - throw new \InvalidArgumentException(sprintf('Class "%s" does not exist.', $class)); + throw new \InvalidArgumentException(\sprintf('Class "%s" does not exist.', $class)); } $class = new \ReflectionClass($class); if ($class->isAbstract()) { - throw new \InvalidArgumentException(sprintf('Attributes from class "%s" cannot be read as it is abstract.', $class->getName())); + throw new \InvalidArgumentException(\sprintf('Attributes from class "%s" cannot be read as it is abstract.', $class->getName())); } $this->hasDeprecatedAnnotations = false; @@ -144,7 +144,7 @@ public function load(mixed $class, ?string $type = null): RouteCollection if (1 === $collection->count() - \count($routeNamesBefore)) { $newRouteName = current(array_diff(array_keys($collection->all()), $routeNamesBefore)); - if ($newRouteName !== $aliasName = sprintf('%s::%s', $class->name, $method->name)) { + if ($newRouteName !== $aliasName = \sprintf('%s::%s', $class->name, $method->name)) { $collection->addAlias($aliasName, $newRouteName); } } @@ -162,7 +162,7 @@ public function load(mixed $class, ?string $type = null): RouteCollection $collection->addAlias($class->name, $invokeRouteName); } - if ($invokeRouteName !== $aliasName = sprintf('%s::__invoke', $class->name)) { + if ($invokeRouteName !== $aliasName = \sprintf('%s::__invoke', $class->name)) { $collection->addAlias($aliasName, $invokeRouteName); } } @@ -195,7 +195,7 @@ protected function addRoute(RouteCollection $collection, object $annot, array $g foreach ($requirements as $placeholder => $requirement) { if (\is_int($placeholder)) { - throw new \InvalidArgumentException(sprintf('A placeholder name must be a string (%d given). Did you forget to specify the placeholder key for the requirement "%s" of route "%s" in "%s::%s()"?', $placeholder, $requirement, $name, $class->getName(), $method->getName())); + throw new \InvalidArgumentException(\sprintf('A placeholder name must be a string (%d given). Did you forget to specify the placeholder key for the requirement "%s" of route "%s" in "%s::%s()"?', $placeholder, $requirement, $name, $class->getName(), $method->getName())); } } @@ -219,11 +219,11 @@ protected function addRoute(RouteCollection $collection, object $annot, array $g $paths[$locale] = $prefix.$localePath; } } elseif ($missing = array_diff_key($prefix, $path)) { - throw new \LogicException(sprintf('Route to "%s" is missing paths for locale(s) "%s".', $class->name.'::'.$method->name, implode('", "', array_keys($missing)))); + throw new \LogicException(\sprintf('Route to "%s" is missing paths for locale(s) "%s".', $class->name.'::'.$method->name, implode('", "', array_keys($missing)))); } else { foreach ($path as $locale => $localePath) { if (!isset($prefix[$locale])) { - throw new \LogicException(sprintf('Route to "%s" with locale "%s" is missing a corresponding prefix in class "%s".', $method->name, $locale, $class->name)); + throw new \LogicException(\sprintf('Route to "%s" with locale "%s" is missing a corresponding prefix in class "%s".', $method->name, $locale, $class->name)); } $paths[$locale] = $prefix[$locale].$localePath; @@ -242,7 +242,7 @@ protected function addRoute(RouteCollection $collection, object $annot, array $g continue; } foreach ($paths as $locale => $path) { - if (preg_match(sprintf('/\{%s(?:<.*?>)?\}/', preg_quote($param->name)), $path)) { + if (preg_match(\sprintf('/\{%s(?:<.*?>)?\}/', preg_quote($param->name)), $path)) { if (\is_scalar($defaultValue = $param->getDefaultValue()) || null === $defaultValue) { $defaults[$param->name] = $defaultValue; } elseif ($defaultValue instanceof \BackedEnum) { @@ -360,7 +360,7 @@ protected function getGlobals(\ReflectionClass $class) foreach ($globals['requirements'] as $placeholder => $requirement) { if (\is_int($placeholder)) { - throw new \InvalidArgumentException(sprintf('A placeholder name must be a string (%d given). Did you forget to specify the placeholder key for the requirement "%s" in "%s"?', $placeholder, $requirement, $class->getName())); + throw new \InvalidArgumentException(\sprintf('A placeholder name must be a string (%d given). Did you forget to specify the placeholder key for the requirement "%s" in "%s"?', $placeholder, $requirement, $class->getName())); } } } diff --git a/Loader/AttributeFileLoader.php b/Loader/AttributeFileLoader.php index e9a13e59..8d522f47 100644 --- a/Loader/AttributeFileLoader.php +++ b/Loader/AttributeFileLoader.php @@ -82,7 +82,7 @@ protected function findClass(string $file): string|false $tokens = token_get_all(file_get_contents($file)); if (1 === \count($tokens) && \T_INLINE_HTML === $tokens[0][0]) { - throw new \InvalidArgumentException(sprintf('The file "%s" does not contain PHP code. Did you forget to add the " true, \T_STRING => true]; diff --git a/Loader/Configurator/CollectionConfigurator.php b/Loader/Configurator/CollectionConfigurator.php index 1abf3bc0..fdb659ca 100644 --- a/Loader/Configurator/CollectionConfigurator.php +++ b/Loader/Configurator/CollectionConfigurator.php @@ -84,11 +84,11 @@ final public function prefix(string|array $prefix): static if (null === $this->parentPrefixes) { // no-op } elseif ($missing = array_diff_key($this->parentPrefixes, $prefix)) { - throw new \LogicException(sprintf('Collection "%s" is missing prefixes for locale(s) "%s".', $this->name, implode('", "', array_keys($missing)))); + throw new \LogicException(\sprintf('Collection "%s" is missing prefixes for locale(s) "%s".', $this->name, implode('", "', array_keys($missing)))); } else { foreach ($prefix as $locale => $localePrefix) { if (!isset($this->parentPrefixes[$locale])) { - throw new \LogicException(sprintf('Collection "%s" with locale "%s" is missing a corresponding prefix in its parent collection.', $this->name, $locale)); + throw new \LogicException(\sprintf('Collection "%s" with locale "%s" is missing a corresponding prefix in its parent collection.', $this->name, $locale)); } $prefix[$locale] = $this->parentPrefixes[$locale].$localePrefix; diff --git a/Loader/Configurator/Traits/HostTrait.php b/Loader/Configurator/Traits/HostTrait.php index 1050bb0f..e584f356 100644 --- a/Loader/Configurator/Traits/HostTrait.php +++ b/Loader/Configurator/Traits/HostTrait.php @@ -39,7 +39,7 @@ final protected function addHost(RouteCollection $routes, string|array $hosts): $routes->add($name.'.'.$locale, $localizedRoute, $priority); } } elseif (!isset($hosts[$locale])) { - throw new \InvalidArgumentException(sprintf('Route "%s" with locale "%s" is missing a corresponding host in its parent collection.', $name, $locale)); + throw new \InvalidArgumentException(\sprintf('Route "%s" with locale "%s" is missing a corresponding host in its parent collection.', $name, $locale)); } else { $route->setHost($hosts[$locale]); $route->setRequirement('_locale', preg_quote($locale)); diff --git a/Loader/Configurator/Traits/LocalizedRouteTrait.php b/Loader/Configurator/Traits/LocalizedRouteTrait.php index a26a7342..d90ef9d3 100644 --- a/Loader/Configurator/Traits/LocalizedRouteTrait.php +++ b/Loader/Configurator/Traits/LocalizedRouteTrait.php @@ -37,11 +37,11 @@ final protected function createLocalizedRoute(RouteCollection $collection, strin if (null === $prefixes) { $paths = $path; } elseif ($missing = array_diff_key($prefixes, $path)) { - throw new \LogicException(sprintf('Route "%s" is missing routes for locale(s) "%s".', $name, implode('", "', array_keys($missing)))); + throw new \LogicException(\sprintf('Route "%s" is missing routes for locale(s) "%s".', $name, implode('", "', array_keys($missing)))); } else { foreach ($path as $locale => $localePath) { if (!isset($prefixes[$locale])) { - throw new \LogicException(sprintf('Route "%s" with locale "%s" is missing a corresponding prefix in its parent collection.', $name, $locale)); + throw new \LogicException(\sprintf('Route "%s" with locale "%s" is missing a corresponding prefix in its parent collection.', $name, $locale)); } $paths[$locale] = $prefixes[$locale].$localePath; diff --git a/Loader/Configurator/Traits/PrefixTrait.php b/Loader/Configurator/Traits/PrefixTrait.php index 89a65d8f..9777c649 100644 --- a/Loader/Configurator/Traits/PrefixTrait.php +++ b/Loader/Configurator/Traits/PrefixTrait.php @@ -40,7 +40,7 @@ final protected function addPrefix(RouteCollection $routes, string|array $prefix $routes->add($name.'.'.$locale, $localizedRoute, $priority); } } elseif (!isset($prefix[$locale])) { - throw new \InvalidArgumentException(sprintf('Route "%s" with locale "%s" is missing a corresponding prefix in its parent collection.', $name, $locale)); + throw new \InvalidArgumentException(\sprintf('Route "%s" with locale "%s" is missing a corresponding prefix in its parent collection.', $name, $locale)); } else { $route->setPath($prefix[$locale].(!$trailingSlashOnRoot && '/' === $route->getPath() ? '' : $route->getPath())); $routes->add($name, $route, $routes->getPriority($name) ?? 0); diff --git a/Loader/ObjectLoader.php b/Loader/ObjectLoader.php index c2ad6a03..d4234c13 100644 --- a/Loader/ObjectLoader.php +++ b/Loader/ObjectLoader.php @@ -36,7 +36,7 @@ abstract protected function getObject(string $id): object; public function load(mixed $resource, ?string $type = null): RouteCollection { if (!preg_match('/^[^\:]+(?:::(?:[^\:]+))?$/', $resource)) { - throw new \InvalidArgumentException(sprintf('Invalid resource "%s" passed to the %s route loader: use the format "object_id::method" or "object_id" if your object class has an "__invoke" method.', $resource, \is_string($type) ? '"'.$type.'"' : 'object')); + throw new \InvalidArgumentException(\sprintf('Invalid resource "%s" passed to the %s route loader: use the format "object_id::method" or "object_id" if your object class has an "__invoke" method.', $resource, \is_string($type) ? '"'.$type.'"' : 'object')); } $parts = explode('::', $resource); @@ -45,11 +45,11 @@ public function load(mixed $resource, ?string $type = null): RouteCollection $loaderObject = $this->getObject($parts[0]); if (!\is_object($loaderObject)) { - throw new \TypeError(sprintf('"%s:getObject()" must return an object: "%s" returned.', static::class, get_debug_type($loaderObject))); + throw new \TypeError(\sprintf('"%s:getObject()" must return an object: "%s" returned.', static::class, get_debug_type($loaderObject))); } if (!\is_callable([$loaderObject, $method])) { - throw new \BadMethodCallException(sprintf('Method "%s" not found on "%s" when importing routing resource "%s".', $method, get_debug_type($loaderObject), $resource)); + throw new \BadMethodCallException(\sprintf('Method "%s" not found on "%s" when importing routing resource "%s".', $method, get_debug_type($loaderObject), $resource)); } $routeCollection = $loaderObject->$method($this, $this->env); @@ -57,7 +57,7 @@ public function load(mixed $resource, ?string $type = null): RouteCollection if (!$routeCollection instanceof RouteCollection) { $type = get_debug_type($routeCollection); - throw new \LogicException(sprintf('The "%s::%s()" method must return a RouteCollection: "%s" returned.', get_debug_type($loaderObject), $method, $type)); + throw new \LogicException(\sprintf('The "%s::%s()" method must return a RouteCollection: "%s" returned.', get_debug_type($loaderObject), $method, $type)); } // make the object file tracked so that if it changes, the cache rebuilds diff --git a/Loader/XmlFileLoader.php b/Loader/XmlFileLoader.php index 1e3e3283..5b41bd69 100644 --- a/Loader/XmlFileLoader.php +++ b/Loader/XmlFileLoader.php @@ -90,7 +90,7 @@ protected function parseNode(RouteCollection $collection, \DOMElement $node, str } break; default: - throw new \InvalidArgumentException(sprintf('Unknown tag "%s" used in file "%s". Expected "route" or "import".', $node->localName, $path)); + throw new \InvalidArgumentException(\sprintf('Unknown tag "%s" used in file "%s". Expected "route" or "import".', $node->localName, $path)); } } @@ -109,7 +109,7 @@ public function supports(mixed $resource, ?string $type = null): bool protected function parseRoute(RouteCollection $collection, \DOMElement $node, string $path) { if ('' === $id = $node->getAttribute('id')) { - throw new \InvalidArgumentException(sprintf('The element in file "%s" must have an "id" attribute.', $path)); + throw new \InvalidArgumentException(\sprintf('The element in file "%s" must have an "id" attribute.', $path)); } if ('' !== $alias = $node->getAttribute('alias')) { @@ -128,11 +128,11 @@ protected function parseRoute(RouteCollection $collection, \DOMElement $node, st [$defaults, $requirements, $options, $condition, $paths, /* $prefixes */, $hosts] = $this->parseConfigs($node, $path); if (!$paths && '' === $node->getAttribute('path')) { - throw new \InvalidArgumentException(sprintf('The element in file "%s" must have a "path" attribute or child nodes.', $path)); + throw new \InvalidArgumentException(\sprintf('The element in file "%s" must have a "path" attribute or child nodes.', $path)); } if ($paths && '' !== $node->getAttribute('path')) { - throw new \InvalidArgumentException(sprintf('The element in file "%s" must not have both a "path" attribute and child nodes.', $path)); + throw new \InvalidArgumentException(\sprintf('The element in file "%s" must not have both a "path" attribute and child nodes.', $path)); } $routes = $this->createLocalizedRoute(new RouteCollection(), $id, $paths ?: $node->getAttribute('path')); @@ -169,7 +169,7 @@ protected function parseImport(RouteCollection $collection, \DOMElement $node, s } if (!$resource) { - throw new \InvalidArgumentException(sprintf('The element in file "%s" must have a "resource" attribute or element.', $path)); + throw new \InvalidArgumentException(\sprintf('The element in file "%s" must have a "resource" attribute or element.', $path)); } $type = $node->getAttribute('type'); @@ -182,7 +182,7 @@ protected function parseImport(RouteCollection $collection, \DOMElement $node, s [$defaults, $requirements, $options, $condition, /* $paths */, $prefixes, $hosts] = $this->parseConfigs($node, $path); if ('' !== $prefix && $prefixes) { - throw new \InvalidArgumentException(sprintf('The element in file "%s" must not have both a "prefix" attribute and child nodes.', $path)); + throw new \InvalidArgumentException(\sprintf('The element in file "%s" must not have both a "prefix" attribute and child nodes.', $path)); } $exclude = []; @@ -296,15 +296,15 @@ private function parseConfigs(\DOMElement $node, string $path): array case 'resource': break; default: - throw new \InvalidArgumentException(sprintf('Unknown tag "%s" used in file "%s". Expected "default", "requirement", "option" or "condition".', $n->localName, $path)); + throw new \InvalidArgumentException(\sprintf('Unknown tag "%s" used in file "%s". Expected "default", "requirement", "option" or "condition".', $n->localName, $path)); } } if ($controller = $node->getAttribute('controller')) { if (isset($defaults['_controller'])) { - $name = $node->hasAttribute('id') ? sprintf('"%s".', $node->getAttribute('id')) : sprintf('the "%s" tag.', $node->tagName); + $name = $node->hasAttribute('id') ? \sprintf('"%s".', $node->getAttribute('id')) : \sprintf('the "%s" tag.', $node->tagName); - throw new \InvalidArgumentException(sprintf('The routing file "%s" must not specify both the "controller" attribute and the defaults key "_controller" for ', $path).$name); + throw new \InvalidArgumentException(\sprintf('The routing file "%s" must not specify both the "controller" attribute and the defaults key "_controller" for ', $path).$name); } $defaults['_controller'] = $controller; @@ -320,9 +320,9 @@ private function parseConfigs(\DOMElement $node, string $path): array } if ($stateless = $node->getAttribute('stateless')) { if (isset($defaults['_stateless'])) { - $name = $node->hasAttribute('id') ? sprintf('"%s".', $node->getAttribute('id')) : sprintf('the "%s" tag.', $node->tagName); + $name = $node->hasAttribute('id') ? \sprintf('"%s".', $node->getAttribute('id')) : \sprintf('the "%s" tag.', $node->tagName); - throw new \InvalidArgumentException(sprintf('The routing file "%s" must not specify both the "stateless" attribute and the defaults key "_stateless" for ', $path).$name); + throw new \InvalidArgumentException(\sprintf('The routing file "%s" must not specify both the "stateless" attribute and the defaults key "_stateless" for ', $path).$name); } $defaults['_stateless'] = XmlUtils::phpize($stateless); @@ -418,7 +418,7 @@ private function parseDefaultNode(\DOMElement $node, string $path): array|bool|f return $map; default: - throw new \InvalidArgumentException(sprintf('Unknown tag "%s" used in file "%s". Expected "bool", "int", "float", "string", "list", or "map".', $node->localName, $path)); + throw new \InvalidArgumentException(\sprintf('Unknown tag "%s" used in file "%s". Expected "bool", "int", "float", "string", "list", or "map".', $node->localName, $path)); } } @@ -446,7 +446,7 @@ private function parseDeprecation(\DOMElement $node, string $path): array continue; } if ('deprecated' !== $child->localName) { - throw new \InvalidArgumentException(sprintf('Invalid child element "%s" defined for alias "%s" in "%s".', $child->localName, $node->getAttribute('id'), $path)); + throw new \InvalidArgumentException(\sprintf('Invalid child element "%s" defined for alias "%s" in "%s".', $child->localName, $node->getAttribute('id'), $path)); } $deprecatedNode = $child; @@ -457,10 +457,10 @@ private function parseDeprecation(\DOMElement $node, string $path): array } if (!$deprecatedNode->hasAttribute('package')) { - throw new \InvalidArgumentException(sprintf('The element in file "%s" must have a "package" attribute.', $path)); + throw new \InvalidArgumentException(\sprintf('The element in file "%s" must have a "package" attribute.', $path)); } if (!$deprecatedNode->hasAttribute('version')) { - throw new \InvalidArgumentException(sprintf('The element in file "%s" must have a "version" attribute.', $path)); + throw new \InvalidArgumentException(\sprintf('The element in file "%s" must have a "version" attribute.', $path)); } return [ diff --git a/Loader/YamlFileLoader.php b/Loader/YamlFileLoader.php index 09beb7cd..c1924ba6 100644 --- a/Loader/YamlFileLoader.php +++ b/Loader/YamlFileLoader.php @@ -46,11 +46,11 @@ public function load(mixed $file, ?string $type = null): RouteCollection $path = $this->locator->locate($file); if (!stream_is_local($path)) { - throw new \InvalidArgumentException(sprintf('This is not a local file "%s".', $path)); + throw new \InvalidArgumentException(\sprintf('This is not a local file "%s".', $path)); } if (!file_exists($path)) { - throw new \InvalidArgumentException(sprintf('File "%s" not found.', $path)); + throw new \InvalidArgumentException(\sprintf('File "%s" not found.', $path)); } $this->yamlParser ??= new YamlParser(); @@ -58,7 +58,7 @@ public function load(mixed $file, ?string $type = null): RouteCollection try { $parsedConfig = $this->yamlParser->parseFile($path, Yaml::PARSE_CONSTANT); } catch (ParseException $e) { - throw new \InvalidArgumentException(sprintf('The file "%s" does not contain valid YAML: ', $path).$e->getMessage(), 0, $e); + throw new \InvalidArgumentException(\sprintf('The file "%s" does not contain valid YAML: ', $path).$e->getMessage(), 0, $e); } $collection = new RouteCollection(); @@ -71,7 +71,7 @@ public function load(mixed $file, ?string $type = null): RouteCollection // not an array if (!\is_array($parsedConfig)) { - throw new \InvalidArgumentException(sprintf('The file "%s" must contain a YAML array.', $path)); + throw new \InvalidArgumentException(\sprintf('The file "%s" must contain a YAML array.', $path)); } foreach ($parsedConfig as $name => $config) { @@ -137,7 +137,7 @@ protected function parseRoute(RouteCollection $collection, string $name, array $ foreach ($requirements as $placeholder => $requirement) { if (\is_int($placeholder)) { - throw new \InvalidArgumentException(sprintf('A placeholder name must be a string (%d given). Did you forget to specify the placeholder key for the requirement "%s" of route "%s" in "%s"?', $placeholder, $requirement, $name, $path)); + throw new \InvalidArgumentException(\sprintf('A placeholder name must be a string (%d given). Did you forget to specify the placeholder key for the requirement "%s" of route "%s" in "%s"?', $placeholder, $requirement, $name, $path)); } } @@ -252,7 +252,7 @@ protected function parseImport(RouteCollection $collection, array $config, strin protected function validate(mixed $config, string $name, string $path) { if (!\is_array($config)) { - throw new \InvalidArgumentException(sprintf('The definition of "%s" in "%s" must be a YAML array.', $name, $path)); + throw new \InvalidArgumentException(\sprintf('The definition of "%s" in "%s" must be a YAML array.', $name, $path)); } if (isset($config['alias'])) { $this->validateAlias($config, $name, $path); @@ -260,22 +260,22 @@ protected function validate(mixed $config, string $name, string $path) return; } if ($extraKeys = array_diff(array_keys($config), self::AVAILABLE_KEYS)) { - throw new \InvalidArgumentException(sprintf('The routing file "%s" contains unsupported keys for "%s": "%s". Expected one of: "%s".', $path, $name, implode('", "', $extraKeys), implode('", "', self::AVAILABLE_KEYS))); + throw new \InvalidArgumentException(\sprintf('The routing file "%s" contains unsupported keys for "%s": "%s". Expected one of: "%s".', $path, $name, implode('", "', $extraKeys), implode('", "', self::AVAILABLE_KEYS))); } if (isset($config['resource']) && isset($config['path'])) { - throw new \InvalidArgumentException(sprintf('The routing file "%s" must not specify both the "resource" key and the "path" key for "%s". Choose between an import and a route definition.', $path, $name)); + throw new \InvalidArgumentException(\sprintf('The routing file "%s" must not specify both the "resource" key and the "path" key for "%s". Choose between an import and a route definition.', $path, $name)); } if (!isset($config['resource']) && isset($config['type'])) { - throw new \InvalidArgumentException(sprintf('The "type" key for the route definition "%s" in "%s" is unsupported. It is only available for imports in combination with the "resource" key.', $name, $path)); + throw new \InvalidArgumentException(\sprintf('The "type" key for the route definition "%s" in "%s" is unsupported. It is only available for imports in combination with the "resource" key.', $name, $path)); } if (!isset($config['resource']) && !isset($config['path'])) { - throw new \InvalidArgumentException(sprintf('You must define a "path" for the route "%s" in file "%s".', $name, $path)); + throw new \InvalidArgumentException(\sprintf('You must define a "path" for the route "%s" in file "%s".', $name, $path)); } if (isset($config['controller']) && isset($config['defaults']['_controller'])) { - throw new \InvalidArgumentException(sprintf('The routing file "%s" must not specify both the "controller" key and the defaults key "_controller" for "%s".', $path, $name)); + throw new \InvalidArgumentException(\sprintf('The routing file "%s" must not specify both the "controller" key and the defaults key "_controller" for "%s".', $path, $name)); } if (isset($config['stateless']) && isset($config['defaults']['_stateless'])) { - throw new \InvalidArgumentException(sprintf('The routing file "%s" must not specify both the "stateless" key and the defaults key "_stateless" for "%s".', $path, $name)); + throw new \InvalidArgumentException(\sprintf('The routing file "%s" must not specify both the "stateless" key and the defaults key "_stateless" for "%s".', $path, $name)); } } @@ -287,16 +287,16 @@ private function validateAlias(array $config, string $name, string $path): void { foreach ($config as $key => $value) { if (!\in_array($key, ['alias', 'deprecated'], true)) { - throw new \InvalidArgumentException(sprintf('The routing file "%s" must not specify other keys than "alias" and "deprecated" for "%s".', $path, $name)); + throw new \InvalidArgumentException(\sprintf('The routing file "%s" must not specify other keys than "alias" and "deprecated" for "%s".', $path, $name)); } if ('deprecated' === $key) { if (!isset($value['package'])) { - throw new \InvalidArgumentException(sprintf('The routing file "%s" must specify the attribute "package" of the "deprecated" option for "%s".', $path, $name)); + throw new \InvalidArgumentException(\sprintf('The routing file "%s" must specify the attribute "package" of the "deprecated" option for "%s".', $path, $name)); } if (!isset($value['version'])) { - throw new \InvalidArgumentException(sprintf('The routing file "%s" must specify the attribute "version" of the "deprecated" option for "%s".', $path, $name)); + throw new \InvalidArgumentException(\sprintf('The routing file "%s" must specify the attribute "version" of the "deprecated" option for "%s".', $path, $name)); } } } diff --git a/Matcher/Dumper/CompiledUrlMatcherDumper.php b/Matcher/Dumper/CompiledUrlMatcherDumper.php index a7639cd4..9deb0125 100644 --- a/Matcher/Dumper/CompiledUrlMatcherDumper.php +++ b/Matcher/Dumper/CompiledUrlMatcherDumper.php @@ -137,7 +137,7 @@ private function generateCompiledRoutes(): string $code .= '[ // $staticRoutes'."\n"; foreach ($staticRoutes as $path => $routes) { - $code .= sprintf(" %s => [\n", self::export($path)); + $code .= \sprintf(" %s => [\n", self::export($path)); foreach ($routes as $route) { $code .= vsprintf(" [%s, %s, %s, %s, %s, %s, %s],\n", array_map([__CLASS__, 'export'], $route)); } @@ -145,11 +145,11 @@ private function generateCompiledRoutes(): string } $code .= "],\n"; - $code .= sprintf("[ // \$regexpList%s\n],\n", $regexpCode); + $code .= \sprintf("[ // \$regexpList%s\n],\n", $regexpCode); $code .= '[ // $dynamicRoutes'."\n"; foreach ($dynamicRoutes as $path => $routes) { - $code .= sprintf(" %s => [\n", self::export($path)); + $code .= \sprintf(" %s => [\n", self::export($path)); foreach ($routes as $route) { $code .= vsprintf(" [%s, %s, %s, %s, %s, %s, %s],\n", array_map([__CLASS__, 'export'], $route)); } @@ -402,7 +402,7 @@ private function compileStaticPrefixCollection(StaticPrefixCollection $tree, \st $state->mark += 3 + $state->markTail + \strlen($regex) - $prefixLen; $state->markTail = 2 + \strlen($state->mark); - $rx = sprintf('|%s(*:%s)', substr($regex, $prefixLen), $state->mark); + $rx = \sprintf('|%s(*:%s)', substr($regex, $prefixLen), $state->mark); $code .= "\n .".self::export($rx); $state->regex .= $rx; diff --git a/Matcher/Dumper/CompiledUrlMatcherTrait.php b/Matcher/Dumper/CompiledUrlMatcherTrait.php index 50abf458..db754e6d 100644 --- a/Matcher/Dumper/CompiledUrlMatcherTrait.php +++ b/Matcher/Dumper/CompiledUrlMatcherTrait.php @@ -42,7 +42,7 @@ public function match(string $pathinfo): array throw new MethodNotAllowedException(array_keys($allow)); } if (!$this instanceof RedirectableUrlMatcherInterface) { - throw new ResourceNotFoundException(sprintf('No routes found for "%s".', $pathinfo)); + throw new ResourceNotFoundException(\sprintf('No routes found for "%s".', $pathinfo)); } if (!\in_array($this->context->getMethod(), ['HEAD', 'GET'], true)) { // no-op @@ -67,7 +67,7 @@ public function match(string $pathinfo): array } } - throw new ResourceNotFoundException(sprintf('No routes found for "%s".', $pathinfo)); + throw new ResourceNotFoundException(\sprintf('No routes found for "%s".', $pathinfo)); } private function doMatch(string $pathinfo, array &$allow = [], array &$allowSchemes = []): array diff --git a/Matcher/ExpressionLanguageProvider.php b/Matcher/ExpressionLanguageProvider.php index 3aeebe69..a910a07a 100644 --- a/Matcher/ExpressionLanguageProvider.php +++ b/Matcher/ExpressionLanguageProvider.php @@ -36,7 +36,7 @@ public function getFunctions(): array foreach ($this->functions->getProvidedServices() as $function => $type) { $functions[] = new ExpressionFunction( $function, - static fn (...$args) => sprintf('($context->getParameter(\'_functions\')->get(%s)(%s))', var_export($function, true), implode(', ', $args)), + static fn (...$args) => \sprintf('($context->getParameter(\'_functions\')->get(%s)(%s))', var_export($function, true), implode(', ', $args)), fn ($values, ...$args) => $values['context']->getParameter('_functions')->get($function)(...$args) ); } diff --git a/Matcher/TraceableUrlMatcher.php b/Matcher/TraceableUrlMatcher.php index 3c7e24d0..20fb0646 100644 --- a/Matcher/TraceableUrlMatcher.php +++ b/Matcher/TraceableUrlMatcher.php @@ -72,7 +72,7 @@ protected function matchCollection(string $pathinfo, RouteCollection $routes): a // check the static prefix of the URL first. Only use the more expensive preg_match when it matches if ('' !== $staticPrefix && !str_starts_with($trimmedPathinfo, $staticPrefix)) { - $this->addTrace(sprintf('Path "%s" does not match', $route->getPath()), self::ROUTE_DOES_NOT_MATCH, $name, $route); + $this->addTrace(\sprintf('Path "%s" does not match', $route->getPath()), self::ROUTE_DOES_NOT_MATCH, $name, $route); continue; } $regex = $compiledRoute->getRegex(); @@ -86,7 +86,7 @@ protected function matchCollection(string $pathinfo, RouteCollection $routes): a $r = new Route($route->getPath(), $route->getDefaults(), [], $route->getOptions()); $cr = $r->compile(); if (!preg_match($cr->getRegex(), $pathinfo)) { - $this->addTrace(sprintf('Path "%s" does not match', $route->getPath()), self::ROUTE_DOES_NOT_MATCH, $name, $route); + $this->addTrace(\sprintf('Path "%s" does not match', $route->getPath()), self::ROUTE_DOES_NOT_MATCH, $name, $route); continue; } @@ -96,7 +96,7 @@ protected function matchCollection(string $pathinfo, RouteCollection $routes): a $cr = $r->compile(); if (\in_array($n, $cr->getVariables()) && !preg_match($cr->getRegex(), $pathinfo)) { - $this->addTrace(sprintf('Requirement for "%s" does not match (%s)', $n, $regex), self::ROUTE_ALMOST_MATCHES, $name, $route); + $this->addTrace(\sprintf('Requirement for "%s" does not match (%s)', $n, $regex), self::ROUTE_ALMOST_MATCHES, $name, $route); continue 2; } @@ -117,7 +117,7 @@ protected function matchCollection(string $pathinfo, RouteCollection $routes): a $hostMatches = []; if ($compiledRoute->getHostRegex() && !preg_match($compiledRoute->getHostRegex(), $this->context->getHost(), $hostMatches)) { - $this->addTrace(sprintf('Host "%s" does not match the requirement ("%s")', $this->context->getHost(), $route->getHost()), self::ROUTE_ALMOST_MATCHES, $name, $route); + $this->addTrace(\sprintf('Host "%s" does not match the requirement ("%s")', $this->context->getHost(), $route->getHost()), self::ROUTE_ALMOST_MATCHES, $name, $route); continue; } @@ -126,7 +126,7 @@ protected function matchCollection(string $pathinfo, RouteCollection $routes): a $status = $this->handleRouteRequirements($pathinfo, $name, $route, $attributes); if (self::REQUIREMENT_MISMATCH === $status[0]) { - $this->addTrace(sprintf('Condition "%s" does not evaluate to "true"', $route->getCondition()), self::ROUTE_ALMOST_MATCHES, $name, $route); + $this->addTrace(\sprintf('Condition "%s" does not evaluate to "true"', $route->getCondition()), self::ROUTE_ALMOST_MATCHES, $name, $route); continue; } @@ -136,19 +136,19 @@ protected function matchCollection(string $pathinfo, RouteCollection $routes): a return $this->allow = $this->allowSchemes = []; } - $this->addTrace(sprintf('Path "%s" does not match', $route->getPath()), self::ROUTE_DOES_NOT_MATCH, $name, $route); + $this->addTrace(\sprintf('Path "%s" does not match', $route->getPath()), self::ROUTE_DOES_NOT_MATCH, $name, $route); continue; } if ($route->getSchemes() && !$route->hasScheme($this->context->getScheme())) { $this->allowSchemes = array_merge($this->allowSchemes, $route->getSchemes()); - $this->addTrace(sprintf('Scheme "%s" does not match any of the required schemes (%s)', $this->context->getScheme(), implode(', ', $route->getSchemes())), self::ROUTE_ALMOST_MATCHES, $name, $route); + $this->addTrace(\sprintf('Scheme "%s" does not match any of the required schemes (%s)', $this->context->getScheme(), implode(', ', $route->getSchemes())), self::ROUTE_ALMOST_MATCHES, $name, $route); continue; } if ($requiredMethods && !\in_array($method, $requiredMethods)) { $this->allow = array_merge($this->allow, $requiredMethods); - $this->addTrace(sprintf('Method "%s" does not match any of the required methods (%s)', $this->context->getMethod(), implode(', ', $requiredMethods)), self::ROUTE_ALMOST_MATCHES, $name, $route); + $this->addTrace(\sprintf('Method "%s" does not match any of the required methods (%s)', $this->context->getMethod(), implode(', ', $requiredMethods)), self::ROUTE_ALMOST_MATCHES, $name, $route); continue; } diff --git a/Matcher/UrlMatcher.php b/Matcher/UrlMatcher.php index 778d154e..ec281fde 100644 --- a/Matcher/UrlMatcher.php +++ b/Matcher/UrlMatcher.php @@ -87,7 +87,7 @@ public function match(string $pathinfo): array throw new NoConfigurationException(); } - throw 0 < \count($this->allow) ? new MethodNotAllowedException(array_unique($this->allow)) : new ResourceNotFoundException(sprintf('No routes found for "%s".', $pathinfo)); + throw 0 < \count($this->allow) ? new MethodNotAllowedException(array_unique($this->allow)) : new ResourceNotFoundException(\sprintf('No routes found for "%s".', $pathinfo)); } public function matchRequest(Request $request): array @@ -225,7 +225,7 @@ protected function handleRouteRequirements(string $pathinfo, string $name, Route $routeParameters = func_get_arg(3); if (!\is_array($routeParameters)) { - throw new \TypeError(sprintf('"%s": Argument $routeParameters is expected to be an array, got "%s".', __METHOD__, get_debug_type($routeParameters))); + throw new \TypeError(\sprintf('"%s": Argument $routeParameters is expected to be an array, got "%s".', __METHOD__, get_debug_type($routeParameters))); } } diff --git a/Requirement/EnumRequirement.php b/Requirement/EnumRequirement.php index 3ab2ed33..acbd3bab 100644 --- a/Requirement/EnumRequirement.php +++ b/Requirement/EnumRequirement.php @@ -26,7 +26,7 @@ public function __construct(string|array $cases = []) { if (\is_string($cases)) { if (!is_subclass_of($cases, \BackedEnum::class, true)) { - throw new InvalidArgumentException(sprintf('"%s" is not a "BackedEnum" class.', $cases)); + throw new InvalidArgumentException(\sprintf('"%s" is not a "BackedEnum" class.', $cases)); } $cases = $cases::cases(); @@ -35,13 +35,13 @@ public function __construct(string|array $cases = []) foreach ($cases as $case) { if (!$case instanceof \BackedEnum) { - throw new InvalidArgumentException(sprintf('Case must be a "BackedEnum" instance, "%s" given.', get_debug_type($case))); + throw new InvalidArgumentException(\sprintf('Case must be a "BackedEnum" instance, "%s" given.', get_debug_type($case))); } $class ??= $case::class; if (!$case instanceof $class) { - throw new InvalidArgumentException(sprintf('"%s::%s" is not a case of "%s".', get_debug_type($case), $case->name, $class)); + throw new InvalidArgumentException(\sprintf('"%s::%s" is not a case of "%s".', get_debug_type($case), $case->name, $class)); } } } diff --git a/Route.php b/Route.php index ac8d8bc6..70798e54 100644 --- a/Route.php +++ b/Route.php @@ -445,7 +445,7 @@ private function sanitizeRequirement(string $key, string $regex): string } if ('' === $regex) { - throw new \InvalidArgumentException(sprintf('Routing requirement for "%s" cannot be empty.', $key)); + throw new \InvalidArgumentException(\sprintf('Routing requirement for "%s" cannot be empty.', $key)); } return $regex; diff --git a/RouteCollection.php b/RouteCollection.php index 2f49ad21..7032b3e1 100644 --- a/RouteCollection.php +++ b/RouteCollection.php @@ -387,7 +387,7 @@ public function addResource(ResourceInterface $resource) public function addAlias(string $name, string $alias): Alias { if ($name === $alias) { - throw new InvalidArgumentException(sprintf('Route alias "%s" can not reference itself.', $name)); + throw new InvalidArgumentException(\sprintf('Route alias "%s" can not reference itself.', $name)); } unset($this->routes[$name], $this->priorities[$name]); diff --git a/RouteCompiler.php b/RouteCompiler.php index 330639f4..a96fb9ad 100644 --- a/RouteCompiler.php +++ b/RouteCompiler.php @@ -75,7 +75,7 @@ public static function compile(Route $route): CompiledRoute foreach ($pathVariables as $pathParam) { if ('_fragment' === $pathParam) { - throw new \InvalidArgumentException(sprintf('Route pattern "%s" cannot contain "_fragment" as a path parameter.', $route->getPath())); + throw new \InvalidArgumentException(\sprintf('Route pattern "%s" cannot contain "_fragment" as a path parameter.', $route->getPath())); } } @@ -107,10 +107,10 @@ private static function compilePattern(Route $route, string $pattern, bool $isHo $needsUtf8 = $route->getOption('utf8'); if (!$needsUtf8 && $useUtf8 && preg_match('/[\x80-\xFF]/', $pattern)) { - throw new \LogicException(sprintf('Cannot use UTF-8 route patterns without setting the "utf8" option for route "%s".', $route->getPath())); + throw new \LogicException(\sprintf('Cannot use UTF-8 route patterns without setting the "utf8" option for route "%s".', $route->getPath())); } if (!$useUtf8 && $needsUtf8) { - throw new \LogicException(sprintf('Cannot mix UTF-8 requirements with non-UTF-8 pattern "%s".', $pattern)); + throw new \LogicException(\sprintf('Cannot mix UTF-8 requirements with non-UTF-8 pattern "%s".', $pattern)); } // Match all variables enclosed in "{}" and iterate over them. But we only want to match the innermost variable @@ -136,14 +136,14 @@ private static function compilePattern(Route $route, string $pattern, bool $isHo // A PCRE subpattern name must start with a non-digit. Also a PHP variable cannot start with a digit so the // variable would not be usable as a Controller action argument. if (preg_match('/^\d/', $varName)) { - throw new \DomainException(sprintf('Variable name "%s" cannot start with a digit in route pattern "%s". Please use a different name.', $varName, $pattern)); + throw new \DomainException(\sprintf('Variable name "%s" cannot start with a digit in route pattern "%s". Please use a different name.', $varName, $pattern)); } if (\in_array($varName, $variables)) { - throw new \LogicException(sprintf('Route pattern "%s" cannot reference variable name "%s" more than once.', $pattern, $varName)); + throw new \LogicException(\sprintf('Route pattern "%s" cannot reference variable name "%s" more than once.', $pattern, $varName)); } if (\strlen($varName) > self::VARIABLE_MAXIMUM_LENGTH) { - throw new \DomainException(sprintf('Variable name "%s" cannot be longer than %d characters in route pattern "%s". Please use a shorter name.', $varName, self::VARIABLE_MAXIMUM_LENGTH, $pattern)); + throw new \DomainException(\sprintf('Variable name "%s" cannot be longer than %d characters in route pattern "%s". Please use a shorter name.', $varName, self::VARIABLE_MAXIMUM_LENGTH, $pattern)); } if ($isSeparator && $precedingText !== $precedingChar) { @@ -163,7 +163,7 @@ private static function compilePattern(Route $route, string $pattern, bool $isHo // Also even if {_format} was not optional the requirement prevents that {page} matches something that was originally // part of {_format} when generating the URL, e.g. _format = 'mobile.html'. $nextSeparator = self::findNextSeparator($followingPattern, $useUtf8); - $regexp = sprintf( + $regexp = \sprintf( '[^%s%s]+', preg_quote($defaultSeparator), $defaultSeparator !== $nextSeparator && '' !== $nextSeparator ? preg_quote($nextSeparator) : '' @@ -180,10 +180,10 @@ private static function compilePattern(Route $route, string $pattern, bool $isHo if (!preg_match('//u', $regexp)) { $useUtf8 = false; } elseif (!$needsUtf8 && preg_match('/[\x80-\xFF]|(?%s)?', preg_quote($token[1]), $token[3], $token[2]); + return \sprintf('%s(?P<%s>%s)?', preg_quote($token[1]), $token[3], $token[2]); } else { - $regexp = sprintf('%s(?P<%s>%s)', preg_quote($token[1]), $token[3], $token[2]); + $regexp = \sprintf('%s(?P<%s>%s)', preg_quote($token[1]), $token[3], $token[2]); if ($index >= $firstOptional) { // Enclose each optional token in a subpattern to make it optional. // "?:" means it is non-capturing, i.e. the portion of the subject string that diff --git a/Router.php b/Router.php index b769caee..95f6091d 100644 --- a/Router.php +++ b/Router.php @@ -144,7 +144,7 @@ public function setOptions(array $options) } if ($invalid) { - throw new \InvalidArgumentException(sprintf('The Router does not support the following options: "%s".', implode('", "', $invalid))); + throw new \InvalidArgumentException(\sprintf('The Router does not support the following options: "%s".', implode('", "', $invalid))); } } @@ -158,7 +158,7 @@ public function setOptions(array $options) public function setOption(string $key, mixed $value) { if (!\array_key_exists($key, $this->options)) { - throw new \InvalidArgumentException(sprintf('The Router does not support the "%s" option.', $key)); + throw new \InvalidArgumentException(\sprintf('The Router does not support the "%s" option.', $key)); } $this->options[$key] = $value; @@ -172,7 +172,7 @@ public function setOption(string $key, mixed $value) public function getOption(string $key): mixed { if (!\array_key_exists($key, $this->options)) { - throw new \InvalidArgumentException(sprintf('The Router does not support the "%s" option.', $key)); + throw new \InvalidArgumentException(\sprintf('The Router does not support the "%s" option.', $key)); } return $this->options[$key]; diff --git a/Tests/Loader/AttributeClassLoaderTestCase.php b/Tests/Loader/AttributeClassLoaderTestCase.php index c05237a4..726d1e86 100644 --- a/Tests/Loader/AttributeClassLoaderTestCase.php +++ b/Tests/Loader/AttributeClassLoaderTestCase.php @@ -239,14 +239,14 @@ public function testInvokableClassMultipleRouteLoad() public function testMissingPrefixLocale() { $this->expectException(\LogicException::class); - $this->expectExceptionMessage(sprintf('Route to "action" with locale "en" is missing a corresponding prefix in class "%s\LocalizedPrefixMissingLocaleActionController".', $this->getNamespace())); + $this->expectExceptionMessage(\sprintf('Route to "action" with locale "en" is missing a corresponding prefix in class "%s\LocalizedPrefixMissingLocaleActionController".', $this->getNamespace())); $this->loader->load($this->getNamespace().'\LocalizedPrefixMissingLocaleActionController'); } public function testMissingRouteLocale() { $this->expectException(\LogicException::class); - $this->expectExceptionMessage(sprintf('Route to "%s\LocalizedPrefixMissingRouteLocaleActionController::action" is missing paths for locale(s) "en".', $this->getNamespace())); + $this->expectExceptionMessage(\sprintf('Route to "%s\LocalizedPrefixMissingRouteLocaleActionController::action" is missing paths for locale(s) "en".', $this->getNamespace())); $this->loader->load($this->getNamespace().'\LocalizedPrefixMissingRouteLocaleActionController'); } diff --git a/Tests/Loader/ObjectLoaderTest.php b/Tests/Loader/ObjectLoaderTest.php index 18d8c919..cd40077f 100644 --- a/Tests/Loader/ObjectLoaderTest.php +++ b/Tests/Loader/ObjectLoaderTest.php @@ -127,7 +127,7 @@ public function __construct($collection, ?string $env = null) public function loadRoutes(TestObjectLoader $loader, ?string $env = null) { if ($this->env !== $env) { - throw new \InvalidArgumentException(sprintf('Expected env "%s", "%s" given.', $this->env, $env)); + throw new \InvalidArgumentException(\sprintf('Expected env "%s", "%s" given.', $this->env, $env)); } return $this->collection; diff --git a/Tests/Loader/PhpFileLoaderTest.php b/Tests/Loader/PhpFileLoaderTest.php index 2ec8bd04..9623f364 100644 --- a/Tests/Loader/PhpFileLoaderTest.php +++ b/Tests/Loader/PhpFileLoaderTest.php @@ -346,7 +346,7 @@ public function testImportAttributesWithPsr4Prefix(string $configFile) new LoaderResolver([ $loader = new PhpFileLoader($locator), new Psr4DirectoryLoader($locator), - new class() extends AttributeClassLoader { + new class extends AttributeClassLoader { protected function configureRoute(Route $route, \ReflectionClass $class, \ReflectionMethod $method, object $annot): void { $route->setDefault('_controller', $class->getName().'::'.$method->getName()); @@ -371,7 +371,7 @@ public function testImportAttributesFromClass() { new LoaderResolver([ $loader = new PhpFileLoader(new FileLocator(\dirname(__DIR__).'/Fixtures')), - new class() extends AttributeClassLoader { + new class extends AttributeClassLoader { protected function configureRoute(Route $route, \ReflectionClass $class, \ReflectionMethod $method, object $annot): void { $route->setDefault('_controller', $class->getName().'::'.$method->getName()); diff --git a/Tests/Loader/Psr4DirectoryLoaderTest.php b/Tests/Loader/Psr4DirectoryLoaderTest.php index 4700d92c..a007d4c9 100644 --- a/Tests/Loader/Psr4DirectoryLoaderTest.php +++ b/Tests/Loader/Psr4DirectoryLoaderTest.php @@ -105,7 +105,7 @@ private function getLoader(): DelegatingLoader return new DelegatingLoader( new LoaderResolver([ new Psr4DirectoryLoader($locator), - new class() extends AttributeClassLoader { + new class extends AttributeClassLoader { protected function configureRoute(Route $route, \ReflectionClass $class, \ReflectionMethod $method, object $annot): void { $route->setDefault('_controller', $class->getName().'::'.$method->getName()); diff --git a/Tests/Loader/XmlFileLoaderTest.php b/Tests/Loader/XmlFileLoaderTest.php index 83859120..32fd4de8 100644 --- a/Tests/Loader/XmlFileLoaderTest.php +++ b/Tests/Loader/XmlFileLoaderTest.php @@ -616,7 +616,7 @@ public function testImportAttributesWithPsr4Prefix(string $configFile) new LoaderResolver([ $loader = new XmlFileLoader($locator), new Psr4DirectoryLoader($locator), - new class() extends AttributeClassLoader { + new class extends AttributeClassLoader { protected function configureRoute(Route $route, \ReflectionClass $class, \ReflectionMethod $method, object $annot): void { $route->setDefault('_controller', $class->getName().'::'.$method->getName()); @@ -641,7 +641,7 @@ public function testImportAttributesFromClass() { new LoaderResolver([ $loader = new XmlFileLoader(new FileLocator(\dirname(__DIR__).'/Fixtures')), - new class() extends AttributeClassLoader { + new class extends AttributeClassLoader { protected function configureRoute(Route $route, \ReflectionClass $class, \ReflectionMethod $method, object $annot): void { $route->setDefault('_controller', $class->getName().'::'.$method->getName()); diff --git a/Tests/Loader/YamlFileLoaderTest.php b/Tests/Loader/YamlFileLoaderTest.php index 1e343868..84ca12bb 100644 --- a/Tests/Loader/YamlFileLoaderTest.php +++ b/Tests/Loader/YamlFileLoaderTest.php @@ -477,7 +477,7 @@ public function testPriorityWithPrefix() { new LoaderResolver([ $loader = new YamlFileLoader(new FileLocator(\dirname(__DIR__).'/Fixtures/localized')), - new class() extends AttributeClassLoader { + new class extends AttributeClassLoader { protected function configureRoute(Route $route, \ReflectionClass $class, \ReflectionMethod $method, object $annot): void { $route->setDefault('_controller', $class->getName().'::'.$method->getName()); @@ -496,12 +496,12 @@ public function testPriorityWithHost() { new LoaderResolver([ $loader = new YamlFileLoader(new FileLocator(\dirname(__DIR__).'/Fixtures/locale_and_host')), - new class() extends AttributeClassLoader { + new class extends AttributeClassLoader { protected function configureRoute( Route $route, \ReflectionClass $class, \ReflectionMethod $method, - object $annot + object $annot, ): void { $route->setDefault('_controller', $class->getName().'::'.$method->getName()); } @@ -524,7 +524,7 @@ public function testImportAttributesWithPsr4Prefix(string $configFile) new LoaderResolver([ $loader = new YamlFileLoader($locator), new Psr4DirectoryLoader($locator), - new class() extends AttributeClassLoader { + new class extends AttributeClassLoader { protected function configureRoute(Route $route, \ReflectionClass $class, \ReflectionMethod $method, object $annot): void { $route->setDefault('_controller', $class->getName().'::'.$method->getName()); @@ -549,7 +549,7 @@ public function testImportAttributesFromClass() { new LoaderResolver([ $loader = new YamlFileLoader(new FileLocator(\dirname(__DIR__).'/Fixtures')), - new class() extends AttributeClassLoader { + new class extends AttributeClassLoader { protected function configureRoute(Route $route, \ReflectionClass $class, \ReflectionMethod $method, object $annot): void { $route->setDefault('_controller', $class->getName().'::'.$method->getName()); diff --git a/Tests/Matcher/Dumper/StaticPrefixCollectionTest.php b/Tests/Matcher/Dumper/StaticPrefixCollectionTest.php index 86e0d0e3..9935ced4 100644 --- a/Tests/Matcher/Dumper/StaticPrefixCollectionTest.php +++ b/Tests/Matcher/Dumper/StaticPrefixCollectionTest.php @@ -47,7 +47,7 @@ public static function routeProvider() root prefix_segment leading_segment -EOF +EOF, ], 'Nested - small group' => [ [ @@ -60,7 +60,7 @@ public static function routeProvider() /prefix/segment/ -> prefix_segment -> leading_segment -EOF +EOF, ], 'Nested - contains item at intersection' => [ [ @@ -73,7 +73,7 @@ public static function routeProvider() /prefix/segment/ -> prefix_segment -> leading_segment -EOF +EOF, ], 'Simple one level nesting' => [ [ @@ -88,7 +88,7 @@ public static function routeProvider() -> nested_segment -> some_segment -> other_segment -EOF +EOF, ], 'Retain matching order with groups' => [ [ @@ -110,7 +110,7 @@ public static function routeProvider() -> dd -> ee -> ff -EOF +EOF, ], 'Retain complex matching order with groups at base' => [ [ @@ -142,7 +142,7 @@ public static function routeProvider() -> -> ee -> -> ff -> parent -EOF +EOF, ], 'Group regardless of segments' => [ @@ -163,7 +163,7 @@ public static function routeProvider() -> g1 -> g2 -> g3 -EOF +EOF, ], ]; } diff --git a/Tests/RouteCompilerTest.php b/Tests/RouteCompilerTest.php index 57f61c7e..32902f65 100644 --- a/Tests/RouteCompilerTest.php +++ b/Tests/RouteCompilerTest.php @@ -287,9 +287,9 @@ public function testRouteWithVariableNameStartingWithADigit($name) public static function getVariableNamesStartingWithADigit() { return [ - ['09'], - ['123'], - ['1e2'], + ['09'], + ['123'], + ['1e2'], ]; } @@ -367,7 +367,7 @@ public static function provideCompileWithHostData() public function testRouteWithTooLongVariableName() { $this->expectException(\DomainException::class); - $route = new Route(sprintf('/{%s}', str_repeat('a', RouteCompiler::VARIABLE_MAXIMUM_LENGTH + 1))); + $route = new Route(\sprintf('/{%s}', str_repeat('a', RouteCompiler::VARIABLE_MAXIMUM_LENGTH + 1))); $route->compile(); } diff --git a/Tests/RouteTest.php b/Tests/RouteTest.php index b68ddd0e..da64d6cf 100644 --- a/Tests/RouteTest.php +++ b/Tests/RouteTest.php @@ -65,7 +65,7 @@ public function testOptions() $route = new Route('/{foo}'); $route->setOptions(['foo' => 'bar']); $this->assertEquals(array_merge([ - 'compiler_class' => 'Symfony\\Component\\Routing\\RouteCompiler', + 'compiler_class' => 'Symfony\\Component\\Routing\\RouteCompiler', ], ['foo' => 'bar']), $route->getOptions(), '->setOptions() sets the options'); $this->assertEquals($route, $route->setOptions([]), '->setOptions() implements a fluent interface'); @@ -154,13 +154,13 @@ public function testSetInvalidRequirement($req) public static function getInvalidRequirements() { return [ - [''], - ['^$'], - ['^'], - ['$'], - ['\A\z'], - ['\A'], - ['\z'], + [''], + ['^$'], + ['^'], + ['$'], + ['\A\z'], + ['\A'], + ['\z'], ]; }