From 4e0c6e1b554ac74fee526868b86d028a7c38c10e Mon Sep 17 00:00:00 2001 From: Mikael Pajunen Date: Sun, 12 Apr 2015 22:00:20 +0300 Subject: [PATCH 1/2] Replace is_callable checks with type hints Also removes tests checking the exceptions thrown from the removed is_callable checks. --- .../Component/Console/Command/Command.php | 6 +-- .../Console/Tests/Command/CommandTest.php | 10 ----- src/Symfony/Component/Debug/ErrorHandler.php | 7 +--- .../Component/Debug/ExceptionHandler.php | 5 +-- .../Component/Form/CallbackTransformer.php | 11 +---- .../Form/ChoiceList/ArrayChoiceList.php | 8 +--- .../Form/Tests/CallbackTransformerTest.php | 18 -------- .../Tests/ChoiceList/ArrayChoiceListTest.php | 8 ---- .../HttpFoundation/StreamedResponse.php | 7 +--- .../Tests/StreamedResponseTest.php | 9 ---- .../Event/FilterControllerEvent.php | 41 +------------------ .../Normalizer/AbstractNormalizer.php | 8 +--- .../Translation/PluralizationRules.php | 12 ++---- 13 files changed, 11 insertions(+), 139 deletions(-) diff --git a/src/Symfony/Component/Console/Command/Command.php b/src/Symfony/Component/Console/Command/Command.php index d3db5bce56d78..cb870939b1cf3 100644 --- a/src/Symfony/Component/Console/Command/Command.php +++ b/src/Symfony/Component/Console/Command/Command.php @@ -273,12 +273,8 @@ public function run(InputInterface $input, OutputInterface $output) * * @see execute() */ - public function setCode($code) + public function setCode(callable $code) { - if (!is_callable($code)) { - throw new InvalidArgumentException('Invalid callable provided to Command::setCode.'); - } - if ($code instanceof \Closure) { $r = new \ReflectionFunction($code); if (null === $r->getClosureThis()) { diff --git a/src/Symfony/Component/Console/Tests/Command/CommandTest.php b/src/Symfony/Component/Console/Tests/Command/CommandTest.php index fe8fecd912060..66e7fa51a1e45 100644 --- a/src/Symfony/Component/Console/Tests/Command/CommandTest.php +++ b/src/Symfony/Component/Console/Tests/Command/CommandTest.php @@ -332,16 +332,6 @@ public function testSetCodeWithNonClosureCallable() $this->assertEquals('interact called'.PHP_EOL.'from the code...'.PHP_EOL, $tester->getDisplay()); } - /** - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage Invalid callable provided to Command::setCode. - */ - public function testSetCodeWithNonCallable() - { - $command = new \TestCommand(); - $command->setCode(array($this, 'nonExistentMethod')); - } - public function callableMethodCommand(InputInterface $input, OutputInterface $output) { $output->writeln('from the code...'); diff --git a/src/Symfony/Component/Debug/ErrorHandler.php b/src/Symfony/Component/Debug/ErrorHandler.php index 38bb70a25f486..5f31aa4df618b 100644 --- a/src/Symfony/Component/Debug/ErrorHandler.php +++ b/src/Symfony/Component/Debug/ErrorHandler.php @@ -235,14 +235,9 @@ public function setLoggers(array $loggers) * @param callable $handler A handler that will be called on Exception * * @return callable|null The previous exception handler - * - * @throws \InvalidArgumentException */ - public function setExceptionHandler($handler) + public function setExceptionHandler(callable $handler = null) { - if (null !== $handler && !is_callable($handler)) { - throw new \LogicException('The exception handler must be a valid PHP callable.'); - } $prev = $this->exceptionHandler; $this->exceptionHandler = $handler; diff --git a/src/Symfony/Component/Debug/ExceptionHandler.php b/src/Symfony/Component/Debug/ExceptionHandler.php index a36f61b4980e9..73f5bb08394e8 100644 --- a/src/Symfony/Component/Debug/ExceptionHandler.php +++ b/src/Symfony/Component/Debug/ExceptionHandler.php @@ -72,11 +72,8 @@ public static function register($debug = true, $charset = null, $fileLinkFormat * * @return callable|null The previous exception handler if any */ - public function setHandler($handler) + public function setHandler(callable $handler = null) { - if (null !== $handler && !is_callable($handler)) { - throw new \LogicException('The exception handler must be a valid PHP callable.'); - } $old = $this->handler; $this->handler = $handler; diff --git a/src/Symfony/Component/Form/CallbackTransformer.php b/src/Symfony/Component/Form/CallbackTransformer.php index 7857ad5f598fe..c704224f98f43 100644 --- a/src/Symfony/Component/Form/CallbackTransformer.php +++ b/src/Symfony/Component/Form/CallbackTransformer.php @@ -35,18 +35,9 @@ class CallbackTransformer implements DataTransformerInterface * * @param callable $transform The forward transform callback * @param callable $reverseTransform The reverse transform callback - * - * @throws \InvalidArgumentException when the given callbacks is invalid */ - public function __construct($transform, $reverseTransform) + public function __construct(callable $transform, callable $reverseTransform) { - if (!is_callable($transform)) { - throw new \InvalidArgumentException('Argument 1 should be a callable'); - } - if (!is_callable($reverseTransform)) { - throw new \InvalidArgumentException('Argument 2 should be a callable'); - } - $this->transform = $transform; $this->reverseTransform = $reverseTransform; } diff --git a/src/Symfony/Component/Form/ChoiceList/ArrayChoiceList.php b/src/Symfony/Component/Form/ChoiceList/ArrayChoiceList.php index 156735b81751e..5ac149a9bd387 100644 --- a/src/Symfony/Component/Form/ChoiceList/ArrayChoiceList.php +++ b/src/Symfony/Component/Form/ChoiceList/ArrayChoiceList.php @@ -11,8 +11,6 @@ namespace Symfony\Component\Form\ChoiceList; -use Symfony\Component\Form\Exception\UnexpectedTypeException; - /** * A list of choices with arbitrary data types. * @@ -64,12 +62,8 @@ class ArrayChoiceList implements ChoiceListInterface * incrementing integers are used as * values */ - public function __construct($choices, $value = null) + public function __construct($choices, callable $value = null) { - if (null !== $value && !is_callable($value)) { - throw new UnexpectedTypeException($value, 'null or callable'); - } - if ($choices instanceof \Traversable) { $choices = iterator_to_array($choices); } diff --git a/src/Symfony/Component/Form/Tests/CallbackTransformerTest.php b/src/Symfony/Component/Form/Tests/CallbackTransformerTest.php index af49e69e6c1e5..8c0469e6b8bc7 100644 --- a/src/Symfony/Component/Form/Tests/CallbackTransformerTest.php +++ b/src/Symfony/Component/Form/Tests/CallbackTransformerTest.php @@ -25,22 +25,4 @@ function ($value) { return $value.' has reversely been transformed'; } $this->assertEquals('foo has been transformed', $transformer->transform('foo')); $this->assertEquals('bar has reversely been transformed', $transformer->reverseTransform('bar')); } - - /** - * @dataProvider invalidCallbacksProvider - * - * @expectedException \InvalidArgumentException - */ - public function testConstructorWithInvalidCallbacks($transformCallback, $reverseTransformCallback) - { - new CallbackTransformer($transformCallback, $reverseTransformCallback); - } - - public function invalidCallbacksProvider() - { - return array( - array(null, function () {}), - array(function () {}, null), - ); - } } diff --git a/src/Symfony/Component/Form/Tests/ChoiceList/ArrayChoiceListTest.php b/src/Symfony/Component/Form/Tests/ChoiceList/ArrayChoiceListTest.php index 50d4df8a9b7cb..f71ba67a9afbf 100644 --- a/src/Symfony/Component/Form/Tests/ChoiceList/ArrayChoiceListTest.php +++ b/src/Symfony/Component/Form/Tests/ChoiceList/ArrayChoiceListTest.php @@ -42,14 +42,6 @@ protected function getValues() return array('0', '1', '2', '3', '4', '5', '6'); } - /** - * @expectedException \Symfony\Component\Form\Exception\InvalidArgumentException - */ - public function testFailIfKeyMismatch() - { - new ArrayChoiceList(array(0 => 'a', 1 => 'b'), array(1 => 'a', 2 => 'b')); - } - public function testCreateChoiceListWithValueCallback() { $callback = function ($choice) { diff --git a/src/Symfony/Component/HttpFoundation/StreamedResponse.php b/src/Symfony/Component/HttpFoundation/StreamedResponse.php index 4b936a150e19c..90c272b469037 100644 --- a/src/Symfony/Component/HttpFoundation/StreamedResponse.php +++ b/src/Symfony/Component/HttpFoundation/StreamedResponse.php @@ -64,14 +64,9 @@ public static function create($callback = null, $status = 200, $headers = array( * Sets the PHP callback associated with this Response. * * @param callable $callback A valid PHP callback - * - * @throws \LogicException */ - public function setCallback($callback) + public function setCallback(callable $callback) { - if (!is_callable($callback)) { - throw new \LogicException('The Response callback must be a valid PHP callable.'); - } $this->callback = $callback; } diff --git a/src/Symfony/Component/HttpFoundation/Tests/StreamedResponseTest.php b/src/Symfony/Component/HttpFoundation/Tests/StreamedResponseTest.php index 940f17cac48ce..121459cc1b701 100644 --- a/src/Symfony/Component/HttpFoundation/Tests/StreamedResponseTest.php +++ b/src/Symfony/Component/HttpFoundation/Tests/StreamedResponseTest.php @@ -87,15 +87,6 @@ public function testSendContentWithNonCallable() $response->sendContent(); } - /** - * @expectedException \LogicException - */ - public function testSetCallbackNonCallable() - { - $response = new StreamedResponse(null); - $response->setCallback(null); - } - /** * @expectedException \LogicException */ diff --git a/src/Symfony/Component/HttpKernel/Event/FilterControllerEvent.php b/src/Symfony/Component/HttpKernel/Event/FilterControllerEvent.php index b61999cd6d062..93c9553fd4a58 100644 --- a/src/Symfony/Component/HttpKernel/Event/FilterControllerEvent.php +++ b/src/Symfony/Component/HttpKernel/Event/FilterControllerEvent.php @@ -58,47 +58,8 @@ public function getController() * * @throws \LogicException */ - public function setController($controller) + public function setController(callable $controller) { - // controller must be a callable - if (!is_callable($controller)) { - throw new \LogicException(sprintf('The controller must be a callable (%s given).', $this->varToString($controller))); - } - $this->controller = $controller; } - - private function varToString($var) - { - if (is_object($var)) { - return sprintf('Object(%s)', get_class($var)); - } - - if (is_array($var)) { - $a = array(); - foreach ($var as $k => $v) { - $a[] = sprintf('%s => %s', $k, $this->varToString($v)); - } - - return sprintf('Array(%s)', implode(', ', $a)); - } - - if (is_resource($var)) { - return sprintf('Resource(%s)', get_resource_type($var)); - } - - if (null === $var) { - return 'null'; - } - - if (false === $var) { - return 'false'; - } - - if (true === $var) { - return 'true'; - } - - return (string) $var; - } } diff --git a/src/Symfony/Component/Serializer/Normalizer/AbstractNormalizer.php b/src/Symfony/Component/Serializer/Normalizer/AbstractNormalizer.php index 5ad2197a21ce9..a39e8896d7e89 100644 --- a/src/Symfony/Component/Serializer/Normalizer/AbstractNormalizer.php +++ b/src/Symfony/Component/Serializer/Normalizer/AbstractNormalizer.php @@ -86,15 +86,9 @@ public function setCircularReferenceLimit($circularReferenceLimit) * @param callable $circularReferenceHandler * * @return self - * - * @throws InvalidArgumentException */ - public function setCircularReferenceHandler($circularReferenceHandler) + public function setCircularReferenceHandler(callable $circularReferenceHandler) { - if (!is_callable($circularReferenceHandler)) { - throw new InvalidArgumentException('The given circular reference handler is not callable.'); - } - $this->circularReferenceHandler = $circularReferenceHandler; return $this; diff --git a/src/Symfony/Component/Translation/PluralizationRules.php b/src/Symfony/Component/Translation/PluralizationRules.php index 3ef8f00b6e934..7ca2a8146bf29 100644 --- a/src/Symfony/Component/Translation/PluralizationRules.php +++ b/src/Symfony/Component/Translation/PluralizationRules.php @@ -189,12 +189,10 @@ public static function get($number, $locale) /** * Overrides the default plural rule for a given locale. * - * @param string $rule A PHP callable - * @param string $locale The locale - * - * @throws \LogicException + * @param callable $rule A PHP callable + * @param string $locale The locale */ - public static function set($rule, $locale) + public static function set(callable $rule, $locale) { if ('pt_BR' === $locale) { // temporary set a locale for brazilian @@ -205,10 +203,6 @@ public static function set($rule, $locale) $locale = substr($locale, 0, -strlen(strrchr($locale, '_'))); } - if (!is_callable($rule)) { - throw new \LogicException('The given rule can not be called'); - } - self::$rules[$locale] = $rule; } } From 7685cddf9583bb7992b80e27dae423e742bce105 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Mon, 5 Oct 2015 18:52:37 +0200 Subject: [PATCH 2/2] Add more callable type hints --- src/Symfony/Bridge/Twig/Command/DebugCommand.php | 2 +- .../FrameworkBundle/Resources/config/debug_prod.xml | 2 +- .../Component/Console/Helper/ProcessHelper.php | 6 +++--- src/Symfony/Component/Console/Helper/ProgressBar.php | 2 +- .../Component/Console/Helper/QuestionHelper.php | 2 +- src/Symfony/Component/Console/Question/Question.php | 8 ++++---- .../ExpressionLanguage/ExpressionFunction.php | 2 +- .../ExpressionLanguage/ExpressionLanguage.php | 2 +- .../Finder/Iterator/CustomFilterIterator.php | 4 ++-- .../Component/Form/ChoiceList/ArrayKeyChoiceList.php | 2 +- .../Component/Form/ChoiceList/LazyChoiceList.php | 2 +- .../Component/HttpFoundation/StreamedResponse.php | 2 +- .../HttpKernel/Controller/ControllerResolver.php | 2 +- .../HttpKernel/Event/FilterControllerEvent.php | 4 +--- .../EventListener/DebugHandlersListener.php | 2 +- .../Component/HttpKernel/Tests/HttpKernelTest.php | 11 ----------- src/Symfony/Component/Process/PhpProcess.php | 2 +- src/Symfony/Component/Process/Process.php | 10 +++++----- .../Serializer/Normalizer/AbstractNormalizer.php | 2 +- src/Symfony/Component/Templating/PhpEngine.php | 8 ++++---- .../Component/VarDumper/Cloner/AbstractCloner.php | 2 +- .../VarDumper/Exception/ThrowingCasterException.php | 5 ++--- src/Symfony/Component/VarDumper/VarDumper.php | 6 +----- 23 files changed, 36 insertions(+), 54 deletions(-) diff --git a/src/Symfony/Bridge/Twig/Command/DebugCommand.php b/src/Symfony/Bridge/Twig/Command/DebugCommand.php index bb37d99b21b07..6100eb87a5e17 100644 --- a/src/Symfony/Bridge/Twig/Command/DebugCommand.php +++ b/src/Symfony/Bridge/Twig/Command/DebugCommand.php @@ -149,7 +149,7 @@ private function getMetadata($type, $entity) return; } $refl = new \ReflectionMethod($cb[0], $cb[1]); - } elseif (is_object($cb) && is_callable($cb)) { + } elseif (is_object($cb) && method_exists($cb, '__invoke')) { $refl = new \ReflectionMethod($cb, '__invoke'); } elseif (function_exists($cb)) { $refl = new \ReflectionFunction($cb); diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/debug_prod.xml b/src/Symfony/Bundle/FrameworkBundle/Resources/config/debug_prod.xml index 4078a656d5a9c..3ef3ec90d0f17 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/debug_prod.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/debug_prod.xml @@ -12,7 +12,7 @@ - + null null null diff --git a/src/Symfony/Component/Console/Helper/ProcessHelper.php b/src/Symfony/Component/Console/Helper/ProcessHelper.php index fab23ee0d4895..2c46a2c39d0b2 100644 --- a/src/Symfony/Component/Console/Helper/ProcessHelper.php +++ b/src/Symfony/Component/Console/Helper/ProcessHelper.php @@ -36,7 +36,7 @@ class ProcessHelper extends Helper * * @return Process The process that ran */ - public function run(OutputInterface $output, $cmd, $error = null, $callback = null, $verbosity = OutputInterface::VERBOSITY_VERY_VERBOSE) + public function run(OutputInterface $output, $cmd, $error = null, callable $callback = null, $verbosity = OutputInterface::VERBOSITY_VERY_VERBOSE) { if ($output instanceof ConsoleOutputInterface) { $output = $output->getErrorOutput(); @@ -92,7 +92,7 @@ public function run(OutputInterface $output, $cmd, $error = null, $callback = nu * * @see run() */ - public function mustRun(OutputInterface $output, $cmd, $error = null, $callback = null) + public function mustRun(OutputInterface $output, $cmd, $error = null, callable $callback = null) { $process = $this->run($output, $cmd, $error, $callback); @@ -112,7 +112,7 @@ public function mustRun(OutputInterface $output, $cmd, $error = null, $callback * * @return callable */ - public function wrapCallback(OutputInterface $output, Process $process, $callback = null) + public function wrapCallback(OutputInterface $output, Process $process, callable $callback = null) { if ($output instanceof ConsoleOutputInterface) { $output = $output->getErrorOutput(); diff --git a/src/Symfony/Component/Console/Helper/ProgressBar.php b/src/Symfony/Component/Console/Helper/ProgressBar.php index 099f45420a8f4..59127f943a48f 100644 --- a/src/Symfony/Component/Console/Helper/ProgressBar.php +++ b/src/Symfony/Component/Console/Helper/ProgressBar.php @@ -86,7 +86,7 @@ public function __construct(OutputInterface $output, $max = 0) * @param string $name The placeholder name (including the delimiter char like %) * @param callable $callable A PHP callable */ - public static function setPlaceholderFormatterDefinition($name, $callable) + public static function setPlaceholderFormatterDefinition($name, callable $callable) { if (!self::$formatters) { self::$formatters = self::initPlaceholderFormatters(); diff --git a/src/Symfony/Component/Console/Helper/QuestionHelper.php b/src/Symfony/Component/Console/Helper/QuestionHelper.php index b95bf9e5f52cb..13ea0d0834c11 100644 --- a/src/Symfony/Component/Console/Helper/QuestionHelper.php +++ b/src/Symfony/Component/Console/Helper/QuestionHelper.php @@ -377,7 +377,7 @@ private function getHiddenResponse(OutputInterface $output, $inputStream) * * @throws \Exception In case the max number of attempts has been reached and no valid response has been given */ - private function validateAttempts($interviewer, OutputInterface $output, Question $question) + private function validateAttempts(callable $interviewer, OutputInterface $output, Question $question) { $error = null; $attempts = $question->getMaxAttempts(); diff --git a/src/Symfony/Component/Console/Question/Question.php b/src/Symfony/Component/Console/Question/Question.php index 9aa4c69d278f8..71cb8f5c8b5a3 100644 --- a/src/Symfony/Component/Console/Question/Question.php +++ b/src/Symfony/Component/Console/Question/Question.php @@ -164,7 +164,7 @@ public function setAutocompleterValues($values) * * @return Question The current instance */ - public function setValidator($validator) + public function setValidator(callable $validator = null) { $this->validator = $validator; @@ -220,11 +220,11 @@ public function getMaxAttempts() * * The normalizer can be a callable (a string), a closure or a class implementing __invoke. * - * @param string|\Closure $normalizer + * @param callable $normalizer * * @return Question The current instance */ - public function setNormalizer($normalizer) + public function setNormalizer(callable $normalizer) { $this->normalizer = $normalizer; @@ -236,7 +236,7 @@ public function setNormalizer($normalizer) * * The normalizer can ba a callable (a string), a closure or a class implementing __invoke. * - * @return string|\Closure + * @return callable */ public function getNormalizer() { diff --git a/src/Symfony/Component/ExpressionLanguage/ExpressionFunction.php b/src/Symfony/Component/ExpressionLanguage/ExpressionFunction.php index 7222261cd5386..c42f29f60958c 100644 --- a/src/Symfony/Component/ExpressionLanguage/ExpressionFunction.php +++ b/src/Symfony/Component/ExpressionLanguage/ExpressionFunction.php @@ -41,7 +41,7 @@ class ExpressionFunction * @param callable $compiler A callable able to compile the function * @param callable $evaluator A callable able to evaluate the function */ - public function __construct($name, $compiler, $evaluator) + public function __construct($name, callable $compiler, callable $evaluator) { $this->name = $name; $this->compiler = $compiler; diff --git a/src/Symfony/Component/ExpressionLanguage/ExpressionLanguage.php b/src/Symfony/Component/ExpressionLanguage/ExpressionLanguage.php index fb3faf79a5484..e40afd00ed17e 100644 --- a/src/Symfony/Component/ExpressionLanguage/ExpressionLanguage.php +++ b/src/Symfony/Component/ExpressionLanguage/ExpressionLanguage.php @@ -112,7 +112,7 @@ public function parse($expression, $names) * * @see ExpressionFunction */ - public function register($name, $compiler, $evaluator) + public function register($name, callable $compiler, callable $evaluator) { $this->functions[$name] = array('compiler' => $compiler, 'evaluator' => $evaluator); } diff --git a/src/Symfony/Component/Finder/Iterator/CustomFilterIterator.php b/src/Symfony/Component/Finder/Iterator/CustomFilterIterator.php index 24b15d97adf90..b43b88d98df79 100644 --- a/src/Symfony/Component/Finder/Iterator/CustomFilterIterator.php +++ b/src/Symfony/Component/Finder/Iterator/CustomFilterIterator.php @@ -26,8 +26,8 @@ class CustomFilterIterator extends FilterIterator /** * Constructor. * - * @param \Iterator $iterator The Iterator to filter - * @param array $filters An array of PHP callbacks + * @param \Iterator $iterator The Iterator to filter + * @param callable[] $filters An array of PHP callbacks * * @throws \InvalidArgumentException */ diff --git a/src/Symfony/Component/Form/ChoiceList/ArrayKeyChoiceList.php b/src/Symfony/Component/Form/ChoiceList/ArrayKeyChoiceList.php index 7c3c107d0f720..55cfab399f4ed 100644 --- a/src/Symfony/Component/Form/ChoiceList/ArrayKeyChoiceList.php +++ b/src/Symfony/Component/Form/ChoiceList/ArrayKeyChoiceList.php @@ -101,7 +101,7 @@ public static function toArrayKey($choice) * the keys of the values or if any of the * choices is not scalar */ - public function __construct($choices, $value = null) + public function __construct($choices, callable $value = null) { // If no values are given, use the choices as values // Since the choices are stored in the collection keys, i.e. they are diff --git a/src/Symfony/Component/Form/ChoiceList/LazyChoiceList.php b/src/Symfony/Component/Form/ChoiceList/LazyChoiceList.php index f691d71330715..27d8deb8825b4 100644 --- a/src/Symfony/Component/Form/ChoiceList/LazyChoiceList.php +++ b/src/Symfony/Component/Form/ChoiceList/LazyChoiceList.php @@ -59,7 +59,7 @@ class LazyChoiceList implements ChoiceListInterface * @param null|callable $value The callable generating the choice * values */ - public function __construct(ChoiceLoaderInterface $loader, $value = null) + public function __construct(ChoiceLoaderInterface $loader, callable $value = null) { $this->loader = $loader; $this->value = $value; diff --git a/src/Symfony/Component/HttpFoundation/StreamedResponse.php b/src/Symfony/Component/HttpFoundation/StreamedResponse.php index 90c272b469037..b021d3c405a28 100644 --- a/src/Symfony/Component/HttpFoundation/StreamedResponse.php +++ b/src/Symfony/Component/HttpFoundation/StreamedResponse.php @@ -36,7 +36,7 @@ class StreamedResponse extends Response * @param int $status The response status code * @param array $headers An array of response headers */ - public function __construct($callback = null, $status = 200, $headers = array()) + public function __construct(callable $callback = null, $status = 200, $headers = array()) { parent::__construct(null, $status, $headers); diff --git a/src/Symfony/Component/HttpKernel/Controller/ControllerResolver.php b/src/Symfony/Component/HttpKernel/Controller/ControllerResolver.php index 1af46dc656caa..a4a5fdba14c22 100644 --- a/src/Symfony/Component/HttpKernel/Controller/ControllerResolver.php +++ b/src/Symfony/Component/HttpKernel/Controller/ControllerResolver.php @@ -131,7 +131,7 @@ protected function doGetArguments(Request $request, $controller, array $paramete * * @param string $controller A Controller string * - * @return mixed A PHP callable + * @return callable A PHP callable * * @throws \InvalidArgumentException */ diff --git a/src/Symfony/Component/HttpKernel/Event/FilterControllerEvent.php b/src/Symfony/Component/HttpKernel/Event/FilterControllerEvent.php index 93c9553fd4a58..e0af13106c2bf 100644 --- a/src/Symfony/Component/HttpKernel/Event/FilterControllerEvent.php +++ b/src/Symfony/Component/HttpKernel/Event/FilterControllerEvent.php @@ -29,12 +29,10 @@ class FilterControllerEvent extends KernelEvent { /** * The current controller. - * - * @var callable */ private $controller; - public function __construct(HttpKernelInterface $kernel, $controller, Request $request, $requestType) + public function __construct(HttpKernelInterface $kernel, callable $controller, Request $request, $requestType) { parent::__construct($kernel, $request, $requestType); diff --git a/src/Symfony/Component/HttpKernel/EventListener/DebugHandlersListener.php b/src/Symfony/Component/HttpKernel/EventListener/DebugHandlersListener.php index f50e4d6c3b9c1..33a543819d08d 100644 --- a/src/Symfony/Component/HttpKernel/EventListener/DebugHandlersListener.php +++ b/src/Symfony/Component/HttpKernel/EventListener/DebugHandlersListener.php @@ -45,7 +45,7 @@ class DebugHandlersListener implements EventSubscriberInterface * @param bool $scream Enables/disables screaming mode, where even silenced errors are logged * @param string $fileLinkFormat The format for links to source files */ - public function __construct($exceptionHandler, LoggerInterface $logger = null, $levels = null, $throwAt = -1, $scream = true, $fileLinkFormat = null) + public function __construct(callable $exceptionHandler = null, LoggerInterface $logger = null, $levels = null, $throwAt = -1, $scream = true, $fileLinkFormat = null) { $this->exceptionHandler = $exceptionHandler; $this->logger = $logger; diff --git a/src/Symfony/Component/HttpKernel/Tests/HttpKernelTest.php b/src/Symfony/Component/HttpKernel/Tests/HttpKernelTest.php index 97e68f66f979a..06f611ef464fd 100644 --- a/src/Symfony/Component/HttpKernel/Tests/HttpKernelTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/HttpKernelTest.php @@ -154,17 +154,6 @@ public function testHandleWhenNoControllerIsFound() $kernel->handle(new Request()); } - /** - * @expectedException \LogicException - */ - public function testHandleWhenTheControllerIsNotACallable() - { - $dispatcher = new EventDispatcher(); - $kernel = new HttpKernel($dispatcher, $this->getResolver('foobar')); - - $kernel->handle(new Request()); - } - public function testHandleWhenTheControllerIsAClosure() { $response = new Response('foo'); diff --git a/src/Symfony/Component/Process/PhpProcess.php b/src/Symfony/Component/Process/PhpProcess.php index e5777ea22afe7..583516bbbed80 100644 --- a/src/Symfony/Component/Process/PhpProcess.php +++ b/src/Symfony/Component/Process/PhpProcess.php @@ -54,7 +54,7 @@ public function setPhpBinary($php) /** * {@inheritdoc} */ - public function start($callback = null) + public function start(callable $callback = null) { if (null === $this->getCommandLine()) { throw new RuntimeException('Unable to find the PHP executable.'); diff --git a/src/Symfony/Component/Process/Process.php b/src/Symfony/Component/Process/Process.php index 02499cb208cd9..3a369fd3bf49f 100644 --- a/src/Symfony/Component/Process/Process.php +++ b/src/Symfony/Component/Process/Process.php @@ -217,7 +217,7 @@ public function run($callback = null) * @throws RuntimeException if PHP was compiled with --enable-sigchild and the enhanced sigchild compatibility mode is not enabled * @throws ProcessFailedException if the process didn't terminate successfully */ - public function mustRun($callback = null) + public function mustRun(callable $callback = null) { if ($this->isSigchildEnabled() && !$this->enhanceSigchildCompatibility) { throw new RuntimeException('This PHP has been compiled with --enable-sigchild. You must use setEnhanceSigchildCompatibility() to use this method.'); @@ -252,7 +252,7 @@ public function mustRun($callback = null) * @throws RuntimeException When process is already running * @throws LogicException In case a callback is provided and output has been disabled */ - public function start($callback = null) + public function start(callable $callback = null) { if ($this->isRunning()) { throw new RuntimeException('Process is already running'); @@ -310,7 +310,7 @@ public function start($callback = null) * * @see start() */ - public function restart($callback = null) + public function restart(callable $callback = null) { if ($this->isRunning()) { throw new RuntimeException('Process is already running'); @@ -337,7 +337,7 @@ public function restart($callback = null) * @throws RuntimeException When process stopped after receiving signal * @throws LogicException When process is not yet started */ - public function wait($callback = null) + public function wait(callable $callback = null) { $this->requireProcessIsStarted(__FUNCTION__); @@ -1232,7 +1232,7 @@ private function getDescriptors() * * @param callable|null $callback The user defined PHP callback * - * @return callable A PHP callable + * @return \Closure A PHP closure */ protected function buildCallback($callback) { diff --git a/src/Symfony/Component/Serializer/Normalizer/AbstractNormalizer.php b/src/Symfony/Component/Serializer/Normalizer/AbstractNormalizer.php index a39e8896d7e89..4bc71ca667d35 100644 --- a/src/Symfony/Component/Serializer/Normalizer/AbstractNormalizer.php +++ b/src/Symfony/Component/Serializer/Normalizer/AbstractNormalizer.php @@ -97,7 +97,7 @@ public function setCircularReferenceHandler(callable $circularReferenceHandler) /** * Set normalization callbacks. * - * @param array $callbacks help normalize the result + * @param callable[] $callbacks help normalize the result * * @return self * diff --git a/src/Symfony/Component/Templating/PhpEngine.php b/src/Symfony/Component/Templating/PhpEngine.php index de90d74aad84b..50b39566488c6 100644 --- a/src/Symfony/Component/Templating/PhpEngine.php +++ b/src/Symfony/Component/Templating/PhpEngine.php @@ -350,10 +350,10 @@ public function getCharset() /** * Adds an escaper for the given context. * - * @param string $context The escaper context (html, js, ...) - * @param mixed $escaper A PHP callable + * @param string $context The escaper context (html, js, ...) + * @param callable $escaper A PHP callable */ - public function setEscaper($context, $escaper) + public function setEscaper($context, callable $escaper) { $this->escapers[$context] = $escaper; self::$escaperCache[$context] = array(); @@ -364,7 +364,7 @@ public function setEscaper($context, $escaper) * * @param string $context The context name * - * @return mixed $escaper A PHP callable + * @return callable $escaper A PHP callable * * @throws \InvalidArgumentException */ diff --git a/src/Symfony/Component/VarDumper/Cloner/AbstractCloner.php b/src/Symfony/Component/VarDumper/Cloner/AbstractCloner.php index 79817803a2c37..c7f035de23973 100644 --- a/src/Symfony/Component/VarDumper/Cloner/AbstractCloner.php +++ b/src/Symfony/Component/VarDumper/Cloner/AbstractCloner.php @@ -304,7 +304,7 @@ private function callCaster($callback, $obj, $a, $stub, $isNested) $a = $cast; } } catch (\Exception $e) { - $a[(Stub::TYPE_OBJECT === $stub->type ? Caster::PREFIX_VIRTUAL : '').'⚠'] = new ThrowingCasterException($callback, $e); + $a[(Stub::TYPE_OBJECT === $stub->type ? Caster::PREFIX_VIRTUAL : '').'⚠'] = new ThrowingCasterException($e); } return $a; diff --git a/src/Symfony/Component/VarDumper/Exception/ThrowingCasterException.php b/src/Symfony/Component/VarDumper/Exception/ThrowingCasterException.php index c1b427b92e1bf..976f4439b67f3 100644 --- a/src/Symfony/Component/VarDumper/Exception/ThrowingCasterException.php +++ b/src/Symfony/Component/VarDumper/Exception/ThrowingCasterException.php @@ -17,10 +17,9 @@ class ThrowingCasterException extends \Exception { /** - * @param callable $caster The failing caster - * @param \Exception $prev The exception thrown from the caster + * @param \Exception $prev The exception thrown from the caster */ - public function __construct($caster, \Exception $prev) + public function __construct(\Exception $prev) { parent::__construct('Unexpected '.get_class($prev).' thrown from a caster: '.$prev->getMessage(), 0, $prev); } diff --git a/src/Symfony/Component/VarDumper/VarDumper.php b/src/Symfony/Component/VarDumper/VarDumper.php index c728439df21bd..8c610c5d33b86 100644 --- a/src/Symfony/Component/VarDumper/VarDumper.php +++ b/src/Symfony/Component/VarDumper/VarDumper.php @@ -38,12 +38,8 @@ public static function dump($var) return call_user_func(self::$handler, $var); } - public static function setHandler($callable) + public static function setHandler(callable $callable = null) { - if (null !== $callable && !is_callable($callable, true)) { - throw new \InvalidArgumentException('Invalid PHP callback.'); - } - $prevHandler = self::$handler; self::$handler = $callable;