Skip to content

Commit

Permalink
Fixes after PHPStan update
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Sep 30, 2024
1 parent 7e5633f commit a0572ad
Show file tree
Hide file tree
Showing 14 changed files with 14 additions and 28 deletions.
3 changes: 1 addition & 2 deletions src/Rules/Symfony/InvalidArgumentDefaultValueRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
use PHPStan\Type\NullType;
use PHPStan\Type\ObjectType;
use PHPStan\Type\StringType;
use PHPStan\Type\TypeUtils;
use PHPStan\Type\UnionType;
use PHPStan\Type\VerbosityLevel;
use function count;
Expand Down Expand Up @@ -46,7 +45,7 @@ public function processNode(Node $node, Scope $scope): array
if ($modeType->isNull()->yes()) {
$modeType = new ConstantIntegerType(2); // InputArgument::OPTIONAL
}
$modeTypes = TypeUtils::getConstantScalars($modeType);
$modeTypes = $modeType->getConstantScalarTypes();
if (count($modeTypes) !== 1) {
return [];
}
Expand Down
3 changes: 1 addition & 2 deletions src/Rules/Symfony/InvalidOptionDefaultValueRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
use PHPStan\Type\NullType;
use PHPStan\Type\ObjectType;
use PHPStan\Type\StringType;
use PHPStan\Type\TypeUtils;
use PHPStan\Type\UnionType;
use PHPStan\Type\VerbosityLevel;
use function count;
Expand Down Expand Up @@ -48,7 +47,7 @@ public function processNode(Node $node, Scope $scope): array
if ($modeType->isNull()->yes()) {
$modeType = new ConstantIntegerType(1); // InputOption::VALUE_NONE
}
$modeTypes = TypeUtils::getConstantScalars($modeType);
$modeTypes = $modeType->getConstantScalarTypes();
if (count($modeTypes) !== 1) {
return [];
}
Expand Down
3 changes: 1 addition & 2 deletions src/Rules/Symfony/UndefinedArgumentRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
use PHPStan\Symfony\ConsoleApplicationResolver;
use PHPStan\Type\ObjectType;
use PHPStan\Type\Symfony\Helper;
use PHPStan\Type\TypeUtils;
use function count;
use function sprintf;

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

$argType = $scope->getType($node->getArgs()[0]->value);
$argStrings = TypeUtils::getConstantStrings($argType);
$argStrings = $argType->getConstantStrings();
if (count($argStrings) !== 1) {
return [];
}
Expand Down
3 changes: 1 addition & 2 deletions src/Rules/Symfony/UndefinedOptionRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
use PHPStan\Symfony\ConsoleApplicationResolver;
use PHPStan\Type\ObjectType;
use PHPStan\Type\Symfony\Helper;
use PHPStan\Type\TypeUtils;
use function count;
use function sprintf;

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

$optType = $scope->getType($node->getArgs()[0]->value);
$optStrings = TypeUtils::getConstantStrings($optType);
$optStrings = $optType->getConstantStrings();
if (count($optStrings) !== 1) {
return [];
}
Expand Down
3 changes: 1 addition & 2 deletions src/Symfony/DefaultParameterMap.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use PhpParser\Node\Expr;
use PHPStan\Analyser\Scope;
use PHPStan\Type\Type;
use PHPStan\Type\TypeUtils;
use function array_map;

final class DefaultParameterMap implements ParameterMap
Expand Down Expand Up @@ -37,7 +36,7 @@ public function getParameter(string $key): ?ParameterDefinition

public static function getParameterKeysFromNode(Expr $node, Scope $scope): array
{
$strings = TypeUtils::getConstantStrings($scope->getType($node));
$strings = $scope->getType($node)->getConstantStrings();

return array_map(static fn (Type $type) => $type->getValue(), $strings);
}
Expand Down
3 changes: 1 addition & 2 deletions src/Symfony/DefaultServiceMap.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use PhpParser\Node\Expr;
use PHPStan\Analyser\Scope;
use PHPStan\Type\TypeUtils;
use function count;

final class DefaultServiceMap implements ServiceMap
Expand Down Expand Up @@ -36,7 +35,7 @@ public function getService(string $id): ?ServiceDefinition

