add few create_function cases

This commit is contained in:
Tomas Votruba 2018-12-18 01:02:03 +01:00
parent da9e036b85
commit c31dcb18a0
2 changed files with 54 additions and 0 deletions

View File

@ -16,6 +16,7 @@ final class CreateFunctionToAnonymousFunctionRectorTest extends AbstractRectorTe
__DIR__ . '/Fixture/stackoverflow.php.inc',
__DIR__ . '/Fixture/drupal.php.inc',
__DIR__ . '/Fixture/php_net.php.inc',
__DIR__ . '/Fixture/wordpress.php.inc',
]);
}

View File

@ -0,0 +1,53 @@
<?php
namespace Rector\Php\Tests\Rector\FuncCall\CreateFunctionToAnonymousFunctionRector\Fixture;
class Wordpress
{
public function run()
{
$replace = create_function('$t', 'return $t || "0" === $t;');
$php_with = 'abc';
$function = create_function('$x', "return \$php_with.\$x;");
$this->map_attrs_func = create_function('$k,$v', 'return "$k=\"$v\"";');
$this->map_xmlns_func = create_function('$p,$n', '$xd = "xmlns"; if(strlen($n[0])>0) $xd .= ":{$n[0]}"; return "{$xd}=\"{$n[1]}\"";');
}
}
?>
-----
<?php
namespace Rector\Php\Tests\Rector\FuncCall\CreateFunctionToAnonymousFunctionRector\Fixture;
class Wordpress
{
public function run()
{
$replace = function ($t) {
return $t || "0" === $t;
};
$php_with = 'abc';
$function = function ($x) use ($php_with) {
return $php_with . $x;
};
$this->map_attrs_func = function ($k, $v) {
return "{$k}=\"{$v}\"";
};
$this->map_xmlns_func = function ($p, $n) use ($xd) {
$xd = "xmlns";
if (strlen($n[0]) > 0) {
$xd .= ":{$n[0]}";
}
return "{$xd}=\"{$n[1]}\"";
};
}
}
?>