Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Php70][Visibility] Avoid error Argument #1 ($scope) must be of type PHPStan\Analyser\Scope, null given #1120

Merged
merged 11 commits into from
Nov 1, 2021
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
{
}