1
0
mirror of https://github.com/nikic/PHP-Parser.git synced 2025-07-07 15:34:19 +02:00

Compare commits

...

4 Commits

Author SHA1 Message Date
08f97eb4ef Release PHP-Parser 1.2.2 2015-04-03 16:33:59 +02:00
8d18848fb0 Don't set unserialize_callback_func in Autoloader::register() as it has side effects even when the library is not used 2015-04-03 16:25:33 +02:00
805078e0a9 Add missing type hints 2015-03-28 18:14:24 +01:00
52dafafd10 Resolve param type hints earlier
For convenience of concurrent visitors that want to perform
enterNode actions based on Stmt\Function_ etc.

Fixes .
2015-03-25 20:57:39 +01:00
5 changed files with 26 additions and 15 deletions

@ -1,8 +1,16 @@
Version 1.2.2-dev
Version 1.2.3-dev
-----------------
Nothing yet.
Version 1.2.2 (2015-04-03)
--------------------------
* The `NameResolver` now resolves parameter type hints when entering the function/method/closure node. As such other
visitors running after it will be able to make use of the resolved names at that point already.
* The autoloader no longer sets the `unserialize_callback_func` ini option on registration - this is not necessary and
may cause issues when running PhpUnit tests with process isolation.
Version 1.2.1 (2015-03-24)
--------------------------

@ -23,7 +23,6 @@ class Autoloader
return;
}
ini_set('unserialize_callback_func', 'spl_autoload_call');
spl_autoload_register(array(__CLASS__, 'autoload'), true, $prepend);
self::$registered = true;
self::$runningOnPhp7 = version_compare(PHP_VERSION, '7.0-dev', '>=');

@ -15,7 +15,7 @@ class ShellExec extends Expr
* @param array $parts Encapsed string array
* @param array $attributes Additional attributes
*/
public function __construct($parts, array $attributes = array()) {
public function __construct(array $parts, array $attributes = array()) {
parent::__construct(null, $attributes);
$this->parts = $parts;
}

@ -28,7 +28,7 @@ class Param extends NodeAbstract
* @param bool $variadic Whether this is a variadic argument
* @param array $attributes Additional attributes
*/
public function __construct($name, $default = null, $type = null, $byRef = false, $variadic = false, array $attributes = array()) {
public function __construct($name, Expr $default = null, $type = null, $byRef = false, $variadic = false, array $attributes = array()) {
parent::__construct(null, $attributes);
$this->type = $type;
$this->byRef = $byRef;

@ -48,15 +48,11 @@ class NameResolver extends NodeVisitorAbstract
$this->addNamespacedName($node);
} elseif ($node instanceof Stmt\Function_) {
$this->addNamespacedName($node);
if ($node->returnType instanceof Name) {
$node->returnType = $this->resolveClassName($node->returnType);
}
$this->resolveSignature($node);
} elseif ($node instanceof Stmt\ClassMethod
|| $node instanceof Expr\Closure
) {
if ($node->returnType instanceof Name) {
$node->returnType = $this->resolveClassName($node->returnType);
}
$this->resolveSignature($node);
} elseif ($node instanceof Stmt\Const_) {
foreach ($node->consts as $const) {
$this->addNamespacedName($const);
@ -83,7 +79,7 @@ class NameResolver extends NodeVisitorAbstract
$trait = $this->resolveClassName($trait);
}
foreach($node->adaptations as $adaptation) {
foreach ($node->adaptations as $adaptation) {
if (null !== $adaptation->trait) {
$adaptation->trait = $this->resolveClassName($adaptation->trait);
}
@ -95,10 +91,6 @@ class NameResolver extends NodeVisitorAbstract
}
}
} elseif ($node instanceof Node\Param
&& $node->type instanceof Name
) {
$node->type = $this->resolveClassName($node->type);
}
}
@ -138,6 +130,18 @@ class NameResolver extends NodeVisitorAbstract
$this->aliases[$type][$aliasName] = $use->name;
}
/** @param Stmt\Function_|Stmt\ClassMethod|Expr\Closure $node */
private function resolveSignature($node) {
foreach ($node->params as $param) {
if ($param->type instanceof Name) {
$param->type = $this->resolveClassName($param->type);
}
}
if ($node->returnType instanceof Name) {
$node->returnType = $this->resolveClassName($node->returnType);
}
}
protected function resolveClassName(Name $name) {
// don't resolve special class names
if (in_array(strtolower($name->toString()), array('self', 'parent', 'static'))) {