Skip to content

Commit

Permalink
bump deps
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasVotruba committed Jan 29, 2021
1 parent 227c244 commit 1c882b5
Show file tree
Hide file tree
Showing 4 changed files with 115 additions and 40 deletions.
32 changes: 16 additions & 16 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,16 @@
"symfony/finder": "^4.4.8|^5.1",
"symfony/http-kernel": "^4.4.8|^5.1",
"symfony/process": "^4.4.8|^5.1",
"symplify/astral": "^9.0.34",
"symplify/autowire-array-parameter": "^9.0.34",
"symplify/console-color-diff": "^9.0.34",
"symplify/package-builder": "^9.0.34",
"symplify/rule-doc-generator": "^9.0.34",
"symplify/set-config-resolver": "^9.0.34",
"symplify/simple-php-doc-parser": "^9.0",
"symplify/skipper": "^9.0.34",
"symplify/smart-file-system": "^9.0.34",
"symplify/symfony-php-config": "^9.0.34",
"symplify/astral": "^9.0.48",
"symplify/autowire-array-parameter": "^9.0.48",
"symplify/console-color-diff": "^9.0.48",
"symplify/package-builder": "^9.0.48",
"symplify/rule-doc-generator": "^9.0.48",
"symplify/set-config-resolver": "^9.0.48",
"symplify/simple-php-doc-parser": "^9.0.48",
"symplify/skipper": "^9.0.48",
"symplify/smart-file-system": "^9.0.48",
"symplify/symfony-php-config": "^9.0.48",
"webmozart/assert": "^1.9"
},
"require-dev": {
Expand All @@ -72,12 +72,12 @@
"sebastian/diff": "^4.0.4",
"symfony/security-core": "^5.2",
"symfony/security-http": "^5.2",
"symplify/changelog-linker": "^9.0.34",
"symplify/coding-standard": "^9.0.34",
"symplify/easy-coding-standard": "^9.0.34",
"symplify/easy-testing": "^9.0.34",
"symplify/phpstan-extensions": "^9.0.34",
"symplify/phpstan-rules": "^9.0.34",
"symplify/changelog-linker": "^9.0.48",
"symplify/coding-standard": "^9.0.48",
"symplify/easy-coding-standard": "^9.0.48",
"symplify/easy-testing": "^9.0.48",
"symplify/phpstan-extensions": "^9.0.48",
"symplify/phpstan-rules": "^9.0.48",
"tracy/tracy": "^2.7"
},
"replace": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use PHPStan\PhpDocParser\Ast\PhpDoc\MethodTagValueNode;
use PHPStan\PhpDocParser\Ast\PhpDoc\MethodTagValueParameterNode;
use PHPStan\PhpDocParser\Ast\PhpDoc\ReturnTagValueNode;
use PHPStan\PhpDocParser\Ast\Type\ArrayTypeNode;
use PHPStan\PhpDocParser\Ast\Type\IdentifierTypeNode;
use PHPStan\PhpDocParser\Ast\Type\TypeNode;
use PHPStan\PhpDocParser\Ast\Type\UnionTypeNode;
Expand Down Expand Up @@ -48,30 +49,7 @@ public function createFromMethodReflectionAndReturnTagValueNode(
$classReflection = $methodReflection->getDeclaringClass();
$templateTypeMap = $classReflection->getTemplateTypeMap();

$returnTagTypeNode = $returnTagValueNode->type;

if ($returnTagValueNode->type instanceof UnionTypeNode) {
$resolvedTypes = [];
foreach ($returnTagValueNode->type->types as $unionedTypeNode) {
if (! $unionedTypeNode instanceof IdentifierTypeNode) {
continue;
}

$resolvedTypes[] = $this->resolveIdentifierTypeNode(
$unionedTypeNode,
$templateTypeMap,
$unionedTypeNode
);
}

$returnTagTypeNode = new UnionTypeNode($resolvedTypes);
} elseif ($returnTagValueNode->type instanceof IdentifierTypeNode) {
$returnTagTypeNode = $this->resolveIdentifierTypeNode(
$returnTagValueNode->type,
$templateTypeMap,
$returnTagTypeNode
);
}
$returnTagTypeNode = $this->resolveReturnTagTypeNode($returnTagValueNode, $templateTypeMap);

return new MethodTagValueNode(
false,
Expand Down Expand Up @@ -99,6 +77,23 @@ private function resolveStringParameters(array $parameterReflections): array
return $stringParameters;
}

private function resolveReturnTagTypeNode(ReturnTagValueNode $returnTagValueNode, TemplateTypeMap $templateTypeMap): TypeNode
{
$returnTagTypeNode = $returnTagValueNode->type;

if ($returnTagValueNode->type instanceof UnionTypeNode) {
return $this->resolveUnionTypeNode($returnTagValueNode->type, $templateTypeMap);
} elseif ($returnTagValueNode->type instanceof IdentifierTypeNode) {
return $this->resolveIdentifierTypeNode(
$returnTagValueNode->type,
$templateTypeMap,
$returnTagTypeNode
);
}

return $returnTagTypeNode;
}

private function resolveIdentifierTypeNode(
IdentifierTypeNode $identifierTypeNode,
TemplateTypeMap $templateTypeMap,
Expand All @@ -114,4 +109,28 @@ private function resolveIdentifierTypeNode(

return $fallbackTypeNode;
}

private function resolveUnionTypeNode(UnionTypeNode $unionTypeNode, TemplateTypeMap $templateTypeMap): UnionTypeNode
{
$resolvedTypes = [];
foreach ($unionTypeNode->types as $unionedTypeNode) {
if ($unionedTypeNode instanceof ArrayTypeNode) {
$resolvedType = $this->resolveIdentifierTypeNode(
$unionedTypeNode->type,
$templateTypeMap,
$unionedTypeNode
);

$resolvedTypes[] = new ArrayTypeNode($resolvedType);
} elseif ($unionedTypeNode instanceof IdentifierTypeNode) {
$resolvedTypes[] = $this->resolveIdentifierTypeNode(
$unionedTypeNode,
$templateTypeMap,
$unionedTypeNode
);
}
}

return new UnionTypeNode($resolvedTypes);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

declare(strict_types=1);

namespace Rector\Generics\Tests\Rector\Class_\GenericsPHPStormMethodAnnotationRector\Fixture;

use Rector\Generics\Tests\Rector\Class_\GenericsPHPStormMethodAnnotationRector\Source\AbstractGenericMaybeArrayRepository;
use Rector\Generics\Tests\Rector\Class_\GenericsPHPStormMethodAnnotationRector\Source\RealObject;

/**
* @template TEntity as RealObject
* @extends AbstractRepository<TEntity>
*/
final class ArrayLikeNullable extends AbstractGenericMaybeArrayRepository
{
}

?>
-----
<?php

declare(strict_types=1);

namespace Rector\Generics\Tests\Rector\Class_\GenericsPHPStormMethodAnnotationRector\Fixture;

use Rector\Generics\Tests\Rector\Class_\GenericsPHPStormMethodAnnotationRector\Source\AbstractGenericMaybeArrayRepository;
use Rector\Generics\Tests\Rector\Class_\GenericsPHPStormMethodAnnotationRector\Source\RealObject;

/**
* @template TEntity as RealObject
* @extends AbstractRepository<TEntity>
* @method \Rector\Generics\Tests\Rector\Class_\GenericsPHPStormMethodAnnotationRector\Source\RealObject[]|null findAllMaybe(string $some, int $type, $unknown)
*/
final class ArrayLikeNullable extends AbstractGenericMaybeArrayRepository
{
}

?>
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

declare(strict_types=1);

namespace Rector\Generics\Tests\Rector\Class_\GenericsPHPStormMethodAnnotationRector\Source;

/**
* @template TEntity as object
*/
abstract class AbstractGenericMaybeArrayRepository
{
/**
* @return TEntity[]|null
*/
public function findAllMaybe(string $some, int $type, $unknown)
{
}
}

0 comments on commit 1c882b5

Please sign in to comment.