update v1.0.4

This commit is contained in:
sujitprasad
2016-01-04 18:05:45 +05:30
parent 372485336b
commit 4864e5a3f1
529 changed files with 20956 additions and 8178 deletions

View File

@@ -9,6 +9,7 @@ use PhpParser\PrettyPrinter\Standard as NodePrinter;
use PhpParser\Error as ParserError;
use PhpParser\NodeVisitor\NameResolver;
use PhpParser\Parser as CodeParser;
use PhpParser\ParserFactory;
use PhpParser\Lexer\Emulative as EmulativeLexer;
/**
@@ -122,8 +123,19 @@ class AstAnalyzer extends ClosureAnalyzer
);
}
$parser = new CodeParser(new EmulativeLexer);
return $parser->parse(file_get_contents($fileName));
return $this->getParser()->parse(file_get_contents($fileName));
}
/**
* @return CodeParser
*/
private function getParser()
{
if (class_exists('PhpParser\ParserFactory')) {
return (new ParserFactory)->create(ParserFactory::PREFER_PHP7);
}
return new CodeParser(new EmulativeLexer);
}
}

View File

@@ -55,7 +55,13 @@ abstract class ClosureAnalyzer
private function isClosureStatic(\Closure $closure)
{
$rebound = new \ReflectionFunction(@$closure->bindTo(new \stdClass));
$closure = @$closure->bindTo(new \stdClass);
if ($closure === null) {
return true;
}
$rebound = new \ReflectionFunction($closure);
return $rebound->getClosureThis() === null;
}

View File

@@ -68,7 +68,7 @@ class TokenAnalyzer extends ClosureAnalyzer
case 3:
if ($token->is(T_FUNCTION)) {
throw new ClosureAnalysisException('Multiple closures '
. 'were declared on the same line of code. Could '
. 'were declared on the same line of code. Could not '
. 'determine which closure was the intended target.'
);
}

View File

@@ -106,12 +106,15 @@ final class ClosureLocatorVisitor extends NodeVisitor
} elseif ($this->location['trait']) {
$this->location['trait'] = $this->location['namespace'] . '\\' . $this->location['trait'];
$this->location['method'] = "{$this->location['trait']}::{$this->location['function']}";
}
if (!$this->location['class']) {
/** @var \ReflectionClass $closureScopeClass */
$closureScopeClass = $this->reflection->getClosureScopeClass();
$this->location['class'] = $closureScopeClass ? $closureScopeClass->getName() : null;
// If the closure was declared in a trait, then we will do a best
// effort guess on the name of the class that used the trait. It's
// actually impossible at this point to know for sure what it is.
if ($closureScope = $this->reflection->getClosureScopeClass()) {
$this->location['class'] = $closureScope ? $closureScope->getName() : null;
} elseif ($closureThis = $this->reflection->getClosureThis()) {
$this->location['class'] = get_class($closureThis);
}
}
}
}

View File

@@ -1,7 +1,7 @@
<?php namespace SuperClosure\Analyzer\Visitor;
use PhpParser\Node\Scalar\LNumber as NumberNode;
use PhpParser\Node\Scalar\String as StringNode;
use PhpParser\Node\Scalar\String_ as StringNode;
use PhpParser\Node as AstNode;
use PhpParser\NodeVisitorAbstract as NodeVisitor;