8000 Add more callable type hints · symfony/symfony@7685cdd · GitHub
[go: up one dir, main page]

Skip to content

Commit 7685cdd

Browse files
Add more callable type hints
1 parent 4e0c6e1 commit 7685cdd

File tree

23 files changed

+36
-54
lines changed

23 files changed

+36
-54
lines changed

src/Symfony/Bridge/Twig/Command/DebugCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ private function getMetadata($type, $entity)
149149
return;
150150
}
151151
$refl = new \ReflectionMethod($cb[0], $cb[1]);
152-
} elseif (is_object($cb) && is_callable($cb)) {
152+
} elseif (is_object($cb) && method_exists($cb, '__invoke')) {
153153
$refl = new \ReflectionMethod($cb, '__invoke');
154154
} elseif (function_exists($cb)) {
155155
$refl = new \ReflectionFunction($cb);

src/Symfony/Bundle/FrameworkBundle/Resources/config/debug_prod.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<service id="debug.debug_handlers_listener" class="Symfony\Component\HttpKernel\EventListener\DebugHandlersListener">
1313
<tag name="kernel.event_subscriber" />
1414
<tag name="monolog.logger" channel="php" />
15-
<argument /><!-- Exception handler -->
15+
<argument>null</argument><!-- Exception handler -->
1616
<argument type="service" id="logger" on-invalid="null" />
1717
<argument>null</argument><!-- Log levels map for enabled error levels -->
1818
<argument>null</argument>

src/Symfony/Component/Console/Helper/ProcessHelper.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class ProcessHelper extends Helper
3636
*
3737
* @return Process The process that ran
3838
*/
39-
public function run(OutputInterface $output, $cmd, $error = null, $callback = null, $verbosity = OutputInterface::VERBOSITY_VERY_VERBOSE)
39+
public function run(OutputInterface $output, $cmd, $error = null, callable $callback = null, $verbosity = OutputInterface::VERBOSITY_VERY_VERBOSE)
4040
{
4141
if ($output instanceof ConsoleOutputInterface) {
4242
$output = $output->getErrorOutput();
@@ -92,7 +92,7 @@ public function run(OutputInterface $output, $cmd, $error = null, $callback = nu
9292
*
9393
* @see run()
9494
*/
95-
public function mustRun(OutputInterface $output, $cmd, $error = null, $callback = null)
95+
public function mustRun(OutputInterface $output, $cmd, $error = null, callable $callback = null)
9696
{
9797
$process = $this->run($output, $cmd, $error, $callback);
9898

@@ -112,7 +112,7 @@ public function mustRun(OutputInterface $output, $cmd, $error = null, $callback
112112
*
113113
* @return callable
114114
*/
115-
public function wrapCallback(OutputInterface $output, Process $process, $callback = null)
115+
public function wrapCallback(OutputInterface $output, Process $process, callable $callback = null)
116116
{
117117
if ($output instanceof ConsoleOutputInterface) {
118118
$output = $output->getErrorOutput();

src/Symfony/Component/Console/Helper/ProgressBar.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public function __construct(OutputInterface $output, $max = 0)
8686
* @param string $name The placeholder name (including the delimiter char like %)
8787
* @param callable $callable A PHP callable
8888
*/
89-
public static function setPlaceholderFormatterDefinition($name, $callable)
89+
public static function setPlaceholderFormatterDefinition($name, callable $callable)
9090
{
9191
if (!self::$formatters) {
9292
self::$formatters = self::initPlaceholderFormatters();

src/Symfony/Component/Console/Helper/QuestionHelper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ private function getHiddenResponse(OutputInterface $output, $inputStream)
377377
*
378378
* @throws \Exception In case the max number of attempts has been reached and no valid response has been given
379379
*/
380-
private function validateAttempts($interviewer, OutputInterface $output, Question $question)
380+
private function validateAttempts(callable $interviewer, OutputInterface $output, Question $question)
381381
{
382382
$error = null;
383383
$attempts = $question->getMaxAttempts();

src/Symfony/Component/Console/Question/Question.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ public function setAutocompleterValues($values)
164164
*
165165
* @return Question The current instance
166166
*/
167-
public function setValidator($validator)
167+
public function setValidator(callable $validator = null)
168168
{
169169
$this->validator = $validator;
170170

@@ -220,11 +220,11 @@ public function getMaxAttempts()
220220
*
221221
* The normalizer can be a callable (a string), a closure or a class implementing __invoke.
222222
*
223-
* @param string|\Closure $normalizer
223+
* @param callable $normalizer
224224
*
225225
* @return Question The current instance
226226
*/
227-
public function setNormalizer($normalizer)
227+
public function setNormalizer(callable $normalizer)
228228
{
229229
$this->normalizer = $normalizer;
230230

@@ -236,7 +236,7 @@ public function setNormalizer($normalizer)
236236
*
237237
* The normalizer can ba a callable (a string), a closure or a class implementing __invoke.
238238
*
239-
* @return string|\Closure
239+
* @return callable
240240
*/
241241
public function getNormalizer()
242242
{

src/Symfony/Component/ExpressionLanguage/ExpressionFunction.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class ExpressionFunction
4141
* @param callable $compiler A callable able to compile the function
4242
* @param callable $evaluator A callable able to evaluate the function
4343
*/
44-
public function __construct($name, $compiler, $evaluator)
44+
public function __construct($name, callable $compiler, callable $evaluator)
4545
{
4646
$this->name = $name;
4747
$this->compiler = $compiler;

src/Symfony/Component/ExpressionLanguage/ExpressionLanguage.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ public function parse($expression, $names)
112112
*
113113
* @see ExpressionFunction
114114
*/
115-
public function register($name, $compiler, $evaluator)
115+
public function register($name, callable $compiler, callable $evaluator)
116116
{
117117
$this->functions[$name] = array('compiler' => $compiler, 'evaluator' => $evaluator);
118118
}

src/Symfony/Component/Finder/Iterator/CustomFilterIterator.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ class CustomFilterIterator extends FilterIterator
2626
/**
2727
* Constructor.
2828
*
29-
* @param \Iterator $iterator The Iterator to filter
30-
* @param array $filters An array of PHP callbacks
29+
* @param \Iterator $iterator The Iterator to filter
30+
* @param callable[] $filters An array of PHP callbacks
3131
*
3232
* @throws \InvalidArgumentException
3333
*/

src/Symfony/Component/Form/ChoiceList/ArrayKeyChoiceList.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public static function toArrayKey($choice)
101101
* the keys of the values or if any of the
102102
* choices is not scalar
103103
*/
104-
public function __construct($choices, $value = null)
104+
public function __construct($choices, callable $value = null)
105105
{
106106
// If no values are given, use the choices as values
107107
// Since the choices are stored in the collection keys, i.e. they are

src/Symfony/Component/Form/ChoiceList/LazyChoiceList.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class LazyChoiceList implements ChoiceListInterface
5959
* @param null|callable $value The callable generating the choice
6060
* values
6161
*/
62-
public function __construct(ChoiceLoaderInterface $loader, $value = null)
62+
public function __construct(ChoiceLoaderInterface $loader, callable $value = null)
6363
{
6464
$this->loader = $loader;
6565
$this->value = $value;

src/Symfony/Component/HttpFoundation/StreamedResponse.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class StreamedResponse extends Response
3636
* @param int $status The response status code
3737
* @param array $headers An array of response headers
3838
*/
39-
public function __construct($callback = null, $status = 200, $headers = array())
39+
public function __construct(callable $callback = null, $status = 200, $headers = array())
4040
{
4141
parent::__construct(null, $status, $headers);
4242

src/Symfony/Component/HttpKernel/Controller/ControllerResolver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ protected function doGetArguments(Request $request, $controller, array $paramete
131131
*
132132
* @param string $controller A Controller string
133133
*
134-
* @return mixed A PHP callable
134+
* @return callable A PHP callable
135135
*
136136
* @throws \InvalidArgumentException
137137
*/

src/Symfony/Component/HttpKernel/Event/FilterControllerEvent.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,10 @@ class FilterControllerEvent extends KernelEvent
2929
{
3030
/**
3131
* The current controller.
32-
*
33-
* @var callable
3432
*/
3533
private $controller;
3634

37-
public function __construct(HttpKernelInterface $kernel, $controller, Request $request, $requestType)
35+
public function __construct(HttpKernelInterface $kernel, callable $controller, Request $request, $requestType)
3836
{
3937
parent::__construct($kernel, $request, $requestType);
4038

src/Symfony/Component/HttpKernel/EventListener/DebugHandlersListener.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class DebugHandlersListener implements EventSubscriberInterface
4545
* @param bool $scream Enables/disables screaming mode, where even silenced errors are logged
4646
* @param string $fileLinkFormat The format for links to source files
4747
*/
48-
public function __construct($exceptionHandler, LoggerInterface $logger = null, $levels = null, $throwAt = -1, $scream = true, $fileLinkFormat = null)
48+
public function __construct(callable $exceptionHandler = null, LoggerInterface $logger = null, $levels = null, $throwAt = -1, $scream = true, $fileLinkFormat = null)
4949
{
5050
$this->exceptionHandler = $exceptionHandler;
5151
$this->logger = $logger;

src/Symfony/Component/HttpKernel/Tests/HttpKernelTest.php

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -154,17 +154,6 @@ public function testHandleWhenNoControllerIsFound()
154154
$kernel->handle(new Request());
155155
}
156156

157-
/**
158-
* @expectedException \LogicException
159-
*/
160-
public function testHandleWhenTheControllerIsNotACallable()
161-
{
162-
$dispatcher = new EventDispatcher();
163-
$kernel = new HttpKernel($dispatcher, $this->getResolver('foobar'));
164-
165-
$kernel->handle(new Request());
166-
}
167-
168157
public function testHandleWhenTheControllerIsAClosure()
169158
{
170159
$response = new Response('foo');

src/Symfony/Component/Process/PhpProcess.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public function setPhpBinary($php)
5454
/**
5555
* {@inheritdoc}
5656
*/
57-
public function start($callback = null)
57+
public function start(callable $callback = null)
5858
{
5959
if (null === $this->getCommandLine()) {
6060
throw new RuntimeException('Unable to find the PHP executable.');

src/Symfony/Component/Process/Process.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ public function run($callback = null)
217217
* @throws RuntimeException if PHP was compiled with --enable-sigchild and the enhanced sigchild compatibility mode is not enabled
218218
* @throws ProcessFailedException if the process didn't terminate successfully
219219
*/
220-
public function mustRun($callback = null)
220+
public function mustRun(callable $callback = null)
221221
{
222222
if ($this->isSigchildEnabled() && !$this->enhanceSigchildCompatibility) {
223223
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)
252252
* @throws RuntimeException When process is already running
253253
* @throws LogicException In case a callback is provided and output has been disabled
254254
*/
255-
public function start($callback = null)
255+
public function start(callable $callback = null)
256256
{
257257
if ($this->isRunning()) {
258258
throw new RuntimeException('Process is already running');
@@ -310,7 +310,7 @@ public function start($callback = null)
310310
*
311311
* @see start()
312312
*/
313-
public function restart($callback = null)
313+
public function restart(callable $callback = null)
314314
{
315315
if ($this->isRunning()) {
316316
throw new RuntimeException('Process is already running');
@@ -337,7 +337,7 @@ public function restart($callback = null)
337337
* @throws RuntimeException When process stopped after receiving signal
338338
* @throws LogicException When process is not yet started
339339
*/
340-
public function wait($callback = null)
340+
public function wait(callable $callback = null)
341341
{
342342
$this->requireProcessIsStarted(__FUNCTION__);
343343

@@ -1232,7 +1232,7 @@ private function getDescriptors()
12321232
*
12331233
* @param callable|null $callback The user defined PHP callback
12341234
*
1235-
* @return callable A PHP callable
1235+
* @return \Closure A PHP closure
12361236
*/
12371237
protected function buildCallback($callback)
12381238
{

src/Symfony/Component/Serializer/Normalizer/AbstractNormalizer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public function setCircularReferenceHandler(callable $circularReferenceHandler)
9797
/**
9898
* Set normalization callbacks.
9999
*
100-
* @param array $callbacks help normalize the result
100+
* @param callable[] $callbacks help normalize the result
101101
*
102102
* @return self
103103
*

src/Symfony/Component/Templating/PhpEngine.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -350,10 +350,10 @@ public function getCharset()
350350
/**
351351
* Adds an escaper for the given context.
352352
*
353-
* @param string $context The escaper context (html, js, ...)
354-
* @param mixed $escaper A PHP callable
353+
* @param string $context The escaper context (html, js, ...)
354+
* @param callable $escaper A PHP callable
355355
*/
356-
public function setEscaper($context, $escaper)
356+
public function setEscaper($context, callable $escaper)
357357
{
358358
$this->escapers[$context] = $escaper;
359359
self::$escaperCache[$context] = array();
@@ -364,7 +364,7 @@ public function setEscaper($context, $escaper)
364364
*
365365
* @param string $context The context name
366366
*
367-
* @return mixed $escaper A PHP callable
367+
* @return callable $escaper A PHP callable
368368
*
369369
* @throws \InvalidArgumentException
370370
*/

src/Symfony/Component/VarDumper/Cloner/AbstractCloner.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ private function callCaster($callback, $obj, $a, $stub, $isNested)
304304
$a = $cast;
305305
}
306306
} catch (\Exception $e) {
307-
$a[(Stub::TYPE_OBJECT === $stub->type ? Caster::PREFIX_VIRTUAL : '').''] = new ThrowingCasterException($callback, $e);
307+
$a[(Stub::TYPE_OBJECT === $stub->type ? Caster::PREFIX_VIRTUAL : '').''] = new ThrowingCasterException($e);
308308
}
309309

310310
return $a;

src/Symfony/Component/VarDumper/Exception/ThrowingCasterException.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,9 @@
1717
class ThrowingCasterException extends \Exception
1818
{
1919
/**
20-
* @param callable $caster The failing caster
21-
* @param \Exception $prev The exception thrown from the caster
20+
* @param \Exception $prev The exception thrown from the caster
2221
*/
23-
public function __construct($caster, \Exception $prev)
22+
public function __construct(\Exception $prev)
2423
{
2524
parent::__construct('Unexpected '.get_class($prev).' thrown from a caster: '.$prev->getMessage(), 0, $prev);
2625
}

src/Symfony/Component/VarDumper/VarDumper.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,8 @@ public static function dump($var)
3838
return call_user_func(self::$handler, $var);
3939
}
4040

41-
public static function setHandler($callable)
41+
public static function setHandler(callable $callable = null)
4242
{
43-
if (null !== $callable && !is_callable($callable, true)) {
44-
throw new \InvalidArgumentException('Invalid PHP callback.');
45-
}
46-
4743
$prevHandler = self::$handler;
4844
self::$handler = $callable;
4945

0 commit comments

Comments
 (0)
0