diff --git a/src/Symfony/Component/Console/Command/Command.php b/src/Symfony/Component/Console/Command/Command.php index d3db5bce56..cb870939b1 100644 --- a/src/Symfony/Component/Console/Command/Command.php +++ b/src/Symfony/Component/Console/Command/Command.php @@ -273,12 +273,8 @@ class Command * * @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 fe8fecd912..66e7fa51a1 100644 --- a/src/Symfony/Component/Console/Tests/Command/CommandTest.php +++ b/src/Symfony/Component/Console/Tests/Command/CommandTest.php @@ -332,16 +332,6 @@ class CommandTest extends \PHPUnit_Framework_TestCase $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 38bb70a25f..5f31aa4df6 100644 --- a/src/Symfony/Component/Debug/ErrorHandler.php +++ b/src/Symfony/Component/Debug/ErrorHandler.php @@ -235,14 +235,9 @@ class ErrorHandler * @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 a36f61b498..73f5bb0839 100644 --- a/src/Symfony/Component/Debug/ExceptionHandler.php +++ b/src/Symfony/Component/Debug/ExceptionHandler.php @@ -72,11 +72,8 @@ class ExceptionHandler * * @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 7857ad5f59..c704224f98 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 156735b817..5ac149a9bd 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 af49e69e6c..8c0469e6b8 100644 --- a/src/Symfony/Component/Form/Tests/CallbackTransformerTest.php +++ b/src/Symfony/Component/Form/Tests/CallbackTransformerTest.php @@ -25,22 +25,4 @@ class CallbackTransformerTest extends \PHPUnit_Framework_TestCase $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 50d4df8a9b..f71ba67a9a 100644 --- a/src/Symfony/Component/Form/Tests/ChoiceList/ArrayChoiceListTest.php +++ b/src/Symfony/Component/Form/Tests/ChoiceList/ArrayChoiceListTest.php @@ -42,14 +42,6 @@ class ArrayChoiceListTest extends AbstractChoiceListTest 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 4b936a150e..90c272b469 100644 --- a/src/Symfony/Component/HttpFoundation/StreamedResponse.php +++ b/src/Symfony/Component/HttpFoundation/StreamedResponse.php @@ -64,14 +64,9 @@ class StreamedResponse extends Response * 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 940f17cac4..121459cc1b 100644 --- a/src/Symfony/Component/HttpFoundation/Tests/StreamedResponseTest.php +++ b/src/Symfony/Component/HttpFoundation/Tests/StreamedResponseTest.php @@ -87,15 +87,6 @@ class StreamedResponseTest extends \PHPUnit_Framework_TestCase $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 b61999cd6d..93c9553fd4 100644 --- a/src/Symfony/Component/HttpKernel/Event/FilterControllerEvent.php +++ b/src/Symfony/Component/HttpKernel/Event/FilterControllerEvent.php @@ -58,47 +58,8 @@ class FilterControllerEvent extends KernelEvent * * @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 5ad2197a21..a39e8896d7 100644 --- a/src/Symfony/Component/Serializer/Normalizer/AbstractNormalizer.php +++ b/src/Symfony/Component/Serializer/Normalizer/AbstractNormalizer.php @@ -86,15 +86,9 @@ abstract class AbstractNormalizer extends SerializerAwareNormalizer implements N * @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 3ef8f00b6e..7ca2a8146b 100644 --- a/src/Symfony/Component/Translation/PluralizationRules.php +++ b/src/Symfony/Component/Translation/PluralizationRules.php @@ -189,12 +189,10 @@ class PluralizationRules /** * 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 @@ class PluralizationRules $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; } }