public static function getServiceIdFromNode(Expr $node, Scope $scope): ?string
{
$strings = TypeUtils::getConstantStrings($scope->getType($node));
$strings = $scope->getType($node)->getConstantStrings();
return count($strings) === 1 ? $strings[0]->getValue() : null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
use PHPStan\Type\ObjectType;
use PHPStan\Type\Type;
use PHPStan\Type\TypeCombinator;
use PHPStan\Type\TypeUtils;
use Throwable;
use function count;
use function get_class;
Expand Down Expand Up @@ -46,7 +45,7 @@ public function getTypeFromMethodCall(MethodReflection $methodReflection, Method
return null;
}

$argStrings = TypeUtils::getConstantStrings($scope->getType($methodCall->getArgs()[0]->value));
$argStrings = $scope->getType($methodCall->getArgs()[0]->value)->getConstantStrings();
if (count($argStrings) !== 1) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
use PHPStan\Type\DynamicMethodReturnTypeExtension;
use PHPStan\Type\Symfony\Config\ValueObject\ParentObjectType;
use PHPStan\Type\Type;
use PHPStan\Type\TypeUtils;
use PHPStan\Type\VerbosityLevel;
use function count;
use function in_array;
Expand Down Expand Up @@ -66,7 +65,7 @@ public function getTypeFromMethodCall(
return $defaultType;
}

$argStrings = TypeUtils::getConstantStrings($scope->getType($methodCall->getArgs()[0]->value));
$argStrings = $scope->getType($methodCall->getArgs()[0]->value)->getConstantStrings();
if (count($argStrings) === 1 && isset(self::MAPPING[$argStrings[0]->getValue()])) {
$type = $argStrings[0]->getValue();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
use PHPStan\Type\DynamicStaticMethodReturnTypeExtension;
use PHPStan\Type\Symfony\Config\ValueObject\TreeBuilderType;
use PHPStan\Type\Type;
use PHPStan\Type\TypeUtils;
use function count;

final class TreeBuilderDynamicReturnTypeExtension implements DynamicStaticMethodReturnTypeExtension
Expand Down Expand Up @@ -47,7 +46,7 @@ public function getTypeFromStaticMethodCall(MethodReflection $methodReflection,
$type = 'array';

if (isset($methodCall->getArgs()[1])) {
$argStrings = TypeUtils::getConstantStrings($scope->getType($methodCall->getArgs()[1]->value));
$argStrings = $scope->getType($methodCall->getArgs()[1]->value)->getConstantStrings();
if (count($argStrings) === 1 && isset(self::MAPPING[$argStrings[0]->getValue()])) {
$type = $argStrings[0]->getValue();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
use PHPStan\Type\StringType;
use PHPStan\Type\Type;
use PHPStan\Type\TypeCombinator;
use PHPStan\Type\TypeUtils;
use function count;
use function in_array;

Expand Down Expand Up @@ -49,7 +48,7 @@ public function getTypeFromMethodCall(MethodReflection $methodReflection, Method
return null;
}

$argStrings = TypeUtils::getConstantStrings($scope->getType($methodCall->getArgs()[0]->value));
$argStrings = $scope->getType($methodCall->getArgs()[0]->value)->getConstantStrings();
if (count($argStrings) !== 1) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
use PHPStan\Type\DynamicMethodReturnTypeExtension;
use PHPStan\Type\Type;
use PHPStan\Type\TypeCombinator;
use PHPStan\Type\TypeUtils;
use function count;

final class InputInterfaceGetOptionDynamicReturnTypeExtension implements DynamicMethodReturnTypeExtension
Expand Down Expand Up @@ -47,7 +46,7 @@ public function getTypeFromMethodCall(MethodReflection $methodReflection, Method
return null;
}

$optStrings = TypeUtils::getConstantStrings($scope->getType($methodCall->getArgs()[0]->value));
$optStrings = $scope->getType($methodCall->getArgs()[0]->value)->getConstantStrings();
if (count($optStrings) !== 1) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
use PHPStan\Type\Constant\ConstantBooleanType;
use PHPStan\Type\DynamicMethodReturnTypeExtension;
use PHPStan\Type\Type;
use PHPStan\Type\TypeUtils;
use function array_unique;
use function count;
use function in_array;
Expand Down Expand Up @@ -46,7 +45,7 @@ public function getTypeFromMethodCall(MethodReflection $methodReflection, Method
return null;
}

$argStrings = TypeUtils::getConstantStrings($scope->getType($methodCall->getArgs()[0]->value));
$argStrings = $scope->getType($methodCall->getArgs()[0]->value)->getConstantStrings();
if (count($argStrings) !== 1) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
use PHPStan\Type\Constant\ConstantBooleanType;
use PHPStan\Type\DynamicMethodReturnTypeExtension;
use PHPStan\Type\Type;
use PHPStan\Type\TypeUtils;
use function array_unique;
use function count;

Expand Down Expand Up @@ -45,7 +44,7 @@ public function getTypeFromMethodCall(MethodReflection $methodReflection, Method
return null;
}

$optStrings = TypeUtils::getConstantStrings($scope->getType($methodCall->getArgs()[0]->value));
$optStrings = $scope->getType($methodCall->getArgs()[0]->value)->getConstantStrings();
if (count($optStrings) !== 1) {
return null;
}
Expand Down
3 changes: 1 addition & 2 deletions src/Type/Symfony/ParameterDynamicReturnTypeExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
use PHPStan\Type\Constant\ConstantArrayType;
use PHPStan\Type\Constant\ConstantArrayTypeBuilder;
use PHPStan\Type\Constant\ConstantBooleanType;
use PHPStan\Type\ConstantType;
use PHPStan\Type\DynamicMethodReturnTypeExtension;
use PHPStan\Type\FloatType;
use PHPStan\Type\GeneralizePrecision;
Expand Down Expand Up @@ -194,7 +193,7 @@ private function generalizeType(Type $type): Type
}
return new ArrayType($this->generalizeType($type->getKeyType()), $this->generalizeType($type->getItemType()));
}
if ($type instanceof ConstantType) {
if ($type->isConstantValue()->yes()) {
return $type->generalize(GeneralizePrecision::lessSpecific());
}
return $traverse($type);
Expand Down

0 comments on commit a0572ad

Please sign in to comment.