Skip to content

Commit 1f95f3b

Browse files
committed
Codestyle fixes and static analysis
1 parent 6a92bc3 commit 1f95f3b

File tree

11 files changed

+76
-19
lines changed

11 files changed

+76
-19
lines changed

src/DocBlock/StandardTagFactory.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ public function registerTagHandler(string $tagName, $handler): void
177177
}
178178

179179
if (is_object($handler)) {
180-
Assert::implementsInterface($handler, Factory::class);
180+
Assert::isInstanceOf($handler, Factory::class);
181181
$this->tagHandlerMappings[$tagName] = $handler;
182182

183183
return;

src/DocBlock/Tags/Factory/MethodFactory.php

+9-2
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,10 @@ public function create(PhpDocTagNode $node, Context $context): Tag
5151
function (MethodTagValueParameterNode $param) use ($context) {
5252
return new MethodParameter(
5353
trim($param->parameterName, '$'),
54-
$this->typeResolver->createType($param->type, $context) ?? new Mixed_(),
54+
$param->type === null ? new Mixed_() : $this->typeResolver->createType(
55+
$param->type,
56+
$context
57+
),
5558
$param->isReference,
5659
$param->isVariadic,
5760
(string) $param->defaultValue
@@ -69,6 +72,10 @@ public function supports(PhpDocTagNode $node, Context $context): bool
6972

7073
private function createReturnType(MethodTagValueNode $tagValue, Context $context): Type
7174
{
72-
return $this->typeResolver->createType($tagValue->returnType, $context) ?? new Void_();
75+
if ($tagValue->returnType === null) {
76+
return new Void_();
77+
}
78+
79+
return $this->typeResolver->createType($tagValue->returnType, $context);
7380
}
7481
}

src/DocBlock/Tags/Method.php

+7-1
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ final class Method extends BaseTag implements Factory\StaticMethod
6363

6464
/**
6565
* @param array<int, array<string, Type|string>> $arguments
66+
* @param MethodParameter[] $parameters
6667
* @phpstan-param array<int, array{name: string, type: Type}|string> $arguments
6768
*/
6869
public function __construct(
@@ -90,6 +91,10 @@ public function __construct(
9091
$this->parameters = $parameters ?? $this->fromLegacyArguments($arguments);
9192
}
9293

94+
/**
95+
* @deprecated Create using static factory is deprecated,
96+
* this method should not be called directly by library consumers
97+
*/
9398
public static function create(
9499
string $body,
95100
?TypeResolver $typeResolver = null,
@@ -261,7 +266,7 @@ public function __toString(): string
261266
{
262267
$arguments = [];
263268
foreach ($this->parameters as $parameter) {
264-
$arguments[] = ($parameter->getType() ?? new Mixed_()) . ' ' .
269+
$arguments[] = $parameter->getType() . ' ' .
265270
($parameter->isReference() ? '&' : '') .
266271
($parameter->isVariadic() ? '...' : '') .
267272
'$' . $parameter->getName();
@@ -334,6 +339,7 @@ private static function stripRestArg(string $argument): string
334339

335340
/**
336341
* @param array{name: string, type: Type} $arguments
342+
* @phpstan-param array<int, array{name: string, type: Type}> $arguments
337343
*
338344
* @return MethodParameter[]
339345
*/

src/DocBlock/Tags/Param.php

+7-2
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,20 @@ public function __construct(
6161
}
6262

6363
/**
64-
* @deprecated Create using static factory is deprecated, this method should not be called directly by library consumers
64+
* @deprecated Create using static factory is deprecated,
65+
* this method should not be called directly by library consumers
6566
*/
6667
public static function create(
6768
string $body,
6869
?TypeResolver $typeResolver = null,
6970
?DescriptionFactory $descriptionFactory = null,
7071
?TypeContext $context = null
7172
): self {
72-
trigger_error('Create using static factory is deprecated, this method should not be called directly by library consumers', E_USER_DEPRECATED);
73+
trigger_error(
74+
'Create using static factory is deprecated, this method should not be called directly
75+
by library consumers',
76+
E_USER_DEPRECATED
77+
);
7378
Assert::stringNotEmpty($body);
7479
Assert::notNull($typeResolver);
7580
Assert::notNull($descriptionFactory);

src/DocBlock/Tags/Property.php

+9-1
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,21 @@ public function __construct(?string $variableName, ?Type $type = null, ?Descript
4949
$this->description = $description;
5050
}
5151

52+
/**
53+
* @deprecated Create using static factory is deprecated,
54+
* this method should not be called directly by library consumers
55+
*/
5256
public static function create(
5357
string $body,
5458
?TypeResolver $typeResolver = null,
5559
?DescriptionFactory $descriptionFactory = null,
5660
?TypeContext $context = null
5761
): self {
58-
trigger_error('Create using static factory is deprecated, this method should not be called directly by library consumers', E_USER_DEPRECATED);
62+
trigger_error(
63+
'Create using static factory is deprecated, this method should not be called directly
64+
by library consumers',
65+
E_USER_DEPRECATED
66+
);
5967
Assert::stringNotEmpty($body);
6068
Assert::notNull($typeResolver);
6169
Assert::notNull($descriptionFactory);

src/DocBlock/Tags/PropertyRead.php

+9-1
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,21 @@ public function __construct(?string $variableName, ?Type $type = null, ?Descript
4949
$this->description = $description;
5050
}
5151

52+
/**
53+
* @deprecated Create using static factory is deprecated,
54+
* this method should not be called directly by library consumers
55+
*/
5256
public static function create(
5357
string $body,
5458
?TypeResolver $typeResolver = null,
5559
?DescriptionFactory $descriptionFactory = null,
5660
?TypeContext $context = null
5761
): self {
58-
trigger_error('Create using static factory is deprecated, this method should not be called directly by library consumers', E_USER_DEPRECATED);
62+
trigger_error(
63+
'Create using static factory is deprecated, this method should not be called directly
64+
by library consumers',
65+
E_USER_DEPRECATED
66+
);
5967
Assert::stringNotEmpty($body);
6068
Assert::notNull($typeResolver);
6169
Assert::notNull($descriptionFactory);

src/DocBlock/Tags/PropertyWrite.php

+9-1
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,21 @@ public function __construct(?string $variableName, ?Type $type = null, ?Descript
4949
$this->description = $description;
5050
}
5151

52+
/**
53+
* @deprecated Create using static factory is deprecated,
54+
* this method should not be called directly by library consumers
55+
*/
5256
public static function create(
5357
string $body,
5458
?TypeResolver $typeResolver = null,
5559
?DescriptionFactory $descriptionFactory = null,
5660
?TypeContext $context = null
5761
): self {
58-
trigger_error('Create using static factory is deprecated, this method should not be called directly by library consumers', E_USER_DEPRECATED);
62+
trigger_error(
63+
'Create using static factory is deprecated, this method should not be called directly
64+
by library consumers',
65+
E_USER_DEPRECATED
66+
);
5967
Assert::stringNotEmpty($body);
6068
Assert::notNull($typeResolver);
6169
Assert::notNull($descriptionFactory);

src/DocBlock/Tags/Return_.php

+9-1
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,21 @@ public function __construct(Type $type, ?Description $description = null)
3636
$this->description = $description;
3737
}
3838

39+
/**
40+
* @deprecated Create using static factory is deprecated,
41+
* this method should not be called directly by library consumers
42+
*/
3943
public static function create(
4044
string $body,
4145
?TypeResolver $typeResolver = null,
4246
?DescriptionFactory $descriptionFactory = null,
4347
?TypeContext $context = null
4448
): self {
45-
trigger_error('Create using static factory is deprecated, this method should not be called directly by library consumers', E_USER_DEPRECATED);
49+
trigger_error(
50+
'Create using static factory is deprecated, this method should not be called directly
51+
by library consumers',
52+
E_USER_DEPRECATED
53+
);
4654
Assert::notNull($typeResolver);
4755
Assert::notNull($descriptionFactory);
4856

src/DocBlock/Tags/Var_.php

+9-1
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,21 @@ public function __construct(?string $variableName, ?Type $type = null, ?Descript
4949
$this->description = $description;
5050
}
5151

52+
/**
53+
* @deprecated Create using static factory is deprecated,
54+
* this method should not be called directly by library consumers
55+
*/
5256
public static function create(
5357
string $body,
5458
?TypeResolver $typeResolver = null,
5559
?DescriptionFactory $descriptionFactory = null,
5660
?TypeContext $context = null
5761
): self {
58-
trigger_error('Create using static factory is deprecated, this method should not be called directly by library consumers', E_USER_DEPRECATED);
62+
trigger_error(
63+
'Create using static factory is deprecated, this method should not be called directly
64+
by library consumers',
65+
E_USER_DEPRECATED
66+
);
5967
Assert::stringNotEmpty($body);
6068
Assert::notNull($typeResolver);
6169
Assert::notNull($descriptionFactory);

src/DocBlockFactory.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
use phpDocumentor\Reflection\DocBlock\Tags\Factory\PropertyReadFactory;
2727
use phpDocumentor\Reflection\DocBlock\Tags\Factory\PropertyWriteFactory;
2828
use phpDocumentor\Reflection\DocBlock\Tags\Factory\ReturnFactory;
29-
use phpDocumentor\Reflection\DocBlock\Tags\Factory\TypeFactory;
3029
use phpDocumentor\Reflection\DocBlock\Tags\Factory\VarFactory;
3130
use Webmozart\Assert\Assert;
3231

@@ -64,7 +63,7 @@ public function __construct(DescriptionFactory $descriptionFactory, TagFactory $
6463
*
6564
* @param array<string, class-string<Tag>|Factory> $additionalTags
6665
*/
67-
public static function createInstance(array $additionalTags = []): self
66+
public static function createInstance(array $additionalTags = []): DocBlockFactoryInterface
6867
{
6968
$fqsenResolver = new FqsenResolver();
7069
$tagFactory = new StandardTagFactory($fqsenResolver);

tests/unit/DocBlock/Tags/Factory/MethodFactoryTest.php

+6-6
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public function tagProvider(): array
7676
new Method(
7777
'myMethod',
7878
[],
79-
new Mixed_(),
79+
new Void_(),
8080
false,
8181
new Description(''),
8282
false,
@@ -88,7 +88,7 @@ public function tagProvider(): array
8888
new Method(
8989
'myMethod',
9090
[],
91-
new Mixed_(),
91+
new Void_(),
9292
false,
9393
new Description(''),
9494
false,
@@ -100,7 +100,7 @@ public function tagProvider(): array
100100
new Method(
101101
'myMethod',
102102
[],
103-
new Mixed_(),
103+
new Void_(),
104104
false,
105105
new Description(''),
106106
false,
@@ -112,7 +112,7 @@ public function tagProvider(): array
112112
new Method(
113113
'myMethod',
114114
[],
115-
new Mixed_(),
115+
new Void_(),
116116
false,
117117
new Description(''),
118118
false,
@@ -124,7 +124,7 @@ public function tagProvider(): array
124124
new Method(
125125
'myMethod',
126126
[],
127-
new Mixed_(),
127+
new Void_(),
128128
false,
129129
new Description(''),
130130
false,
@@ -136,7 +136,7 @@ public function tagProvider(): array
136136
new Method(
137137
'myMethod',
138138
[],
139-
new Mixed_(),
139+
new Void_(),
140140
false,
141141
new Description(''),
142142
false,

0 commit comments

Comments
 (0)