Skip to content

Commit 947b026

Browse files
Merge pull request #154 from sascha-egerer/add-type-declarations
[TASK] Use Type declarations and remove redundant docblocks
2 parents b73c577 + df4ccc3 commit 947b026

25 files changed

+119
-100
lines changed

src/Reflection/RepositoryCountByMethodReflection.php

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use PHPStan\Reflection\ClassReflection;
77
use PHPStan\Reflection\FunctionVariant;
88
use PHPStan\Reflection\MethodReflection;
9+
use PHPStan\Reflection\ParametersAcceptor;
910
use PHPStan\TrinaryLogic;
1011
use PHPStan\Type\Generic\TemplateTypeMap;
1112
use PHPStan\Type\IntegerType;
@@ -15,11 +16,9 @@
1516
class RepositoryCountByMethodReflection implements MethodReflection
1617
{
1718

18-
/** @var \PHPStan\Reflection\ClassReflection */
19-
private $classReflection;
19+
private ClassReflection $classReflection;
2020

21-
/** @var string */
22-
private $name;
21+
private string $name;
2322

2423
public function __construct(ClassReflection $classReflection, string $name)
2524
{
@@ -76,7 +75,7 @@ public function getReturnType(): Type
7675
}
7776

7877
/**
79-
* @return \PHPStan\Reflection\ParametersAcceptor[]
78+
* @return ParametersAcceptor[]
8079
*/
8180
public function getVariants(): array
8281
{
@@ -96,7 +95,7 @@ public function getDocComment(): ?string
9695
return null;
9796
}
9897

99-
public function isDeprecated(): \PHPStan\TrinaryLogic
98+
public function isDeprecated(): TrinaryLogic
10099
{
101100
return TrinaryLogic::createNo();
102101
}
@@ -106,22 +105,22 @@ public function getDeprecatedDescription(): ?string
106105
return null;
107106
}
108107

109-
public function isFinal(): \PHPStan\TrinaryLogic
108+
public function isFinal(): TrinaryLogic
110109
{
111110
return TrinaryLogic::createNo();
112111
}
113112

114-
public function isInternal(): \PHPStan\TrinaryLogic
113+
public function isInternal(): TrinaryLogic
115114
{
116115
return TrinaryLogic::createNo();
117116
}
118117

119-
public function getThrowType(): ?\PHPStan\Type\Type
118+
public function getThrowType(): ?Type
120119
{
121120
return null;
122121
}
123122

124-
public function hasSideEffects(): \PHPStan\TrinaryLogic
123+
public function hasSideEffects(): TrinaryLogic
125124
{
126125
return TrinaryLogic::createNo();
127126
}

src/Reflection/RepositoryCountByMethodsClassReflectionExtension.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ class RepositoryCountByMethodsClassReflectionExtension implements MethodsClassRe
1414

1515
use Typo3ClassNamingUtilityTrait;
1616

17-
/** @var ReflectionProvider */
18-
private $reflectionProvider;
17+
private ReflectionProvider $reflectionProvider;
1918

