[Http-Kernel][5.0] Add type-hints

This commit is contained in:
Philippe Segatori 2019-07-01 15:02:28 +02:00 committed by Nicolas Grekas
parent 86e1321f9b
commit 9e570a2082
37 changed files with 98 additions and 152 deletions

View File

@ -20,8 +20,6 @@ interface CacheClearerInterface
{ {
/** /**
* Clears any caches necessary. * Clears any caches necessary.
*
* @param string $cacheDir The cache directory
*/ */
public function clear($cacheDir); public function clear(string $cacheDir);
} }

View File

@ -30,7 +30,7 @@ class ChainCacheClearer implements CacheClearerInterface
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function clear($cacheDir) public function clear(string $cacheDir)
{ {
foreach ($this->clearers as $clearer) { foreach ($this->clearers as $clearer) {
$clearer->clear($cacheDir); $clearer->clear($cacheDir);

View File

@ -49,7 +49,7 @@ class Psr6CacheClearer implements CacheClearerInterface
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function clear($cacheDir) public function clear(string $cacheDir)
{ {
foreach ($this->pools as $pool) { foreach ($this->pools as $pool) {
$pool->clear(); $pool->clear();

View File

@ -45,10 +45,8 @@ class CacheWarmerAggregate implements CacheWarmerInterface
/** /**
* Warms up the cache. * Warms up the cache.
*
* @param string $cacheDir The cache directory
*/ */
public function warmUp($cacheDir) public function warmUp(string $cacheDir)
{ {
if ($collectDeprecations = $this->debug && !\defined('PHPUNIT_COMPOSER_INSTALL')) { if ($collectDeprecations = $this->debug && !\defined('PHPUNIT_COMPOSER_INSTALL')) {
$collectedLogs = []; $collectedLogs = [];

View File

@ -43,7 +43,7 @@ final class ArgumentResolver implements ArgumentResolverInterface
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function getArguments(Request $request, $controller): array public function getArguments(Request $request, callable $controller): array
{ {
$arguments = []; $arguments = [];

View File

@ -30,5 +30,5 @@ interface ArgumentResolverInterface
* *
* @throws \RuntimeException When no value could be provided for a required argument * @throws \RuntimeException When no value could be provided for a required argument
*/ */
public function getArguments(Request $request, $controller); public function getArguments(Request $request, callable $controller);
} }

View File

@ -32,7 +32,7 @@ class ContainerControllerResolver extends ControllerResolver
parent::__construct($logger); parent::__construct($logger);
} }
protected function createController($controller) protected function createController(string $controller)
{ {
if (1 === substr_count($controller, ':')) { if (1 === substr_count($controller, ':')) {
$controller = str_replace(':', '::', $controller); $controller = str_replace(':', '::', $controller);
@ -45,7 +45,7 @@ class ContainerControllerResolver extends ControllerResolver
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
protected function instantiateController($class) protected function instantiateController(string $class)
{ {
if ($this->container->has($class)) { if ($this->container->has($class)) {
return $this->container->get($class); return $this->container->get($class);

View File

@ -94,11 +94,9 @@ class ControllerResolver implements ControllerResolverInterface
/** /**
* Returns a callable for the given controller. * Returns a callable for the given controller.
* *
* @param string $controller A Controller string
*
* @return callable A PHP callable * @return callable A PHP callable
*/ */
protected function createController($controller) protected function createController(string $controller)
{ {
if (false === strpos($controller, '::')) { if (false === strpos($controller, '::')) {
return $this->instantiateController($controller); return $this->instantiateController($controller);
@ -124,11 +122,9 @@ class ControllerResolver implements ControllerResolverInterface
/** /**
* Returns an instantiated controller. * Returns an instantiated controller.
* *
* @param string $class A class name
*
* @return object * @return object
*/ */
protected function instantiateController($class) protected function instantiateController(string $class)
{ {
return new $class(); return new $class();
} }

View File

@ -31,7 +31,7 @@ class TraceableArgumentResolver implements ArgumentResolverInterface
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function getArguments(Request $request, $controller) public function getArguments(Request $request, callable $controller)
{ {
$e = $this->stopwatch->start('controller.get_arguments'); $e = $this->stopwatch->start('controller.get_arguments');

View File

@ -35,7 +35,7 @@ class LazyLoadingFragmentHandler extends FragmentHandler
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function render($uri, $renderer = 'inline', array $options = []) public function render($uri, string $renderer = 'inline', array $options = [])
{ {
if (!isset($this->initialized[$renderer]) && $this->container->has($renderer)) { if (!isset($this->initialized[$renderer]) && $this->container->has($renderer)) {
$this->addRenderer($this->container->get($renderer)); $this->addRenderer($this->container->get($renderer));

View File

@ -98,13 +98,7 @@ class ExceptionListener implements EventSubscriberInterface
]; ];
} }
/** protected function logException(\Exception $exception, string $message)
* Logs an exception.
*
* @param \Exception $exception The \Exception instance
* @param string $message The error message to log
*/
protected function logException(\Exception $exception, $message)
{ {
if (null !== $this->logger) { if (null !== $this->logger) {
if (!$exception instanceof HttpExceptionInterface || $exception->getStatusCode() >= 500) { if (!$exception instanceof HttpExceptionInterface || $exception->getStatusCode() >= 500) {

View File

@ -60,15 +60,14 @@ class FragmentHandler
* *
* * ignore_errors: true to return an empty string in case of an error * * ignore_errors: true to return an empty string in case of an error
* *
* @param string|ControllerReference $uri A URI as a string or a ControllerReference instance * @param string|ControllerReference $uri A URI as a string or a ControllerReference instance
* @param string $renderer The renderer name
* *
* @return string|null The Response content or null when the Response is streamed * @return string|null The Response content or null when the Response is streamed
* *
* @throws \InvalidArgumentException when the renderer does not exist * @throws \InvalidArgumentException when the renderer does not exist
* @throws \LogicException when no master request is being handled * @throws \LogicException when no master request is being handled
*/ */
public function render($uri, $renderer = 'inline', array $options = []) public function render($uri, string $renderer = 'inline', array $options = [])
{ {
if (!isset($options['ignore_errors'])) { if (!isset($options['ignore_errors'])) {
$options['ignore_errors'] = !$this->debug; $options['ignore_errors'] = !$this->debug;

View File

@ -27,11 +27,9 @@ abstract class RoutableFragmentRenderer implements FragmentRendererInterface
/** /**
* Sets the fragment path that triggers the fragment listener. * Sets the fragment path that triggers the fragment listener.
* *
* @param string $path The path
*
* @see FragmentListener * @see FragmentListener
*/ */
public function setFragmentPath($path) public function setFragmentPath(string $path)
{ {
$this->fragmentPath = $path; $this->fragmentPath = $path;
} }
@ -44,7 +42,7 @@ abstract class RoutableFragmentRenderer implements FragmentRendererInterface
* *
* @return string A fragment URI * @return string A fragment URI
*/ */
protected function generateFragmentUri(ControllerReference $reference, Request $request, $absolute = false, $strict = true) protected function generateFragmentUri(ControllerReference $reference, Request $request, bool $absolute = false, bool $strict = true)
{ {
if ($strict) { if ($strict) {
$this->checkNonScalar($reference->attributes); $this->checkNonScalar($reference->attributes);

View File

@ -88,7 +88,7 @@ abstract class AbstractSurrogate implements SurrogateInterface
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function handle(HttpCache $cache, $uri, $alt, $ignoreErrors) public function handle(HttpCache $cache, string $uri, string $alt, bool $ignoreErrors)
{ {
$subRequest = Request::create($uri, Request::METHOD_GET, [], $cache->getRequest()->cookies->all(), [], $cache->getRequest()->server->all()); $subRequest = Request::create($uri, Request::METHOD_GET, [], $cache->getRequest()->cookies->all(), [], $cache->getRequest()->server->all());

View File

@ -45,7 +45,7 @@ class Esi extends AbstractSurrogate
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function renderIncludeTag($uri, $alt = null, $ignoreErrors = true, $comment = '') public function renderIncludeTag(string $uri, string $alt = null, bool $ignoreErrors = true, string $comment = '')
{ {
$html = sprintf('<esi:include src="%s"%s%s />', $html = sprintf('<esi:include src="%s"%s%s />',
$uri, $uri,

View File

@ -190,7 +190,7 @@ class HttpCache implements HttpKernelInterface, TerminableInterface
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function handle(Request $request, $type = HttpKernelInterface::MASTER_REQUEST, $catch = true) public function handle(Request $request, int $type = HttpKernelInterface::MASTER_REQUEST, bool $catch = true)
{ {
// FIXME: catch exceptions and implement a 500 error page here? -> in Varnish, there is a built-in error page mechanism // FIXME: catch exceptions and implement a 500 error page here? -> in Varnish, there is a built-in error page mechanism
if (HttpKernelInterface::MASTER_REQUEST === $type) { if (HttpKernelInterface::MASTER_REQUEST === $type) {
@ -260,7 +260,7 @@ class HttpCache implements HttpKernelInterface, TerminableInterface
* *
* @return Response A Response instance * @return Response A Response instance
*/ */
protected function pass(Request $request, $catch = false) protected function pass(Request $request, bool $catch = false)
{ {
$this->record($request, 'pass'); $this->record($request, 'pass');
@ -278,7 +278,7 @@ class HttpCache implements HttpKernelInterface, TerminableInterface
* *
* @see RFC2616 13.10 * @see RFC2616 13.10
*/ */
protected function invalidate(Request $request, $catch = false) protected function invalidate(Request $request, bool $catch = false)
{ {
$response = $this->pass($request, $catch); $response = $this->pass($request, $catch);
@ -324,7 +324,7 @@ class HttpCache implements HttpKernelInterface, TerminableInterface
* *
* @throws \Exception * @throws \Exception
*/ */
protected function lookup(Request $request, $catch = false) protected function lookup(Request $request, bool $catch = false)
{ {
try { try {
$entry = $this->store->lookup($request); $entry = $this->store->lookup($request);
@ -367,7 +367,7 @@ class HttpCache implements HttpKernelInterface, TerminableInterface
* *
* @return Response A Response instance * @return Response A Response instance
*/ */
protected function validate(Request $request, Response $entry, $catch = false) protected function validate(Request $request, Response $entry, bool $catch = false)
{ {
$subRequest = clone $request; $subRequest = clone $request;
@ -428,7 +428,7 @@ class HttpCache implements HttpKernelInterface, TerminableInterface
* *
* @return Response A Response instance * @return Response A Response instance
*/ */
protected function fetch(Request $request, $catch = false) protected function fetch(Request $request, bool $catch = false)
{ {
$subRequest = clone $request; $subRequest = clone $request;
@ -461,7 +461,7 @@ class HttpCache implements HttpKernelInterface, TerminableInterface
* *
* @return Response A Response instance * @return Response A Response instance
*/ */
protected function forward(Request $request, $catch = false, Response $entry = null) protected function forward(Request $request, bool $catch = false, Response $entry = null)
{ {
if ($this->surrogate) { if ($this->surrogate) {
$this->surrogate->addSurrogateCapability($request); $this->surrogate->addSurrogateCapability($request);

View File

@ -42,7 +42,7 @@ class Ssi extends AbstractSurrogate
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function renderIncludeTag($uri, $alt = null, $ignoreErrors = true, $comment = '') public function renderIncludeTag(string $uri, string $alt = null, bool $ignoreErrors = true, string $comment = '')
{ {
return sprintf('<!--#include virtual="%s" -->', $uri); return sprintf('<!--#include virtual="%s" -->', $uri);
} }

View File

@ -198,7 +198,7 @@ class Store implements StoreInterface
$entry[1]['vary'] = ['']; $entry[1]['vary'] = [''];
} }
if ($entry[1]['vary'][0] != $vary || !$this->requestsMatch($vary, $entry[0], $storedEnv)) { if ($entry[1]['vary'][0] != $vary || !$this->requestsMatch($vary ?? '', $entry[0], $storedEnv)) {
$entries[] = $entry; $entries[] = $entry;
} }
} }
@ -256,9 +256,9 @@ class Store implements StoreInterface
* Determines whether two Request HTTP header sets are non-varying based on * Determines whether two Request HTTP header sets are non-varying based on
* the vary response header value provided. * the vary response header value provided.
* *
* @param string $vary A Response vary header * @param string|null $vary A Response vary header
* @param array $env1 A Request HTTP header array * @param array $env1 A Request HTTP header array
* @param array $env2 A Request HTTP header array * @param array $env2 A Request HTTP header array
*/ */
private function requestsMatch(?string $vary, array $env1, array $env2): bool private function requestsMatch(?string $vary, array $env1, array $env2): bool
{ {
@ -297,11 +297,9 @@ class Store implements StoreInterface
* *
* This method purges both the HTTP and the HTTPS version of the cache entry. * This method purges both the HTTP and the HTTPS version of the cache entry.
* *
* @param string $url A URL
*
* @return bool true if the URL exists with either HTTP or HTTPS scheme and has been purged, false otherwise * @return bool true if the URL exists with either HTTP or HTTPS scheme and has been purged, false otherwise
*/ */
public function purge($url) public function purge(string $url)
{ {
$http = preg_replace('#^https:#', 'http:', $url); $http = preg_replace('#^https:#', 'http:', $url);
$https = preg_replace('#^http:#', 'https:', $url); $https = preg_replace('#^http:#', 'https:', $url);

View File

@ -70,11 +70,9 @@ interface StoreInterface
/** /**
* Purges data for the given URL. * Purges data for the given URL.
* *
* @param string $url A URL
*
* @return bool true if the URL exists and has been purged, false otherwise * @return bool true if the URL exists and has been purged, false otherwise
*/ */
public function purge($url); public function purge(string $url);
/** /**
* Cleanups storage. * Cleanups storage.

View File

@ -59,14 +59,12 @@ interface SurrogateInterface
/** /**
* Renders a Surrogate tag. * Renders a Surrogate tag.
* *
* @param string $uri A URI * @param string $alt An alternate URI
* @param string $alt An alternate URI * @param string $comment A comment to add as an esi:include tag
* @param bool $ignoreErrors Whether to ignore errors or not
* @param string $comment A comment to add as an esi:include tag
* *
* @return string * @return string
*/ */
public function renderIncludeTag($uri, $alt = null, $ignoreErrors = true, $comment = ''); public function renderIncludeTag(string $uri, string $alt = null, bool $ignoreErrors = true, string $comment = '');
/** /**
* Replaces a Response Surrogate tags with the included resource content. * Replaces a Response Surrogate tags with the included resource content.
@ -78,14 +76,12 @@ interface SurrogateInterface
/** /**
* Handles a Surrogate from the cache. * Handles a Surrogate from the cache.
* *
* @param string $uri The main URI * @param string $alt An alternative URI
* @param string $alt An alternative URI
* @param bool $ignoreErrors Whether to ignore errors or not
* *
* @return string * @return string
* *
* @throws \RuntimeException * @throws \RuntimeException
* @throws \Exception * @throws \Exception
*/ */
public function handle(HttpCache $cache, $uri, $alt, $ignoreErrors); public function handle(HttpCache $cache, string $uri, string $alt, bool $ignoreErrors);
} }

View File

@ -39,7 +39,7 @@ final class HttpClientKernel implements HttpKernelInterface
$this->client = $client ?? HttpClient::create(); $this->client = $client ?? HttpClient::create();
} }
public function handle(Request $request, $type = HttpKernelInterface::MASTER_REQUEST, $catch = true) public function handle(Request $request, int $type = HttpKernelInterface::MASTER_REQUEST, bool $catch = true)
{ {
$headers = $this->getHeaders($request); $headers = $this->getHeaders($request);
$body = ''; $body = '';

View File

@ -59,7 +59,7 @@ class HttpKernel implements HttpKernelInterface, TerminableInterface
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function handle(Request $request, $type = HttpKernelInterface::MASTER_REQUEST, $catch = true) public function handle(Request $request, int $type = HttpKernelInterface::MASTER_REQUEST, bool $catch = true)
{ {
$request->headers->set('X-Php-Ob-Level', ob_get_level()); $request->headers->set('X-Php-Ob-Level', ob_get_level());

View File

@ -50,10 +50,8 @@ class HttpKernelBrowser extends AbstractBrowser
/** /**
* Sets whether to catch exceptions when the kernel is handling a request. * Sets whether to catch exceptions when the kernel is handling a request.
*
* @param bool $catchExceptions Whether to catch exceptions
*/ */
public function catchExceptions($catchExceptions) public function catchExceptions(bool $catchExceptions)
{ {
$this->catchExceptions = $catchExceptions; $this->catchExceptions = $catchExceptions;
} }

View File

@ -38,5 +38,5 @@ interface HttpKernelInterface
* *
* @throws \Exception When an Exception occurs during processing * @throws \Exception When an Exception occurs during processing
*/ */
public function handle(Request $request, $type = self::MASTER_REQUEST, $catch = true); public function handle(Request $request, int $type = self::MASTER_REQUEST, bool $catch = true);
} }

View File

@ -133,7 +133,7 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function reboot($warmupDir) public function reboot(?string $warmupDir)
{ {
$this->shutdown(); $this->shutdown();
$this->warmupDir = $warmupDir; $this->warmupDir = $warmupDir;
@ -178,7 +178,7 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function handle(Request $request, $type = HttpKernelInterface::MASTER_REQUEST, $catch = true) public function handle(Request $request, int $type = HttpKernelInterface::MASTER_REQUEST, bool $catch = true)
{ {
$this->boot(); $this->boot();
++$this->requestStackSize; ++$this->requestStackSize;
@ -212,7 +212,7 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function getBundle($name) public function getBundle(string $name)
{ {
if (!isset($this->bundles[$name])) { if (!isset($this->bundles[$name])) {
$class = \get_class($this); $class = \get_class($this);
@ -229,7 +229,7 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl
* *
* @throws \RuntimeException if a custom resource is hidden by a resource in a derived bundle * @throws \RuntimeException if a custom resource is hidden by a resource in a derived bundle
*/ */
public function locateResource($name, $dir = null, $first = true) public function locateResource(string $name, string $dir = null, bool $first = true)
{ {
if ('@' !== $name[0]) { if ('@' !== $name[0]) {
throw new \InvalidArgumentException(sprintf('A resource name must start with @ ("%s" given).', $name)); throw new \InvalidArgumentException(sprintf('A resource name must start with @ ("%s" given).', $name));
@ -667,7 +667,7 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl
* @param string $class The name of the class to generate * @param string $class The name of the class to generate
* @param string $baseClass The name of the container's base class * @param string $baseClass The name of the container's base class
*/ */
protected function dumpContainer(ConfigCache $cache, ContainerBuilder $container, $class, $baseClass) protected function dumpContainer(ConfigCache $cache, ContainerBuilder $container, string $class, string $baseClass)
{ {
// cache the container // cache the container
$dumper = new PhpDumper($container); $dumper = new PhpDumper($container);
@ -728,11 +728,9 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl
* We don't use the PHP php_strip_whitespace() function * We don't use the PHP php_strip_whitespace() function
* as we want the content to be readable and well-formatted. * as we want the content to be readable and well-formatted.
* *
* @param string $source A PHP string
*
* @return string The PHP string with the comments removed * @return string The PHP string with the comments removed
*/ */
public static function stripComments($source) public static function stripComments(string $source)
{ {
if (!\function_exists('token_get_all')) { if (!\function_exists('token_get_all')) {
return $source; return $source;

View File

@ -58,13 +58,11 @@ interface KernelInterface extends HttpKernelInterface
/** /**
* Returns a bundle. * Returns a bundle.
* *
* @param string $name Bundle name
*
* @return BundleInterface A BundleInterface instance * @return BundleInterface A BundleInterface instance
* *
* @throws \InvalidArgumentException when the bundle is not enabled * @throws \InvalidArgumentException when the bundle is not enabled
*/ */
public function getBundle($name); public function getBundle(string $name);
/** /**
* Returns the file path for a given bundle resource. * Returns the file path for a given bundle resource.
@ -85,16 +83,14 @@ interface KernelInterface extends HttpKernelInterface
* *
* before looking in the bundle resource folder. * before looking in the bundle resource folder.
* *
* @param string $name A resource name to locate * @param bool $first Whether to return the first path or paths for all matching bundles
* @param string $dir A directory where to look for the resource first
* @param bool $first Whether to return the first path or paths for all matching bundles
* *
* @return string|array The absolute path of the resource or an array if $first is false * @return string|array The absolute path of the resource or an array if $first is false
* *
* @throws \InvalidArgumentException if the file cannot be found or the name is not valid * @throws \InvalidArgumentException if the file cannot be found or the name is not valid
* @throws \RuntimeException if the name contains invalid/unsafe characters * @throws \RuntimeException if the name contains invalid/unsafe characters
*/ */
public function locateResource($name, $dir = null, $first = true); public function locateResource(string $name, string $dir = null, bool $first = true);
/** /**
* Gets the environment. * Gets the environment.

View File

@ -189,11 +189,9 @@ class FileProfilerStorage implements ProfilerStorageInterface
/** /**
* Gets filename to store data, associated to the token. * Gets filename to store data, associated to the token.
* *
* @param string $token
*
* @return string The profile filename * @return string The profile filename
*/ */
protected function getFilename($token) protected function getFilename(string $token)
{ {
// Uses 4 last characters, because first are mostly the same. // Uses 4 last characters, because first are mostly the same.
$folderA = substr($token, -2, 2); $folderA = substr($token, -2, 2);

View File

@ -48,12 +48,7 @@ class Profile
$this->token = $token; $this->token = $token;
} }
/** public function setToken(string $token)
* Sets the token.
*
* @param string $token The token
*/
public function setToken($token)
{ {
$this->token = $token; $this->token = $token;
} }
@ -106,19 +101,12 @@ class Profile
return $this->ip; return $this->ip;
} }
/** public function setIp(string $ip)
* Sets the IP.
*
* @param string $ip
*/
public function setIp($ip)
{ {
$this->ip = $ip; $this->ip = $ip;
} }
/** /**
* Returns the request method.
*
* @return string The request method * @return string The request method
*/ */
public function getMethod() public function getMethod()
@ -132,8 +120,6 @@ class Profile
} }
/** /**
* Returns the URL.
*
* @return string The URL * @return string The URL
*/ */
public function getUrl() public function getUrl()
@ -141,14 +127,12 @@ class Profile
return $this->url; return $this->url;
} }
public function setUrl($url) public function setUrl(string $url)
{ {
$this->url = $url; $this->url = $url;
} }
/** /**
* Returns the time.
*
* @return int The time * @return int The time
*/ */
public function getTime() public function getTime()
@ -160,18 +144,12 @@ class Profile
return $this->time; return $this->time;
} }
/** public function setTime(int $time)
* @param int $time The time
*/
public function setTime($time)
{ {
$this->time = $time; $this->time = $time;
} }
/** public function setStatusCode(int $statusCode)
* @param int $statusCode
*/
public function setStatusCode($statusCode)
{ {
$this->statusCode = $statusCode; $this->statusCode = $statusCode;
} }
@ -230,13 +208,11 @@ class Profile
/** /**
* Gets a Collector by name. * Gets a Collector by name.
* *
* @param string $name A collector name
*
* @return DataCollectorInterface A DataCollectorInterface instance * @return DataCollectorInterface A DataCollectorInterface instance
* *
* @throws \InvalidArgumentException if the collector does not exist * @throws \InvalidArgumentException if the collector does not exist
*/ */
public function getCollector($name) public function getCollector(string $name)
{ {
if (!isset($this->collectors[$name])) { if (!isset($this->collectors[$name])) {
throw new \InvalidArgumentException(sprintf('Collector "%s" does not exist.', $name)); throw new \InvalidArgumentException(sprintf('Collector "%s" does not exist.', $name));
@ -277,13 +253,9 @@ class Profile
} }
/** /**
* Returns true if a Collector for the given name exists.
*
* @param string $name A collector name
*
* @return bool * @return bool
*/ */
public function hasCollector($name) public function hasCollector(string $name)
{ {
return isset($this->collectors[$name]); return isset($this->collectors[$name]);
} }

View File

@ -77,11 +77,9 @@ class Profiler implements ResetInterface
/** /**
* Loads the Profile for the given token. * Loads the Profile for the given token.
* *
* @param string $token A token
*
* @return Profile A Profile instance * @return Profile A Profile instance
*/ */
public function loadProfile($token) public function loadProfile(string $token)
{ {
return $this->storage->read($token); return $this->storage->read($token);
} }
@ -118,19 +116,15 @@ class Profiler implements ResetInterface
/** /**
* Finds profiler tokens for the given criteria. * Finds profiler tokens for the given criteria.
* *
* @param string $ip The IP * @param string|null $limit The maximum number of tokens to return
* @param string $url The URL * @param string|null $start The start date to search from
* @param string $limit The maximum number of tokens to return * @param string|null $end The end date to search to
* @param string $method The request method
* @param string $start The start date to search from
* @param string $end The end date to search to
* @param string $statusCode The request status code
* *
* @return array An array of tokens * @return array An array of tokens
* *
* @see https://php.net/datetime.formats for the supported date/time formats * @see https://php.net/datetime.formats for the supported date/time formats
*/ */
public function find($ip, $url, $limit, $method, $start, $end, $statusCode = null) public function find(?string $ip, ?string $url, ?string $limit, ?string $method, ?string $start, ?string $end, string $statusCode = null)
{ {
return $this->storage->find($ip, $url, $limit, $method, $this->getTimestamp($start), $this->getTimestamp($end), $statusCode); return $this->storage->find($ip, $url, $limit, $method, $this->getTimestamp($start), $this->getTimestamp($end), $statusCode);
} }
@ -219,7 +213,7 @@ class Profiler implements ResetInterface
* *
* @return bool * @return bool
*/ */
public function has($name) public function has(string $name)
{ {
return isset($this->collectors[$name]); return isset($this->collectors[$name]);
} }
@ -233,7 +227,7 @@ class Profiler implements ResetInterface
* *
* @throws \InvalidArgumentException if the collector does not exist * @throws \InvalidArgumentException if the collector does not exist
*/ */
public function get($name) public function get(string $name)
{ {
if (!isset($this->collectors[$name])) { if (!isset($this->collectors[$name])) {
throw new \InvalidArgumentException(sprintf('Collector "%s" does not exist.', $name)); throw new \InvalidArgumentException(sprintf('Collector "%s" does not exist.', $name));

View File

@ -26,5 +26,5 @@ interface RebootableInterface
* *
* @param string|null $warmupDir pass null to reboot in the regular cache directory * @param string|null $warmupDir pass null to reboot in the regular cache directory
*/ */
public function reboot($warmupDir); public function reboot(?string $warmupDir);
} }

View File

@ -292,31 +292,31 @@ class ArgumentResolverTest extends TestCase
{ {
} }
protected function controllerWithFooAndDefaultBar($foo, $bar = null) public function controllerWithFooAndDefaultBar($foo, $bar = null)
{ {
} }
protected function controllerWithFooBarFoobar($foo, $bar, $foobar) public function controllerWithFooBarFoobar($foo, $bar, $foobar)
{ {
} }
protected function controllerWithRequest(Request $request) public function controllerWithRequest(Request $request)
{ {
} }
protected function controllerWithExtendingRequest(ExtendingRequest $request) public function controllerWithExtendingRequest(ExtendingRequest $request)
{ {
} }
protected function controllerWithSession(Session $session) public function controllerWithSession(Session $session)
{ {
} }
protected function controllerWithSessionInterface(SessionInterface $session) public function controllerWithSessionInterface(SessionInterface $session)
{ {
} }
protected function controllerWithExtendingSession(ExtendingSession $session) public function controllerWithExtendingSession(ExtendingSession $session)
{ {
} }
} }

View File

@ -72,7 +72,7 @@ class TestHttpKernel extends HttpKernel implements ControllerResolverInterface,
return [$this, 'callController']; return [$this, 'callController'];
} }
public function getArguments(Request $request, $controller) public function getArguments(Request $request, callable $controller)
{ {
return [$request]; return [$request];
} }

View File

@ -55,7 +55,7 @@ class TestMultipleHttpKernel extends HttpKernel implements ControllerResolverInt
return [$this, 'callController']; return [$this, 'callController'];
} }
public function getArguments(Request $request, $controller) public function getArguments(Request $request, callable $controller)
{ {
return [$request]; return [$request];
} }

View File

@ -52,10 +52,12 @@ class FileProfilerStorageTest extends TestCase
$parentProfile = new Profile('token_parent'); $parentProfile = new Profile('token_parent');
$parentProfile->setIp('127.0.0.1'); $parentProfile->setIp('127.0.0.1');
$parentProfile->setUrl('http://foo.bar/parent'); $parentProfile->setUrl('http://foo.bar/parent');
$parentProfile->setStatusCode(200);
$childProfile = new Profile('token_child'); $childProfile = new Profile('token_child');
$childProfile->setIp('127.0.0.1'); $childProfile->setIp('127.0.0.1');
$childProfile->setUrl('http://foo.bar/child'); $childProfile->setUrl('http://foo.bar/child');
$childProfile->setStatusCode(200);
$parentProfile->addChild($childProfile); $parentProfile->addChild($childProfile);
@ -82,21 +84,33 @@ class FileProfilerStorageTest extends TestCase
// supposed to contain them) // supposed to contain them)
$profile = new Profile('simple_quote'); $profile = new Profile('simple_quote');
$profile->setUrl('http://foo.bar/\''); $profile->setUrl('http://foo.bar/\'');
$profile->setIp('127.0.0.1');
$profile->setStatusCode(200);
$this->storage->write($profile); $this->storage->write($profile);
$this->assertNotFalse($this->storage->read('simple_quote'), '->write() accepts single quotes in URL'); $this->assertNotFalse($this->storage->read('simple_quote'), '->write() accepts single quotes in URL');
$profile = new Profile('double_quote'); $profile = new Profile('double_quote');
$profile->setUrl('http://foo.bar/"'); $profile->setUrl('http://foo.bar/"');
$profile->setIp('127.0.0.1');
$profile->setStatusCode(200);
$this->storage->write($profile); $this->storage->write($profile);
$this->assertNotFalse($this->storage->read('double_quote'), '->write() accepts double quotes in URL'); $this->assertNotFalse($this->storage->read('double_quote'), '->write() accepts double quotes in URL');
$profile = new Profile('backslash'); $profile = new Profile('backslash');
$profile->setUrl('http://foo.bar/\\'); $profile->setUrl('http://foo.bar/\\');
$profile->setIp('127.0.0.1');
$profile->setStatusCode(200);
$this->storage->write($profile); $this->storage->write($profile);
$this->assertNotFalse($this->storage->read('backslash'), '->write() accepts backslash in URL'); $this->assertNotFalse($this->storage->read('backslash'), '->write() accepts backslash in URL');
$profile = new Profile('comma'); $profile = new Profile('comma');
$profile->setUrl('http://foo.bar/,'); $profile->setUrl('http://foo.bar/,');
$profile->setIp('127.0.0.1');
$profile->setStatusCode(200);
$this->storage->write($profile); $this->storage->write($profile);
$this->assertNotFalse($this->storage->read('comma'), '->write() accepts comma in URL'); $this->assertNotFalse($this->storage->read('comma'), '->write() accepts comma in URL');
} }
@ -105,6 +119,8 @@ class FileProfilerStorageTest extends TestCase
{ {
$profile = new Profile('token'); $profile = new Profile('token');
$profile->setUrl('http://example.com/'); $profile->setUrl('http://example.com/');
$profile->setIp('127.0.0.1');
$profile->setStatusCode(200);
$this->assertTrue($this->storage->write($profile), '->write() returns true when the token is unique'); $this->assertTrue($this->storage->write($profile), '->write() returns true when the token is unique');
@ -245,6 +261,7 @@ class FileProfilerStorageTest extends TestCase
$profile->setIp('127.0.0.1'); $profile->setIp('127.0.0.1');
$profile->setUrl('http://example.com/'); $profile->setUrl('http://example.com/');
$profile->setMethod('GET'); $profile->setMethod('GET');
$profile->setStatusCode(200);
$this->storage->write($profile); $this->storage->write($profile);
$this->assertNotFalse($this->storage->read('token1')); $this->assertNotFalse($this->storage->read('token1'));
@ -254,6 +271,7 @@ class FileProfilerStorageTest extends TestCase
$profile->setIp('127.0.0.1'); $profile->setIp('127.0.0.1');
$profile->setUrl('http://example.net/'); $profile->setUrl('http://example.net/');
$profile->setMethod('GET'); $profile->setMethod('GET');
$profile->setStatusCode(200);
$this->storage->write($profile); $this->storage->write($profile);
$this->assertNotFalse($this->storage->read('token2')); $this->assertNotFalse($this->storage->read('token2'));

View File

@ -28,6 +28,7 @@ class ProfilerTest extends TestCase
{ {
$request = new Request(); $request = new Request();
$request->query->set('foo', 'bar'); $request->query->set('foo', 'bar');
$request->server->set('REMOTE_ADDR', '127.0.0.1');
$response = new Response('', 204); $response = new Response('', 204);
$collector = new RequestDataCollector(); $collector = new RequestDataCollector();

View File

@ -30,7 +30,7 @@ class TestHttpKernel extends HttpKernel implements ControllerResolverInterface,
return [$this, 'callController']; return [$this, 'callController'];
} }
public function getArguments(Request $request, $controller) public function getArguments(Request $request, callable $controller)
{ {
return [$request]; return [$request];
} }

View File

@ -37,11 +37,9 @@ class UriSigner
* The given URI is signed by adding the query string parameter * The given URI is signed by adding the query string parameter
* which value depends on the URI and the secret. * which value depends on the URI and the secret.
* *
* @param string $uri A URI to sign
*
* @return string The signed URI * @return string The signed URI
*/ */
public function sign($uri) public function sign(string $uri)
{ {
$url = parse_url($uri); $url = parse_url($uri);
if (isset($url['query'])) { if (isset($url['query'])) {
@ -59,11 +57,9 @@ class UriSigner
/** /**
* Checks that a URI contains the correct hash. * Checks that a URI contains the correct hash.
* *
* @param string $uri A signed URI
*
* @return bool True if the URI is signed correctly, false otherwise * @return bool True if the URI is signed correctly, false otherwise
*/ */
public function check($uri) public function check(string $uri)
{ {
$url = parse_url($uri); $url = parse_url($uri);
if (isset($url['query'])) { if (isset($url['query'])) {