Skip to content

Commit

Permalink
[Routing] Add type-hints to all public interfaces.
Browse files Browse the repository at this point in the history
  • Loading branch information
derrabus committed Jun 25, 2019
1 parent 06899a1 commit 17a86c9
Show file tree
Hide file tree
Showing 12 changed files with 19 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function __construct(array $compiledRoutes, RequestContext $context, Logg
$this->defaultLocale = $defaultLocale;
}

public function generate($name, $parameters = [], $referenceType = self::ABSOLUTE_PATH)
public function generate(string $name, array $parameters = [], int $referenceType = self::ABSOLUTE_PATH)
{
$locale = $parameters['_locale']
?? $this->context->getParameter('_locale')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,8 @@ interface ConfigurableRequirementsInterface
/**
* Enables or disables the exception on incorrect parameters.
* Passing null will deactivate the requirements check completely.
*
* @param bool|null $enabled
*/
public function setStrictRequirements($enabled);
public function setStrictRequirements(?bool $enabled);

/**
* Returns whether to throw an exception on incorrect parameters.
Expand Down
10 changes: 5 additions & 5 deletions src/Symfony/Component/Routing/Generator/UrlGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,9 @@ public function getContext()
/**
* {@inheritdoc}
*/
public function setStrictRequirements($enabled)
public function setStrictRequirements(?bool $enabled)
{
$this->strictRequirements = null === $enabled ? null : (bool) $enabled;
$this->strictRequirements = $enabled;
}

/**
Expand All @@ -124,7 +124,7 @@ public function isStrictRequirements()
/**
* {@inheritdoc}
*/
public function generate($name, $parameters = [], $referenceType = self::ABSOLUTE_PATH)
public function generate(string $name, array $parameters = [], int $referenceType = self::ABSOLUTE_PATH)
{
$route = null;
$locale = $parameters['_locale']
Expand Down Expand Up @@ -155,7 +155,7 @@ public function generate($name, $parameters = [], $referenceType = self::ABSOLUT
* @throws InvalidParameterException When a parameter value for a placeholder is not correct because
* it does not match the requirement
*/
protected function doGenerate($variables, $defaults, $requirements, $tokens, $parameters, $name, $referenceType, $hostTokens, array $requiredSchemes = [])
protected function doGenerate(array $variables, array $defaults, array $requirements, array $tokens, array $parameters, string $name, int $referenceType, array $hostTokens, array $requiredSchemes = [])
{
$variables = array_flip($variables);
$mergedParams = array_replace($defaults, $this->context->getParameters(), $parameters);
Expand Down Expand Up @@ -321,7 +321,7 @@ protected function doGenerate($variables, $defaults, $requirements, $tokens, $pa
*
* @return string The relative target path
*/
public static function getRelativePath($basePath, $targetPath)
public static function getRelativePath(string $basePath, string $targetPath)
{
if ($basePath === $targetPath) {
return '';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,16 +71,12 @@ interface UrlGeneratorInterface extends RequestContextAwareInterface
*
* The special parameter _fragment will be used as the document fragment suffixed to the final URL.
*
* @param string $name The name of the route
* @param mixed $parameters An array of parameters
* @param int $referenceType The type of reference to be generated (one of the constants)
*
* @return string The generated URL
*
* @throws RouteNotFoundException If the named route doesn't exist
* @throws MissingMandatoryParametersException When some parameters are missing that are mandatory for the route
* @throws InvalidParameterException When a parameter value for a placeholder is not correct because
* it does not match the requirement
*/
public function generate($name, $parameters = [], $referenceType = self::ABSOLUTE_PATH);
public function generate(string $name, array $parameters = [], int $referenceType = self::ABSOLUTE_PATH);
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ abstract class RedirectableUrlMatcher extends UrlMatcher implements Redirectable
/**
* {@inheritdoc}
*/
public function match($pathinfo)
public function match(string $pathinfo)
{
try {
return parent::match($pathinfo);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ interface RedirectableUrlMatcherInterface
*
* @return array An array of parameters
*/
public function redirect($path, $route, $scheme = null);
public function redirect(string $path, string $route, string $scheme = null);
}
2 changes: 1 addition & 1 deletion src/Symfony/Component/Routing/Matcher/UrlMatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public function getContext()
/**
* {@inheritdoc}
*/
public function match($pathinfo)
public function match(string $pathinfo)
{
$this->allow = $this->allowSchemes = [];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,5 @@ interface UrlMatcherInterface extends RequestContextAwareInterface
* @throws ResourceNotFoundException If the resource could not be found
* @throws MethodNotAllowedException If the resource was found but the request method is not allowed
*/
public function match($pathinfo);
public function match(string $pathinfo);
}
11 changes: 4 additions & 7 deletions src/Symfony/Component/Routing/Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,12 +159,11 @@ public function setOptions(array $options)
/**
* Sets an option.
*
* @param string $key The key
* @param mixed $value The value
*
* @throws \InvalidArgumentException
*/
public function setOption($key, $value)
public function setOption(string $key, $value)
{
if (!\array_key_exists($key, $this->options)) {
throw new \InvalidArgumentException(sprintf('The Router does not support the "%s" option.', $key));
Expand All @@ -176,13 +175,11 @@ public function setOption($key, $value)
/**
* Gets an option value.
*
* @param string $key The key
*
* @return mixed The value
*
* @throws \InvalidArgumentException
*/
public function getOption($key)
public function getOption(string $key)
{
if (!\array_key_exists($key, $this->options)) {
throw new \InvalidArgumentException(sprintf('The Router does not support the "%s" option.', $key));
Expand Down Expand Up @@ -237,15 +234,15 @@ public function setConfigCacheFactory(ConfigCacheFactoryInterface $configCacheFa
/**
* {@inheritdoc}
*/
public function generate($name, $parameters = [], $referenceType = self::ABSOLUTE_PATH)
public function generate(string $name, array $parameters = [], int $referenceType = self::ABSOLUTE_PATH)
{
return $this->getGenerator()->generate($name, $parameters, $referenceType);
}

/**
* {@inheritdoc}
*/
public function match($pathinfo)
public function match(string $pathinfo)
{
return $this->getMatcher()->match($pathinfo);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
*/
class RedirectableUrlMatcher extends UrlMatcher implements RedirectableUrlMatcherInterface
{
public function redirect($path, $route, $scheme = null)
public function redirect(string $path, string $route, string $scheme = null)
{
return [
'_controller' => 'Some controller reference...',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ protected function getUrlMatcher(RouteCollection $routes, RequestContext $contex

class TestCompiledRedirectableUrlMatcher extends CompiledUrlMatcher implements RedirectableUrlMatcherInterface
{
public function redirect($path, $route, $scheme = null)
public function redirect(string $path, string $route, string $scheme = null)
{
return [];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ public function testGenerateDumperMatcherWithObject()

class TestCompiledUrlMatcher extends CompiledUrlMatcher implements RedirectableUrlMatcherInterface
{
public function redirect($path, $route, $scheme = null)
public function redirect(string $path, string $route, string $scheme = null)
{
return [];
}
Expand Down

0 comments on commit 17a86c9

Please sign in to comment.