Skip to content

Commit

Permalink
Changes after PR review
Browse files Browse the repository at this point in the history
  • Loading branch information
carlos-granados committed Nov 15, 2024
1 parent 4df6e0b commit 9818b42
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 13 deletions.
13 changes: 13 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,16 @@ parameters:

# overly detailed generics
- '#Rector\\TypePerfect\\Tests\\Rules\\(.*?) generic (class|interface)#'

-
identifier: phpstanApi.instanceofType
paths:
- src/Printer/CollectorMetadataPrinter.php
- src/Rules/NarrowPrivateClassMethodParamTypeRule.php
- src/Rules/NoArrayAccessOnObjectRule.php
- src/Rules/ReturnNullOverFalseRule.php

-
identifier: phpstanApi.instanceofAssumption
paths:
- src/Rules/NoParamTypeRemovalRule.php
10 changes: 4 additions & 6 deletions src/Printer/CollectorMetadataPrinter.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,12 @@
use PhpParser\Node\NullableType;
use PhpParser\Node\Stmt\ClassMethod;
use PhpParser\Node\UnionType;
use PhpParser\PrettyPrinter\Standard;
use PHPStan\Node\Printer\Printer;
use PHPStan\Analyser\Scope;
use PHPStan\Reflection\ExtendedMethodReflection;
use PHPStan\Reflection\ParametersAcceptorSelector;
use PHPStan\Type\ArrayType;
use PHPStan\Type\BooleanType;
use PHPStan\Type\ClassStringType;
use PHPStan\Type\ClosureType;
use PHPStan\Type\Enum\EnumCaseObjectType;
use PHPStan\Type\IntegerRangeType;
use PHPStan\Type\IntersectionType;
use PHPStan\Type\MixedType;
Expand All @@ -35,9 +32,11 @@

final readonly class CollectorMetadataPrinter
{
private Standard $printer;

public function __construct(
private Printer $printer
) {
$this->printer = new Standard();
}

public function printArgTypesAsString(MethodCall $methodCall, ExtendedMethodReflection $extendedMethodReflection, Scope $scope): string
Expand All @@ -54,7 +53,6 @@ public function printArgTypesAsString(MethodCall $methodCall, ExtendedMethodRefl
return ResolvedTypes::UNKNOWN_TYPES;
}

// @phpstan-ignore phpstanApi.instanceofType
if ($argType instanceof IntersectionType) {
return ResolvedTypes::UNKNOWN_TYPES;
}
Expand Down
3 changes: 1 addition & 2 deletions src/Reflection/ReflectionParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
use PhpParser\NodeVisitor\NameResolver;
use PhpParser\Parser;
use PhpParser\ParserFactory;
use PhpParser\PhpVersion;
use PHPStan\Reflection\ClassReflection;
use Throwable;

Expand All @@ -27,7 +26,7 @@ final class ReflectionParser
public function __construct()
{
$parserFactory = new ParserFactory();
$this->parser = $parserFactory->createForVersion(PhpVersion::fromString('7.4'));
$this->parser = $parserFactory->createForNewestSupportedVersion();
}

public function parseClassReflection(ClassReflection $classReflection): ?ClassLike
Expand Down
1 change: 0 additions & 1 deletion src/Rules/NarrowPrivateClassMethodParamTypeRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ private function validateParam(Param $param, int $position, Expr $expr, Scope $s
return null;
}

// @phpstan-ignore phpstanApi.instanceofType
if ($argType instanceof IntersectionType) {
return null;
}
Expand Down
1 change: 0 additions & 1 deletion src/Rules/NoArrayAccessOnObjectRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ public function getNodeType(): string
public function processNode(Node $node, Scope $scope): array
{
$varType = $scope->getType($node->var);
// @phpstan-ignore phpstanApi.instanceofType
if (! $varType instanceof ObjectType) {
return [];
}
Expand Down
1 change: 0 additions & 1 deletion src/Rules/NoParamTypeRemovalRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ public function processNode(Node $node, Scope $scope): array
}

$parentClassMethodReflection = $this->methodNodeAnalyser->matchFirstParentClassMethod($scope, $classMethodName);
// @phpstan-ignore phpstanApi.instanceofAssumption
if (! $parentClassMethodReflection instanceof PhpMethodReflection) {
return [];
}
Expand Down
2 changes: 0 additions & 2 deletions src/Rules/ReturnNullOverFalseRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
use PHPStan\Rules\Rule;
use PHPStan\Rules\RuleError;
use PHPStan\Rules\RuleErrorBuilder;
use PHPStan\Type\BooleanType;
use PHPStan\Type\Constant\ConstantBooleanType;
use Rector\TypePerfect\Configuration;

Expand Down Expand Up @@ -74,7 +73,6 @@ public function processNode(Node $node, Scope $scope): array
}

$exprType = $scope->getType($return->expr);
// @phpstan-ignore phpstanApi.instanceofType
if (! $exprType instanceof ConstantBooleanType) {
if ($exprType->isBoolean()->yes()) {
return [];
Expand Down

0 comments on commit 9818b42

Please sign in to comment.