Skip to content

Commit

Permalink
[Php70][Visibility] Avoid error Argument #1 ($scope) must be of type …
Browse files Browse the repository at this point in the history
…PHPStan\Analyser\Scope, null given (#1120)

Co-authored-by: GitHub Action <action@github.com>
  • Loading branch information
samsonasik and actions-user committed Nov 1, 2021
1 parent 99dfbea commit 539f70a
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,15 @@ private function isWrappedInCurlyBrackets(BetterTokenIterator $betterTokenProvid
return $betterTokenProvider->isTokenTypeOnPosition(Lexer::TOKEN_CLOSE_PARENTHESES, $startAndEnd->getEnd());
}

private function resolveStardAndEnd(Node $node): ?StartAndEnd
private function resolveStardAndEnd(UnionTypeNode $unionTypeNode): ?StartAndEnd
{
$starAndEnd = $node->getAttribute(PhpDocAttributeKey::START_AND_END);
$starAndEnd = $unionTypeNode->getAttribute(PhpDocAttributeKey::START_AND_END);
if ($starAndEnd instanceof StartAndEnd) {
return $starAndEnd;
}

// unwrap with parent array type...
$parent = $node->getAttribute(PhpDocAttributeKey::PARENT);
$parent = $unionTypeNode->getAttribute(PhpDocAttributeKey::PARENT);
if (! $parent instanceof Node) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use PhpParser\Node\Expr\New_;
use PhpParser\Node\Expr\PropertyFetch;
use PhpParser\Node\Expr\StaticCall;
use PHPStan\Analyser\Scope;
use PHPStan\Reflection\MethodReflection;
use PHPStan\Reflection\ReflectionProvider;
use PHPStan\Type\ObjectType;
Expand Down Expand Up @@ -158,6 +159,9 @@ private function shouldSkip(string $methodName, string $className, StaticCall $s
}

$scope = $staticCall->getAttribute(AttributeKey::SCOPE);
if (! $scope instanceof Scope) {
return true;
}

$parentClassName = $this->parentClassScopeResolver->resolveParentClassName($scope);
return $className === $parentClassName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use PhpParser\Node;
use PhpParser\Node\Stmt\ClassMethod;
use PHPStan\Analyser\Scope;
use Rector\Core\Contract\Rector\ConfigurableRectorInterface;
use Rector\Core\Rector\AbstractRector;
use Rector\Core\ValueObject\Visibility;
Expand Down Expand Up @@ -98,6 +99,9 @@ public function getNodeTypes(): array
public function refactor(Node $node): ?Node
{
$scope = $node->getAttribute(AttributeKey::SCOPE);
if (! $scope instanceof Scope) {
return null;
}

$parentClassName = $this->parentClassScopeResolver->resolveParentClassName($scope);
if ($parentClassName === null) {
Expand Down
4 changes: 3 additions & 1 deletion src/Bootstrap/RectorConfigsResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ private function resolveFromInput(ArgvInput $argvInput): ?string
throw new FileNotFoundException($message);
}

return realpath($configFile);
/** @var string $configFile */
$configFile = realpath($configFile);
return $configFile;
}

private function resolveFromInputWithFallback(ArgvInput $argvInput, string $fallbackFile): ?string
Expand Down
13 changes: 13 additions & 0 deletions stubs/Symfony/Component/HttpKernel/Bundle/BundleInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

declare(strict_types=1);

namespace Symfony\Component\HttpKernel\Bundle;

if (interface_exists('Symfony\Component\HttpKernel\Bundle\BundleInterface')) {
return;
}

interface BundleInterface
{
}

0 comments on commit 539f70a

Please sign in to comment.