Skip to content

Commit

Permalink
Fix build
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Jan 31, 2023
1 parent 44aef78 commit 99ff19f
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/Rules/Symfony/InvalidArgumentDefaultValueRule.php
Expand Up @@ -46,7 +46,7 @@ public function processNode(Node $node, Scope $scope): array
}

$modeType = isset($node->getArgs()[1]) ? $scope->getType($node->getArgs()[1]->value) : new NullType();
if ($modeType instanceof NullType) {
if ($modeType->isNull()->yes()) {
$modeType = new ConstantIntegerType(2); // InputArgument::OPTIONAL
}
$modeTypes = TypeUtils::getConstantScalars($modeType);
Expand Down
2 changes: 1 addition & 1 deletion src/Rules/Symfony/InvalidOptionDefaultValueRule.php
Expand Up @@ -48,7 +48,7 @@ public function processNode(Node $node, Scope $scope): array
}

$modeType = isset($node->getArgs()[2]) ? $scope->getType($node->getArgs()[2]->value) : new NullType();
if ($modeType instanceof NullType) {
if ($modeType->isNull()->yes()) {
$modeType = new ConstantIntegerType(1); // InputOption::VALUE_NONE
}
$modeTypes = TypeUtils::getConstantScalars($modeType);
Expand Down
11 changes: 8 additions & 3 deletions src/Type/Symfony/EnvelopeReturnTypeExtension.php
Expand Up @@ -7,12 +7,12 @@
use PHPStan\Reflection\MethodReflection;
use PHPStan\Type\Accessory\AccessoryArrayListType;
use PHPStan\Type\ArrayType;
use PHPStan\Type\Constant\ConstantStringType;
use PHPStan\Type\DynamicMethodReturnTypeExtension;
use PHPStan\Type\Generic\GenericClassStringType;
use PHPStan\Type\IntegerType;
use PHPStan\Type\ObjectType;
use PHPStan\Type\Type;
use PHPStan\Type\TypeCombinator;
use function count;

final class EnvelopeReturnTypeExtension implements DynamicMethodReturnTypeExtension
Expand Down Expand Up @@ -42,11 +42,16 @@ public function getTypeFromMethodCall(
}

$argType = $scope->getType($methodCall->getArgs()[0]->value);
if (!$argType instanceof ConstantStringType) {
if (count($argType->getConstantStrings()) === 0) {
return AccessoryArrayListType::intersectWith(new ArrayType(new IntegerType(), new ObjectType('Symfony\Component\Messenger\Stamp\StampInterface')));
}

return AccessoryArrayListType::intersectWith(new ArrayType(new IntegerType(), new ObjectType($argType->getValue())));
$objectTypes = [];
foreach ($argType->getConstantStrings() as $constantString) {
$objectTypes[] = new ObjectType($constantString->getValue());
}

return AccessoryArrayListType::intersectWith(new ArrayType(new IntegerType(), TypeCombinator::union(...$objectTypes)));
}

}
12 changes: 8 additions & 4 deletions src/Type/Symfony/SerializerDynamicReturnTypeExtension.php
Expand Up @@ -6,11 +6,12 @@
use PHPStan\Analyser\Scope;
use PHPStan\Reflection\MethodReflection;
use PHPStan\Type\ArrayType;
use PHPStan\Type\Constant\ConstantStringType;
use PHPStan\Type\DynamicMethodReturnTypeExtension;
use PHPStan\Type\MixedType;
use PHPStan\Type\ObjectType;
use PHPStan\Type\Type;
use PHPStan\Type\TypeCombinator;
use function count;
use function substr;

class SerializerDynamicReturnTypeExtension implements DynamicMethodReturnTypeExtension
Expand Down Expand Up @@ -45,13 +46,16 @@ public function getTypeFromMethodCall(MethodReflection $methodReflection, Method
}

$argType = $scope->getType($methodCall->getArgs()[1]->value);
if (!$argType instanceof ConstantStringType) {
if (count($argType->getConstantStrings()) === 0) {
return new MixedType();
}

$objectName = $argType->getValue();
$types = [];
foreach ($argType->getConstantStrings() as $constantString) {
$types[] = $this->getType($constantString->getValue());
}

return $this->getType($objectName);
return TypeCombinator::union(...$types);
}

private function getType(string $objectName): Type
Expand Down

0 comments on commit 99ff19f

Please sign in to comment.