Skip to content

Commit 6a92bc3

Browse files
committed
Remove type logic from this package
1 parent d6e90a3 commit 6a92bc3

28 files changed

+108
-844
lines changed

composer.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
}
1515
],
1616
"require": {
17-
"php": "^7.4 || ^8.0",
18-
"phpdocumentor/type-resolver": "^1.3",
17+
"php": "^7.2 || ^8.0",
18+
"phpdocumentor/type-resolver": "1.x-dev@dev",
1919
"webmozart/assert": "^1.9.1",
2020
"phpdocumentor/reflection-common": "^2.2",
2121
"ext-filter": "*",

composer.lock

+28-18
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/DocBlock/Tags/Factory/AbstractPHPStanFactory.php

+4
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ public function create(string $tagLine, ?TypeContext $context = null): Tag
5050
$tokens = $this->lexer->tokenize($tagLine);
5151
$ast = $this->parser->parseTag(new TokenIterator($tokens));
5252

53+
if ($context === null) {
54+
$context = new TypeContext('');
55+
}
56+
5357
foreach ($this->factories as $factory) {
5458
if ($factory->supports($ast, $context)) {
5559
return $factory->create($ast, $context);

src/DocBlock/Tags/Factory/MethodFactory.php

+9-8
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use phpDocumentor\Reflection\DocBlock\Tags\Method;
1010
use phpDocumentor\Reflection\DocBlock\Tags\MethodParameter;
1111
use phpDocumentor\Reflection\Type;
12+
use phpDocumentor\Reflection\TypeResolver;
1213
use phpDocumentor\Reflection\Types\Context;
1314
use phpDocumentor\Reflection\Types\Mixed_;
1415
use phpDocumentor\Reflection\Types\Void_;
@@ -25,16 +26,16 @@
2526
*/
2627
final class MethodFactory implements PHPStanFactory
2728
{
28-
private TypeFactory $typeFactory;
2929
private DescriptionFactory $descriptionFactory;
30+
private TypeResolver $typeResolver;
3031

31-
public function __construct(TypeFactory $typeFactory, DescriptionFactory $descriptionFactory)
32+
public function __construct(TypeResolver $typeResolver, DescriptionFactory $descriptionFactory)
3233
{
33-
$this->typeFactory = $typeFactory;
3434
$this->descriptionFactory = $descriptionFactory;
35+
$this->typeResolver = $typeResolver;
3536
}
3637

37-
public function create(PhpDocTagNode $node, ?Context $context): Tag
38+
public function create(PhpDocTagNode $node, Context $context): Tag
3839
{
3940
$tagValue = $node->value;
4041
Assert::isInstanceOf($tagValue, MethodTagValueNode::class);
@@ -50,7 +51,7 @@ public function create(PhpDocTagNode $node, ?Context $context): Tag
5051
function (MethodTagValueParameterNode $param) use ($context) {
5152
return new MethodParameter(
5253
trim($param->parameterName, '$'),
53-
$this->typeFactory->createType($param->type, $context) ?? new Mixed_(),
54+
$this->typeResolver->createType($param->type, $context) ?? new Mixed_(),
5455
$param->isReference,
5556
$param->isVariadic,
5657
(string) $param->defaultValue
@@ -61,13 +62,13 @@ function (MethodTagValueParameterNode $param) use ($context) {
6162
);
6263
}
6364

64-
public function supports(PhpDocTagNode $node, ?Context $context): bool
65+
public function supports(PhpDocTagNode $node, Context $context): bool
6566
{
6667
return $node->value instanceof MethodTagValueNode;
6768
}
6869

69-
private function createReturnType(MethodTagValueNode $tagValue, ?Context $context): Type
70+
private function createReturnType(MethodTagValueNode $tagValue, Context $context): Type
7071
{
71-
return $this->typeFactory->createType($tagValue->returnType, $context) ?? new Void_();
72+
return $this->typeResolver->createType($tagValue->returnType, $context) ?? new Void_();
7273
}
7374
}

src/DocBlock/Tags/Factory/PHPStanFactory.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
interface PHPStanFactory
1212
{
13-
public function create(PhpDocTagNode $node, ?Context $context): Tag;
13+
public function create(PhpDocTagNode $node, Context $context): Tag;
1414

15-
public function supports(PhpDocTagNode $node, ?Context $context): bool;
15+
public function supports(PhpDocTagNode $node, Context $context): bool;
1616
}

src/DocBlock/Tags/Factory/ParamFactory.php

+7-6
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use phpDocumentor\Reflection\DocBlock\DescriptionFactory;
88
use phpDocumentor\Reflection\DocBlock\Tag;
99
use phpDocumentor\Reflection\DocBlock\Tags\Param;
10+
use phpDocumentor\Reflection\TypeResolver;
1011
use phpDocumentor\Reflection\Types\Context;
1112
use PHPStan\PhpDocParser\Ast\PhpDoc\ParamTagValueNode;
1213
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagNode;
@@ -19,30 +20,30 @@
1920
*/
2021
final class ParamFactory implements PHPStanFactory
2122
{
22-
private TypeFactory $typeFactory;
2323
private DescriptionFactory $descriptionFactory;
24+
private TypeResolver $typeResolver;
2425

25-
public function __construct(TypeFactory $typeFactory, DescriptionFactory $descriptionFactory)
26+
public function __construct(TypeResolver $typeResolver, DescriptionFactory $descriptionFactory)
2627
{
27-
$this->typeFactory = $typeFactory;
2828
$this->descriptionFactory = $descriptionFactory;
29+
$this->typeResolver = $typeResolver;
2930
}
3031

31-
public function create(PhpDocTagNode $node, ?Context $context): Tag
32+
public function create(PhpDocTagNode $node, Context $context): Tag
3233
{
3334
$tagValue = $node->value;
3435
Assert::isInstanceOf($tagValue, ParamTagValueNode::class);
3536

3637
return new Param(
3738
trim($tagValue->parameterName, '$'),
38-
$this->typeFactory->createType($tagValue->type, $context),
39+
$this->typeResolver->createType($tagValue->type, $context),
3940
$tagValue->isVariadic,
4041
$this->descriptionFactory->create($tagValue->description, $context),
4142
$tagValue->isReference
4243
);
4344
}
4445

45-
public function supports(PhpDocTagNode $node, ?Context $context): bool
46+
public function supports(PhpDocTagNode $node, Context $context): bool
4647
{
4748
return $node->value instanceof ParamTagValueNode;
4849
}

src/DocBlock/Tags/Factory/PropertyFactory.php

+7-6
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use phpDocumentor\Reflection\DocBlock\DescriptionFactory;
88
use phpDocumentor\Reflection\DocBlock\Tag;
99
use phpDocumentor\Reflection\DocBlock\Tags\Property;
10+
use phpDocumentor\Reflection\TypeResolver;
1011
use phpDocumentor\Reflection\Types\Context;
1112
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagNode;
1213
use PHPStan\PhpDocParser\Ast\PhpDoc\PropertyTagValueNode;
@@ -19,28 +20,28 @@
1920
*/
2021
final class PropertyFactory implements PHPStanFactory
2122
{
22-
private TypeFactory $typeFactory;
2323
private DescriptionFactory $descriptionFactory;
24+
private TypeResolver $typeResolver;
2425

25-
public function __construct(TypeFactory $typeFactory, DescriptionFactory $descriptionFactory)
26+
public function __construct(TypeResolver $typeResolver, DescriptionFactory $descriptionFactory)
2627
{
27-
$this->typeFactory = $typeFactory;
2828
$this->descriptionFactory = $descriptionFactory;
29+
$this->typeResolver = $typeResolver;
2930
}
3031

31-
public function create(PhpDocTagNode $node, ?Context $context): Tag
32+
public function create(PhpDocTagNode $node, Context $context): Tag
3233
{
3334
$tagValue = $node->value;
3435
Assert::isInstanceOf($tagValue, PropertyTagValueNode::class);
3536

3637
return new Property(
3738
trim($tagValue->propertyName, '$'),
38-
$this->typeFactory->createType($tagValue->type, $context),
39+
$this->typeResolver->createType($tagValue->type, $context),
3940
$this->descriptionFactory->create($tagValue->description, $context)
4041
);
4142
}
4243

43-
public function supports(PhpDocTagNode $node, ?Context $context): bool
44+
public function supports(PhpDocTagNode $node, Context $context): bool
4445
{
4546
return $node->value instanceof PropertyTagValueNode && $node->name === '@property';
4647
}

src/DocBlock/Tags/Factory/PropertyReadFactory.php

+7-6
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use phpDocumentor\Reflection\DocBlock\DescriptionFactory;
88
use phpDocumentor\Reflection\DocBlock\Tag;
99
use phpDocumentor\Reflection\DocBlock\Tags\PropertyRead;
10+
use phpDocumentor\Reflection\TypeResolver;
1011
use phpDocumentor\Reflection\Types\Context;
1112
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagNode;
1213
use PHPStan\PhpDocParser\Ast\PhpDoc\PropertyTagValueNode;
@@ -19,28 +20,28 @@
1920
*/
2021
final class PropertyReadFactory implements PHPStanFactory
2122
{
22-
private TypeFactory $typeFactory;
2323
private DescriptionFactory $descriptionFactory;
24+
private TypeResolver $typeResolver;
2425

25-
public function __construct(TypeFactory $typeFactory, DescriptionFactory $descriptionFactory)
26+
public function __construct(TypeResolver $typeResolver, DescriptionFactory $descriptionFactory)
2627
{
27-
$this->typeFactory = $typeFactory;
28+
$this->typeResolver = $typeResolver;
2829
$this->descriptionFactory = $descriptionFactory;
2930
}
3031

31-
public function create(PhpDocTagNode $node, ?Context $context): Tag
32+
public function create(PhpDocTagNode $node, Context $context): Tag
3233
{
3334
$tagValue = $node->value;
3435
Assert::isInstanceOf($tagValue, PropertyTagValueNode::class);
3536

3637
return new PropertyRead(
3738
trim($tagValue->propertyName, '$'),
38-
$this->typeFactory->createType($tagValue->type, $context),
39+
$this->typeResolver->createType($tagValue->type, $context),
3940
$this->descriptionFactory->create($tagValue->description, $context)
4041
);
4142
}
4243

43-
public function supports(PhpDocTagNode $node, ?Context $context): bool
44+
public function supports(PhpDocTagNode $node, Context $context): bool
4445
{
4546
return $node->value instanceof PropertyTagValueNode && $node->name === '@property-read';
4647
}

src/DocBlock/Tags/Factory/PropertyWriteFactory.php

+7-6
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use phpDocumentor\Reflection\DocBlock\DescriptionFactory;
88
use phpDocumentor\Reflection\DocBlock\Tag;
99
use phpDocumentor\Reflection\DocBlock\Tags\PropertyWrite;
10+
use phpDocumentor\Reflection\TypeResolver;
1011
use phpDocumentor\Reflection\Types\Context;
1112
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagNode;
1213
use PHPStan\PhpDocParser\Ast\PhpDoc\PropertyTagValueNode;
@@ -19,28 +20,28 @@
1920
*/
2021
final class PropertyWriteFactory implements PHPStanFactory
2122
{
22-
private TypeFactory $typeFactory;
2323
private DescriptionFactory $descriptionFactory;
24+
private TypeResolver $typeResolver;
2425

25-
public function __construct(TypeFactory $typeFactory, DescriptionFactory $descriptionFactory)
26+
public function __construct(TypeResolver $typeResolver, DescriptionFactory $descriptionFactory)
2627
{
27-
$this->typeFactory = $typeFactory;
2828
$this->descriptionFactory = $descriptionFactory;
29+
$this->typeResolver = $typeResolver;
2930
}
3031

31-
public function create(PhpDocTagNode $node, ?Context $context): Tag
32+
public function create(PhpDocTagNode $node, Context $context): Tag
3233
{
3334
$tagValue = $node->value;
3435
Assert::isInstanceOf($tagValue, PropertyTagValueNode::class);
3536

3637
return new PropertyWrite(
3738
trim($tagValue->propertyName, '$'),
38-
$this->typeFactory->createType($tagValue->type, $context),
39+
$this->typeResolver->createType($tagValue->type, $context),
3940
$this->descriptionFactory->create($tagValue->description, $context)
4041
);
4142
}
4243

43-
public function supports(PhpDocTagNode $node, ?Context $context): bool
44+
public function supports(PhpDocTagNode $node, Context $context): bool
4445
{
4546
return $node->value instanceof PropertyTagValueNode && $node->name === '@property-write';
4647
}

0 commit comments

Comments
 (0)