Skip to content

Commit

Permalink
PHPStan updated
Browse files Browse the repository at this point in the history
  • Loading branch information
kukulich committed Feb 4, 2018
1 parent 4a3bfbf commit ac66559
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ jobs:
php: 7.1
env: DEPENDENCIES=""
before_script:
- travis_retry composer require --dev --prefer-dist --prefer-stable phpstan/phpstan:^0.8.3
- travis_retry composer require --dev --prefer-dist --prefer-stable phpstan/phpstan:^0.9.2
script: vendor/bin/phpstan analyse -l 5 -c phpstan.neon src

- stage: Run benchmarks
Expand Down
8 changes: 5 additions & 3 deletions src/NodeCompiler/CompileNodeToValue.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,25 +130,27 @@ private function compileConstFetch(Node\Expr\ConstFetch $constNode)
*/
private function compileClassConstFetch(Node\Expr\ClassConstFetch $node, CompilerContext $context)
{
/** @var string $nodeName */
$nodeName = $node->name;
$className = $node->class->toString();

if ($node->name === 'class') {
if ($nodeName === 'class') {
return $className;
}

/** @var ReflectionClass|null $classInfo */
$classInfo = null;

if ($className === 'self' || $className === 'static') {
$classInfo = $this->getConstantDeclaringClass($node->name, $context->getSelf());
$classInfo = $this->getConstantDeclaringClass($nodeName, $context->getSelf());
}

if ($classInfo === null) {
/** @var ReflectionClass $classInfo */
$classInfo = $context->getReflector()->reflect($className);
}

$reflectionConstant = $classInfo->getReflectionConstant($node->name);
$reflectionConstant = $classInfo->getReflectionConstant($nodeName);

return $this->__invoke(
$reflectionConstant->getAst()->consts[$reflectionConstant->getPositionInAst()]->value,
Expand Down
6 changes: 5 additions & 1 deletion src/Reflection/ReflectionClass.php
Original file line number Diff line number Diff line change
Expand Up @@ -259,9 +259,12 @@ function (ClassMethod $methodNode) : ReflectionMethod {
...array_map(
function (ReflectionClass $trait) : array {
return array_map(function (ReflectionMethod $method) use ($trait) : ReflectionMethod {
/** @var ClassMethod $methodAst */
$methodAst = $method->getAst();

return ReflectionMethod::createFromNode(
$this->reflector,
$method->getAst(),
$methodAst,
$this->declaringNamespace,
$trait,
$this
Expand Down Expand Up @@ -958,6 +961,7 @@ public function getTraitAliases() : array
$adaptations = $traitUsage->adaptations;

foreach ($adaptations as $adaptation) {
/** @var Node\Name|null $usedTrait */
$usedTrait = $adaptation->trait;
if ($usedTrait === null) {
$usedTrait = $traitNames[0];
Expand Down
13 changes: 9 additions & 4 deletions src/Reflection/ReflectionFunctionAbstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public static function export() : void
/**
* Populate the common elements of the function abstract.
*
* @param Node\Stmt\ClassMethod|Node\FunctionLike|Node\Stmt|Node $node Node has to be processed by the PhpParser\NodeVisitor\NameResolver
* @param Node\Stmt\ClassMethod|Node\Stmt\Function_|Node\Expr\Closure $node Node has to be processed by the PhpParser\NodeVisitor\NameResolver
*
* @throws \Roave\BetterReflection\Reflection\Exception\InvalidAbstractFunctionNodeType
*/
Expand Down Expand Up @@ -318,7 +318,9 @@ private function nodeIsOrContainsYield(Node $node) : bool
return true;
}

foreach ($node as $nodeProperty) {
foreach ($node->getSubNodeNames() as $nodeName) {
$nodeProperty = $node->$nodeName;

if ($nodeProperty instanceof Node && $this->nodeIsOrContainsYield($nodeProperty)) {
return true;
}
Expand Down Expand Up @@ -379,7 +381,7 @@ public function getEndColumn() : int
*/
public function returnsReference() : bool
{
return (bool) $this->node->byRef;
return $this->node->byRef;
}

/**
Expand Down Expand Up @@ -503,7 +505,10 @@ public function setBodyFromClosure(Closure $newBody) : void
new Identifier(self::CLOSURE_NAME, new IdentifierType(IdentifierType::IDENTIFIER_FUNCTION))
);

$this->node->stmts = $closureReflection->getNode()->stmts;
/** @var Node\Stmt\Function_ $functionNode */
$functionNode = $closureReflection->getNode();

$this->node->stmts = $functionNode->stmts;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Reflection/ReflectionParameter.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public static function createFromClosure(Closure $closure, string $parameterName
* - ['foo']
* - [function () {}]
*
* @param string[]|string|\Closure $spec
* @param object[]|string[]|string|\Closure $spec
* @throws \Exception
* @throws \InvalidArgumentException
*/
Expand Down Expand Up @@ -195,7 +195,7 @@ private function parseDefaultValueNode() : void
$className = $defaultValueNode->class->toString();

if ($className === 'self' || $className === 'static') {
$className = $this->findParentClassDeclaringConstant($defaultValueNode->name);
$className = $this->findParentClassDeclaringConstant((string) $defaultValueNode->name);
}

$this->isDefaultValueConstant = true;
Expand Down
2 changes: 1 addition & 1 deletion src/Reflection/ReflectionType.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class ReflectionType
];

/**
* @var $type
* @var string
*/
private $type;

Expand Down
3 changes: 2 additions & 1 deletion src/Reflector/ClassReflector.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,14 @@ public function __construct(SourceLocator $sourceLocator)
/**
* Create a ReflectionClass for the specified $className.
*
* @return \Roave\BetterReflection\Reflection\ReflectionClass|Reflection
* @return \Roave\BetterReflection\Reflection\ReflectionClass
* @throws \Roave\BetterReflection\Reflector\Exception\IdentifierNotFound
*/
public function reflect(string $className) : Reflection
{
$identifier = new Identifier($className, new IdentifierType(IdentifierType::IDENTIFIER_CLASS));

/** @var \Roave\BetterReflection\Reflection\ReflectionClass|null $classInfo */
$classInfo = $this->sourceLocator->locateIdentifier($this, $identifier);

if ($classInfo === null) {
Expand Down
3 changes: 2 additions & 1 deletion src/Reflector/FunctionReflector.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,14 @@ public function __construct(SourceLocator $sourceLocator, ClassReflector $classR
/**
* Create a ReflectionFunction for the specified $functionName.
*
* @return \Roave\BetterReflection\Reflection\Reflection|\Roave\BetterReflection\Reflection\ReflectionFunction
* @return \Roave\BetterReflection\Reflection\ReflectionFunction
* @throws \Roave\BetterReflection\Reflector\Exception\IdentifierNotFound
*/
public function reflect(string $functionName) : Reflection
{
$identifier = new Identifier($functionName, new IdentifierType(IdentifierType::IDENTIFIER_FUNCTION));

/** @var \Roave\BetterReflection\Reflection\ReflectionFunction|null $functionInfo */
$functionInfo = $this->sourceLocator->locateIdentifier($this->classReflector, $identifier);

if ($functionInfo === null) {
Expand Down

0 comments on commit ac66559

Please sign in to comment.