Commaaa2
This commit is contained in:
@@ -59,9 +59,14 @@ class PassableByReferencePass extends CodeCleanerPass
|
||||
return;
|
||||
}
|
||||
|
||||
$args = [];
|
||||
foreach ($node->args as $position => $arg) {
|
||||
$args[$arg->name !== null ? $arg->name->name : $position] = $arg;
|
||||
}
|
||||
|
||||
foreach ($refl->getParameters() as $key => $param) {
|
||||
if (\array_key_exists($key, $node->args)) {
|
||||
$arg = $node->args[$key];
|
||||
if (\array_key_exists($key, $args) || \array_key_exists($param->name, $args)) {
|
||||
$arg = $args[$param->name] ?? $args[$key];
|
||||
if ($param->isPassedByReference() && !$this->isPassableByReference($arg)) {
|
||||
throw new FatalErrorException(self::EXCEPTION_MESSAGE, 0, \E_ERROR, null, $node->getStartLine());
|
||||
}
|
||||
|
||||
@@ -15,6 +15,8 @@ use PhpParser\Node;
|
||||
use PhpParser\Node\Expr\Closure;
|
||||
use PhpParser\Node\Expr\ConstFetch;
|
||||
use PhpParser\Node\Identifier;
|
||||
use PhpParser\Node\IntersectionType;
|
||||
use PhpParser\Node\Name;
|
||||
use PhpParser\Node\NullableType;
|
||||
use PhpParser\Node\Stmt\Function_;
|
||||
use PhpParser\Node\Stmt\Return_;
|
||||
@@ -100,12 +102,16 @@ class ReturnTypePass extends CodeCleanerPass
|
||||
return \implode('|', \array_map([$this, 'typeName'], $node->types));
|
||||
}
|
||||
|
||||
if ($node instanceof NullableType) {
|
||||
return \strtolower($node->type->name);
|
||||
if ($node instanceof IntersectionType) {
|
||||
return \implode('&', \array_map([$this, 'typeName'], $node->types));
|
||||
}
|
||||
|
||||
if ($node instanceof Identifier) {
|
||||
return \strtolower($node->name);
|
||||
if ($node instanceof NullableType) {
|
||||
return $this->typeName($node->type);
|
||||
}
|
||||
|
||||
if ($node instanceof Identifier || $node instanceof Name) {
|
||||
return $node->toLowerString();
|
||||
}
|
||||
|
||||
throw new \InvalidArgumentException('Unable to find type name');
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
namespace Psy\CodeCleaner;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\DeclareItem;
|
||||
use PhpParser\Node\Scalar\LNumber;
|
||||
use PhpParser\Node\Stmt\Declare_;
|
||||
use PhpParser\Node\Stmt\DeclareDeclare;
|
||||
@@ -78,7 +79,10 @@ class StrictTypesPass extends CodeCleanerPass
|
||||
if (!$first instanceof Declare_) {
|
||||
// @todo Switch to PhpParser\Node\DeclareItem once we drop support for PHP-Parser 4.x
|
||||
// @todo Rename LNumber to Int_ once we drop support for PHP-Parser 4.x
|
||||
$declare = new Declare_([new DeclareDeclare('strict_types', new LNumber(1))]);
|
||||
$declareItem = \class_exists('PhpParser\Node\DeclareItem') ?
|
||||
new DeclareItem('strict_types', new LNumber(1)) :
|
||||
new DeclareDeclare('strict_types', new LNumber(1));
|
||||
$declare = new Declare_([$declareItem]);
|
||||
\array_unshift($nodes, $declare);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user