[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.
*
* @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}
*/
public function clear($cacheDir)
public function clear(string $cacheDir)
{
foreach ($this->clearers as $clearer) {
$clearer->clear($cacheDir);

View File

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

View File

@ -45,10 +45,8 @@ class CacheWarmerAggregate implements CacheWarmerInterface
/**
* 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')) {
$collectedLogs = [];

View File

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

View File

@ -30,5 +30,5 @@ interface ArgumentResolverInterface
*
* @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);
}
protected function createController($controller)
protected function createController(string $controller)
{
if (1 === substr_count($controller, ':')) {
$controller = str_replace(':', '::', $controller);
@ -45,7 +45,7 @@ class ContainerControllerResolver extends ControllerResolver
/**
* {@inheritdoc}
*/
protected function instantiateController($class)
protected function instantiateController(string $class)
{
if ($this->container->has($class)) {
return $this->container->get($class);

View File

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

View File

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

View File

@ -35,7 +35,7 @@ class LazyLoadingFragmentHandler extends FragmentHandler
/**
* {@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)) {
$this->addRenderer($this->container->get($renderer));

View File

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

View File

@ -61,14 +61,13 @@ class FragmentHandler
* * 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 $renderer The renderer name
*
* @return string|null The Response content or null when the Response is streamed
*
* @throws \InvalidArgumentException when the renderer does not exist
* @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'])) {
$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.
*
* @param string $path The path
*
* @see FragmentListener
*/
public function setFragmentPath($path)
public function setFragmentPath(string $path)
{
$this->fragmentPath = $path;
}
@ -44,7 +42,7 @@ abstract class RoutableFragmentRenderer implements FragmentRendererInterface
*
* @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) {
$this->checkNonScalar($reference->attributes);

View File

@ -88,7 +88,7 @@ abstract class AbstractSurrogate implements SurrogateInterface
/**
* {@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());

View File

@ -45,7 +45,7 @@ class Esi extends AbstractSurrogate
/**
* {@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 />',
$uri,

View File

@ -190,7 +190,7 @@ class HttpCache implements HttpKernelInterface, TerminableInterface
/**
* {@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
if (HttpKernelInterface::MASTER_REQUEST === $type) {
@ -260,7 +260,7 @@ class HttpCache implements HttpKernelInterface, TerminableInterface
*
* @return Response A Response instance
*/
protected function pass(Request $request, $catch = false)
protected function pass(Request $request, bool $catch = false)
{
$this->record($request, 'pass');
@ -278,7 +278,7 @@ class HttpCache implements HttpKernelInterface, TerminableInterface
*
* @see RFC2616 13.10
*/
protected function invalidate(Request $request, $catch = false)
protected function invalidate(Request $request, bool $catch = false)
{
$response = $this->pass($request, $catch);
@ -324,7 +324,7 @@ class HttpCache implements HttpKernelInterface, TerminableInterface
*
* @throws \Exception
*/
protected function lookup(Request $request, $catch = false)
protected function lookup(Request $request, bool $catch = false)
{
try {
$entry = $this->store->lookup($request);
@ -367,7 +367,7 @@ class HttpCache implements HttpKernelInterface, TerminableInterface
*
* @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;
@ -428,7 +428,7 @@ class HttpCache implements HttpKernelInterface, TerminableInterface
*
* @return Response A Response instance
*/
protected function fetch(Request $request, $catch = false)
protected function fetch(Request $request, bool $catch = false)
{
$subRequest = clone $request;
@ -461,7 +461,7 @@ class HttpCache implements HttpKernelInterface, TerminableInterface
*
* @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) {
$this->surrogate->addSurrogateCapability($request);

View File

@ -42,7 +42,7 @@ class Ssi extends AbstractSurrogate
/**
* {@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);
}

View File

@ -198,7 +198,7 @@ class Store implements StoreInterface
$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;
}
}
@ -256,7 +256,7 @@ class Store implements StoreInterface
* Determines whether two Request HTTP header sets are non-varying based on
* 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 $env2 A Request HTTP header array
*/
@ -297,11 +297,9 @@ class Store implements StoreInterface
*
* 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
*/
public function purge($url)
public function purge(string $url)
{
$http = preg_replace('#^https:#', 'http:', $url);
$https = preg_replace('#^http:#', 'https:', $url);

View File

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

View File

@ -59,14 +59,12 @@ interface SurrogateInterface
/**
* Renders a Surrogate tag.
*
* @param string $uri A URI
* @param string $alt An alternate URI
* @param bool $ignoreErrors Whether to ignore errors or not
* @param string $comment A comment to add as an esi:include tag
*
* @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.
@ -78,14 +76,12 @@ interface SurrogateInterface
/**
* Handles a Surrogate from the cache.
*
* @param string $uri The main URI
* @param string $alt An alternative URI
* @param bool $ignoreErrors Whether to ignore errors or not
*
* @return string
*
* @throws \RuntimeException
* @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();
}
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);
$body = '';

View File

@ -59,7 +59,7 @@ class HttpKernel implements HttpKernelInterface, TerminableInterface
/**
* {@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());

View File

@ -50,10 +50,8 @@ class HttpKernelBrowser extends AbstractBrowser
/**
* 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;
}

View File

@ -38,5 +38,5 @@ interface HttpKernelInterface
*
* @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}
*/
public function reboot($warmupDir)
public function reboot(?string $warmupDir)
{
$this->shutdown();
$this->warmupDir = $warmupDir;
@ -178,7 +178,7 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl
/**
* {@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->requestStackSize;
@ -212,7 +212,7 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl
/**
* {@inheritdoc}
*/
public function getBundle($name)
public function getBundle(string $name)
{
if (!isset($this->bundles[$name])) {
$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
*/
public function locateResource($name, $dir = null, $first = true)
public function locateResource(string $name, string $dir = null, bool $first = true)
{
if ('@' !== $name[0]) {
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 $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
$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
* 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
*/
public static function stripComments($source)
public static function stripComments(string $source)
{
if (!\function_exists('token_get_all')) {
return $source;

View File

@ -58,13 +58,11 @@ interface KernelInterface extends HttpKernelInterface
/**
* Returns a bundle.
*
* @param string $name Bundle name
*
* @return BundleInterface A BundleInterface instance
*
* @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.
@ -85,8 +83,6 @@ interface KernelInterface extends HttpKernelInterface
*
* before looking in the bundle resource folder.
*
* @param string $name A resource name to locate
* @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
@ -94,7 +90,7 @@ interface KernelInterface extends HttpKernelInterface
* @throws \InvalidArgumentException if the file cannot be found or the name is not valid
* @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.

View File

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

View File

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

View File

@ -77,11 +77,9 @@ class Profiler implements ResetInterface
/**
* Loads the Profile for the given token.
*
* @param string $token A token
*
* @return Profile A Profile instance
*/
public function loadProfile($token)
public function loadProfile(string $token)
{
return $this->storage->read($token);
}
@ -118,19 +116,15 @@ class Profiler implements ResetInterface
/**
* Finds profiler tokens for the given criteria.
*
* @param string $ip The IP
* @param string $url The URL
* @param string $limit The maximum number of tokens to return
* @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
* @param string|null $limit The maximum number of tokens to return
* @param string|null $start The start date to search from
* @param string|null $end The end date to search to
*
* @return array An array of tokens
*
* @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);
}
@ -219,7 +213,7 @@ class Profiler implements ResetInterface
*
* @return bool
*/
public function has($name)
public function has(string $name)
{
return isset($this->collectors[$name]);
}
@ -233,7 +227,7 @@ class Profiler implements ResetInterface
*
* @throws \InvalidArgumentException if the collector does not exist
*/
public function get($name)
public function get(string $name)
{
if (!isset($this->collectors[$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
*/
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'];
}
public function getArguments(Request $request, $controller)
public function getArguments(Request $request, callable $controller)
{
return [$request];
}

View File

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

View File

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

View File

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

View File

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

View File

@ -37,11 +37,9 @@ class UriSigner
* The given URI is signed by adding the query string parameter
* which value depends on the URI and the secret.
*
* @param string $uri A URI to sign
*
* @return string The signed URI
*/
public function sign($uri)
public function sign(string $uri)
{
$url = parse_url($uri);
if (isset($url['query'])) {
@ -59,11 +57,9 @@ class UriSigner
/**
* 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
*/
public function check($uri)
public function check(string $uri)
{
$url = parse_url($uri);
if (isset($url['query'])) {