2019
public function __construct(ReflectionProvider $reflectionProvider)
2120
{

src/Reflection/RepositoryCountByParameterReflection.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,9 @@
99
class RepositoryCountByParameterReflection implements ParameterReflection
1010
{
1111

12-
/** @var string */
13-
private $name;
12+
private string $name;
1413

15-
/** @var Type */
16-
private $type;
14+
private Type $type;
1715

1816
public function __construct(string $name, Type $type)
1917
{

src/Reflection/RepositoryFindByMethodReflection.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,14 @@
66
use PHPStan\Reflection\ClassReflection;
77
use PHPStan\Reflection\FunctionVariant;
88
use PHPStan\Reflection\MethodReflection;
9+
use PHPStan\Reflection\ParametersAcceptor;
910
use PHPStan\Reflection\ReflectionProvider;
1011
use PHPStan\TrinaryLogic;
1112
use PHPStan\Type\Generic\GenericObjectType;
1213
use PHPStan\Type\Generic\TemplateTypeMap;
14+
use PHPStan\Type\MixedType;
1315
use PHPStan\Type\ObjectType;
16+
use PHPStan\Type\Type;
1417
use SaschaEgerer\PhpstanTypo3\Helpers\Typo3ClassNamingUtilityTrait;
1518
use TYPO3\CMS\Extbase\Persistence\QueryResultInterface;
1619

@@ -19,14 +22,11 @@ class RepositoryFindByMethodReflection implements MethodReflection
1922

2023
use Typo3ClassNamingUtilityTrait;
2124

22-
/** @var \PHPStan\Reflection\ClassReflection */
23-
private $classReflection;
25+
private ClassReflection $classReflection;
2426

25-
/** @var string */
26-
private $name;
27+
private string $name;
2728

28-
/** @var ReflectionProvider */
29-
private $reflectionProvider;
29+
private ReflectionProvider $reflectionProvider;
3030

3131
public function __construct(ClassReflection $classReflection, string $name, ReflectionProvider $reflectionProvider)
3232
{
@@ -89,7 +89,7 @@ public function getParameters(): array
8989
if ($modelReflection->hasNativeProperty($this->getPropertyName())) {
9090
$type = $modelReflection->getNativeProperty($this->getPropertyName())->getReadableType();
9191
} else {
92-
$type = new \PHPStan\Type\MixedType(\false);
92+
$type = new MixedType(\false);
9393
}
9494

9595
return [
@@ -108,7 +108,7 @@ public function getReturnType(): GenericObjectType
108108
}
109109

110110
/**
111-
* @return \PHPStan\Reflection\ParametersAcceptor[]
111+
* @return ParametersAcceptor[]
112112
*/
113113
public function getVariants(): array
114114
{
@@ -148,7 +148,7 @@ public function isInternal(): TrinaryLogic
148148
return TrinaryLogic::createNo();
149149
}
150150

151-
public function getThrowType(): ?\PHPStan\Type\Type
151+
public function getThrowType(): ?Type
152152
{
153153
return null;
154154
}

src/Reflection/RepositoryFindByParameterReflection.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,9 @@
1111
class RepositoryFindByParameterReflection implements ParameterReflection
1212
{
1313

14-
/** @var string */
15-
private $name;
14+
private string $name;
1615

17-
/** @var Type */
18-
private $type;
16+
private Type $type;
1917

2018
public function __construct(string $name, Type $type)
2119
{

src/Reflection/RepositoryFindMethodsClassReflectionExtension.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ class RepositoryFindMethodsClassReflectionExtension implements MethodsClassRefle
1414

1515
use Typo3ClassNamingUtilityTrait;
1616

17-
/** @var ReflectionProvider $reflectionProvider */
18-
private $reflectionProvider;
17+
private ReflectionProvider $reflectionProvider;
1918

2019
public function __construct(
2120
ReflectionProvider $reflectionProvider

src/Reflection/RepositoryFindOneByMethodReflection.php

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use PHPStan\Reflection\ClassReflection;
77
use PHPStan\Reflection\FunctionVariant;
88
use PHPStan\Reflection\MethodReflection;
9+
use PHPStan\Reflection\ParametersAcceptor;
910
use PHPStan\Reflection\ReflectionProvider;
1011
use PHPStan\TrinaryLogic;
1112
use PHPStan\Type\Generic\TemplateTypeMap;
@@ -19,14 +20,11 @@ class RepositoryFindOneByMethodReflection implements MethodReflection
1920

2021
use Typo3ClassNamingUtilityTrait;
2122

22-
/** @var \PHPStan\Reflection\ClassReflection */
23-
private $classReflection;
23+
private ClassReflection $classReflection;
2424

25-
/** @var string */
26-
private $name;
25+
private string $name;
2726

28-
/** @var ReflectionProvider */
29-
private $reflectionProvider;
27+
private ReflectionProvider $reflectionProvider;
3028

3129
public function __construct(ClassReflection $classReflection, string $name, ReflectionProvider $reflectionProvider)
3230
{
@@ -105,7 +103,7 @@ public function getReturnType(): Type
105103
}
106104

107105
/**
108-
* @return \PHPStan\Reflection\ParametersAcceptor[]
106+
* @return ParametersAcceptor[]
109107
*/
110108
public function getVariants(): array
111109
{
@@ -125,7 +123,7 @@ public function getDocComment(): ?string
125123
return null;
126124
}
127125

128-
public function isDeprecated(): \PHPStan\TrinaryLogic
126+
public function isDeprecated(): TrinaryLogic
129127
{
130128
return TrinaryLogic::createNo();
131129
}
@@ -135,22 +133,22 @@ public function getDeprecatedDescription(): ?string
135133
return null;
136134
}
137135

138-
public function isFinal(): \PHPStan\TrinaryLogic
136+
public function isFinal(): TrinaryLogic
139137
{
140138
return TrinaryLogic::createNo();
141139
}
142140

143-
public function isInternal(): \PHPStan\TrinaryLogic
141+
public function isInternal(): TrinaryLogic
144142
{
145143
return TrinaryLogic::createNo();
146144
}
147145

148-
public function getThrowType(): ?\PHPStan\Type\Type
146+
public function getThrowType(): ?Type
149147
{
150148
return null;
151149
}
152150

153-
public function hasSideEffects(): \PHPStan\TrinaryLogic
151+
public function hasSideEffects(): TrinaryLogic
154152
{
155153
return TrinaryLogic::createNo();
156154
}

src/Rule/ContextAspectValidationRule.php

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,23 @@
33
namespace SaschaEgerer\PhpstanTypo3\Rule;
44

55
use PhpParser\Node;
6+
use PhpParser\Node\Arg;
7+
use PhpParser\Node\Expr\MethodCall;
8+
use PhpParser\Node\Identifier;
9+
use PhpParser\Node\Scalar\String_;
610
use PHPStan\Analyser\Scope;
11+
use PHPStan\Rules\Rule;
712
use PHPStan\Rules\RuleErrorBuilder;
13+
use TYPO3\CMS\Core\Context\Context;
814

915
/**
10-
* @implements \PHPStan\Rules\Rule<\PhpParser\Node\Expr\MethodCall>
16+
* @implements Rule<MethodCall>
1117
*/
12-
class ContextAspectValidationRule implements \PHPStan\Rules\Rule
18+
class ContextAspectValidationRule implements Rule
1319
{
1420

1521
/** @var array<string, string> */
16-
private $contextApiGetAspectMapping;
22+
private array $contextApiGetAspectMapping;
1723

1824
/**
1925
* @param array<string, string> $contextApiGetAspectMapping
@@ -25,15 +31,15 @@ public function __construct(array $contextApiGetAspectMapping)
2531

2632
public function getNodeType(): string
2733
{
28-
return Node\Expr\MethodCall::class;
34+
return MethodCall::class;
2935
}
3036

3137
/**
3238
* @param Node\Expr\MethodCall $node
3339
*/
3440
public function processNode(Node $node, Scope $scope): array
3541
{
36-
if (!$node->name instanceof Node\Identifier) {
42+
if (!$node->name instanceof Identifier) {
3743
return [];
3844
}
3945

@@ -49,13 +55,13 @@ public function processNode(Node $node, Scope $scope): array
4955

5056
$declaringClass = $methodReflection->getDeclaringClass();
5157

52-
if ($declaringClass->getName() !== \TYPO3\CMS\Core\Context\Context::class) {
58+
if ($declaringClass->getName() !== Context::class) {
5359
return [];
5460
}
5561

5662
$argument = $node->getArgs()[0] ?? null;
5763

58-
if (!($argument instanceof Node\Arg) || !($argument->value instanceof Node\Scalar\String_)) {
64+
if (!($argument instanceof Arg) || !($argument->value instanceof String_)) {
5965
return [];
6066
}
6167

src/Rule/RequestAttributeValidationRule.php

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,23 @@
33
namespace SaschaEgerer\PhpstanTypo3\Rule;
44

55
use PhpParser\Node;
6+
use PhpParser\Node\Arg;
7+
use PhpParser\Node\Expr\MethodCall;
8+
use PhpParser\Node\Identifier;
9+
use PhpParser\Node\Scalar\String_;
610
use PHPStan\Analyser\Scope;
11+
use PHPStan\Rules\Rule;
712
use PHPStan\Rules\RuleErrorBuilder;
813
use Psr\Http\Message\ServerRequestInterface;
914

1015
/**
11-
* @implements \PHPStan\Rules\Rule<\PhpParser\Node\Expr\MethodCall>
16+
* @implements Rule<MethodCall>
1217
*/
13-
class RequestAttributeValidationRule implements \PHPStan\Rules\Rule
18+
class RequestAttributeValidationRule implements Rule
1419
{
1520

1621
/** @var array<string, string> */
17-
private $requestGetAttributeMapping;
22+
private array $requestGetAttributeMapping;
1823

1924
/**
2025
* @param array<string, string> $requestGetAttributeMapping
@@ -26,15 +31,15 @@ public function __construct(array $requestGetAttributeMapping)
2631

2732
public function getNodeType(): string
2833
{
29-
return Node\Expr\MethodCall::class;
34+
return MethodCall::class;
3035
}
3136

3237
/**
3338
* @param Node\Expr\MethodCall $node
3439
*/
3540
public function processNode(Node $node, Scope $scope): array
3641
{
37-
if (!$node->name instanceof Node\Identifier) {
42+
if (!$node->name instanceof Identifier) {
3843
return [];
3944
}
4045

@@ -54,7 +59,7 @@ public function processNode(Node $node, Scope $scope): array
5459

5560
$argument = $node->getArgs()[0] ?? null;
5661

57-
if (!($argument instanceof Node\Arg) || !($argument->value instanceof Node\Scalar\String_)) {
62+
if (!($argument instanceof Arg) || !($argument->value instanceof String_)) {
5863
return [];
5964
}
6065

0 commit comments

Comments
 (0)