Skip to content

Commit fad7aba

Browse files
[2.3] Remove possible call_user_func()
1 parent 580de75 commit fad7aba

File tree

13 files changed

+30
-22
lines changed

13 files changed

+30
-22
lines changed

src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/AppKernel.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,8 @@ public function serialize()
105105

106106
public function unserialize($str)
107107
{
108-
call_user_func_array(array($this, '__construct'), unserialize($str));
108+
$a = unserialize($str);
109+
$this->__construct($a[0], $a[1], $a[2], $a[3]);
109110
}
110111

111112
protected function getKernelParameters()

src/Symfony/Bundle/SecurityBundle/Tests/Functional/app/AppKernel.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,8 @@ public function serialize()
105105

106106
public function unserialize($str)
107107
{
108-
call_user_func_array(array($this, '__construct'), unserialize($str));
108+
$a = unserialize($str);
109+
$this->__construct($a[0], $a[1], $a[2], $a[3]);
109110
}
110111

111112
protected function getKernelParameters()

src/Symfony/Component/Config/Definition/Builder/ExprBuilder.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,8 +225,10 @@ public static function buildExpressions(array $expressions)
225225
{
226226
foreach ($expressions as $k => $expr) {
227227
if ($expr instanceof ExprBuilder) {
228-
$expressions[$k] = function ($v) use ($expr) {
229-
return call_user_func($expr->ifPart, $v) ? call_user_func($expr->thenPart, $v) : $v;
228+
$if = $expr->ifPart;
229+
$then = $expr->thenPart;
230+
$expressions[$k] = function ($v) use ($if, $then) {
231+
return $if($v) ? $then($v) : $v;
230232
};
231233
}
232234
}

src/Symfony/Component/Config/Definition/VariableNode.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@ public function hasDefaultValue()
4949
*/
5050
public function getDefaultValue()
5151
{
52-
return $this->defaultValue instanceof \Closure ? call_user_func($this->defaultValue) : $this->defaultValue;
52+
$v = $this->defaultValue;
53+
54+
return $v instanceof \Closure ? $v() : $v;
5355
}
5456

5557
/**

src/Symfony/Component/Config/Exception/FileLoaderImportCircularReferenceException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,6 @@ public function __construct(array $resources, $code = null, $previous = null)
2222
{
2323
$message = sprintf('Circular reference detected in "%s" ("%s" > "%s").', $this->varToString($resources[0]), implode('" > "', $resources), $resources[0]);
2424

25-
call_user_func('Exception::__construct', $message, $code, $previous);
25+
\Exception::__construct($message, $code, $previous);
2626
}
2727
}

src/Symfony/Component/Finder/Shell/Command.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,14 +248,14 @@ public function getErrorHandler()
248248
*/
249249
public function execute()
250250
{
251-
if (null === $this->errorHandler) {
251+
if (null === $errorHandler = $this->errorHandler) {
252252
exec($this->join(), $output);
253253
} else {
254254
$process = proc_open($this->join(), array(0 => array('pipe', 'r'), 1 => array('pipe', 'w'), 2 => array('pipe', 'w')), $pipes);
255255
$output = preg_split('~(\r\n|\r|\n)~', stream_get_contents($pipes[1]), -1, PREG_SPLIT_NO_EMPTY);
256256

257257
if ($error = stream_get_contents($pipes[2])) {
258-
call_user_func($this->errorHandler, $error);
258+
$errorHandler($error);
259259
}
260260

261261
proc_close($process);

src/Symfony/Component/HttpKernel/Tests/HttpCache/TestHttpKernel.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ public function callController(Request $request)
7474

7575
$response = new Response($this->body, $this->status, $this->headers);
7676

77-
if (null !== $this->customizer) {
78-
call_user_func($this->customizer, $request, $response);
77+
if (null !== $customizer = $this->customizer) {
78+
$customizer($request, $response);
7979
}
8080

8181
return $response;

src/Symfony/Component/Process/Process.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1102,11 +1102,12 @@ private function readPipes($blocking, $close)
11021102
$result = $this->processPipes->read($blocking);
11031103
}
11041104

1105+
$callback = $this->callback;
11051106
foreach ($result as $type => $data) {
11061107
if (3 == $type) {
11071108
$this->fallbackExitcode = (int) $data;
11081109
} else {
1109-
call_user_func($this->callback, $type === self::STDOUT ? self::OUT : self::ERR, $data);
1110+
$callback($type === self::STDOUT ? self::OUT : self::ERR, $data);
11101111
}
11111112
}
11121113
}

src/Symfony/Component/Process/Tests/AbstractProcessTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -747,7 +747,7 @@ public function testMethodsThatNeedARunningProcess($method)
747747
{
748748
$process = $this->getProcess('php -m');
749749
$this->setExpectedException('Symfony\Component\Process\Exception\LogicException', sprintf('Process must be started before calling %s.', $method));
750-
call_user_func(array($process, $method));
750+
$process->{$method}();
751751
}
752752

753753
public function provideMethodsThatNeedARunningProcess()
@@ -769,7 +769,7 @@ public function testMethodsThatNeedATerminatedProcess($method)
769769
$process = $this->getProcess('php -r "sleep(1);"');
770770
$process->start();
771771
try {
772-
call_user_func(array($process, $method));
772+
$process->{$method}();
773773
$process->stop(0);
774774
$this->fail('A LogicException must have been thrown');
775775
} catch (\Exception $e) {

src/Symfony/Component/Routing/Loader/ClosureLoader.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class ClosureLoader extends Loader
3737
*/
3838
public function load($closure, $type = null)
3939
{
40-
return call_user_func($closure);
40+
return $closure();
4141
}
4242

4343
/**

0 commit comments

Comments
 (0)