Skip to content

Commit 6dd2b27

Browse files
committed
Fixed compatibility with PHPStan 0.12
1 parent 8888fd4 commit 6dd2b27

14 files changed

+94
-29
lines changed

build.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@
8888
>
8989
<arg value="analyse"/>
9090
<arg value="-l"/>
91-
<arg value="7"/>
91+
<arg value="8"/>
9292
<arg value="-c"/>
9393
<arg path="phpstan.neon"/>
9494
<arg path="src"/>

phpcs.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@
2323
@dataProvider,
2424
@requires
2525
"/>
26+
<property name="enableObjectTypeHint" value="false"/>
2627
</properties>
28+
<exclude name="SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingTraversableParameterTypeHintSpecification"/>
29+
<exclude name="SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingTraversableReturnTypeHintSpecification"/>
2730
</rule>
2831
<rule ref="SlevomatCodingStandard.ControlStructures.AssignmentInCondition"/>
2932
<rule ref="SlevomatCodingStandard.ControlStructures.DisallowEqualOperators"/>

phpstan.neon

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,8 @@ includes:
99

1010
parameters:
1111
excludes_analyse:
12-
- %rootDir%/../../../tests/*/data/*
13-
- %rootDir%/../../../tests/NetteObjectChild.php
12+
- tests/*/data/*
13+
- tests/NetteObjectChild.php
1414

1515
ignoreErrors:
16-
- '~^Parameter \#1 \$node \(.*\) of method .*Rule::processNode\(\) should be contravariant with parameter \$node \(PhpParser\\Node\) of method PHPStan\\Rules\\Rule::processNode\(\)$~'
1716
- '~^Variable property access on PhpParser\\Node\.$~'

src/Reflection/Nette/HtmlMethodReflection.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ public function getVariants(): array
5050
{
5151
return [
5252
new FunctionVariant(
53+
TemplateTypeMap::createEmpty(),
5354
TemplateTypeMap::createEmpty(),
5455
[],
5556
true,
@@ -93,9 +94,19 @@ public function isInternal(): TrinaryLogic
9394
return TrinaryLogic::createNo();
9495
}
9596

96-
public function getThrowType(): ?Type
97+
public function getThrowType(): Type
9798
{
9899
return new VoidType();
99100
}
100101

102+
public function getDocComment(): ?string
103+
{
104+
return null;
105+
}
106+
107+
public function hasSideEffects(): \PHPStan\TrinaryLogic
108+
{
109+
return TrinaryLogic::createYes();
110+
}
111+
101112
}

src/Reflection/Nette/HtmlPropertyReflection.php

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,13 @@ class HtmlPropertyReflection implements PropertyReflection
1414
/** @var \PHPStan\Reflection\ClassReflection */
1515
private $declaringClass;
1616

17+
/** @var Type */
18+
private $type;
19+
1720
public function __construct(ClassReflection $declaringClass)
1821
{
1922
$this->declaringClass = $declaringClass;
23+
$this->type = new MixedType();
2024
}
2125

2226
public function getDeclaringClass(): ClassReflection
@@ -39,11 +43,6 @@ public function isPublic(): bool
3943
return true;
4044
}
4145

42-
public function getType(): Type
43-
{
44-
return new MixedType();
45-
}
46-
4746
public function isReadable(): bool
4847
{
4948
return true;
@@ -69,4 +68,24 @@ public function isInternal(): TrinaryLogic
6968
return TrinaryLogic::createNo();
7069
}
7170

71+
public function getDocComment(): ?string
72+
{
73+
return null;
74+
}
75+
76+
public function getReadableType(): \PHPStan\Type\Type
77+
{
78+
return $this->type;
79+
}
80+
81+
public function getWritableType(): \PHPStan\Type\Type
82+
{
83+
return $this->type;
84+
}
85+
86+
public function canChangeTypeAfterAssignment(): bool
87+
{
88+
return true;
89+
}
90+
7291
}

src/Reflection/Nette/NetteObjectClassReflectionExtension.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public function getMethod(ClassReflection $classReflection, string $methodName):
6666
}
6767

6868
/**
69-
* @param \ReflectionClass $class
69+
* @param \ReflectionClass<object> $class
7070
* @return string[]
7171
*/
7272
private function getTraitNames(\ReflectionClass $class): array
@@ -80,6 +80,10 @@ private function getTraitNames(\ReflectionClass $class): array
8080
return $traitNames;
8181
}
8282

83+
/**
84+
* @param \ReflectionClass<object> $class
85+
* @return bool
86+
*/
8387
private function inheritsFromNetteObject(\ReflectionClass $class): bool
8488
{
8589
$class = $class->getParentClass();

src/Reflection/Nette/NetteObjectEventListenerMethodReflection.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ public function getVariants(): array
5353
{
5454
return [
5555
new FunctionVariant(
56+
TemplateTypeMap::createEmpty(),
5657
TemplateTypeMap::createEmpty(),
5758
[],
5859
true,
@@ -96,4 +97,14 @@ public function getThrowType(): ?Type
9697
return null;
9798
}
9899

100+
public function getDocComment(): ?string
101+
{
102+
return null;
103+
}
104+
105+
public function hasSideEffects(): \PHPStan\TrinaryLogic
106+
{
107+
return TrinaryLogic::createYes();
108+
}
109+
99110
}

src/Reflection/Nette/NetteObjectPropertyReflection.php

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,6 @@ public function isPublic(): bool
4242
return true;
4343
}
4444

45-
public function getType(): Type
46-
{
47-
return $this->type;
48-
}
49-
5045
public function isReadable(): bool
5146
{
5247
return true;
@@ -72,4 +67,24 @@ public function isInternal(): TrinaryLogic
7267
return TrinaryLogic::createNo();
7368
}
7469

70+
public function getDocComment(): ?string
71+
{
72+
return null;
73+
}
74+
75+
public function getReadableType(): \PHPStan\Type\Type
76+
{
77+
return $this->type;
78+
}
79+
80+
public function getWritableType(): \PHPStan\Type\Type
81+
{
82+
return $this->type;
83+
}
84+
85+
public function canChangeTypeAfterAssignment(): bool
86+
{
87+
return true;
88+
}
89+
7590
}

src/Rule/Nette/DoNotExtendNetteObjectRule.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
use PHPStan\Analyser\Scope;
88
use PHPStan\Broker\Broker;
99

10+
/**
11+
* @implements \PHPStan\Rules\Rule<Class_>
12+
*/
1013
class DoNotExtendNetteObjectRule implements \PHPStan\Rules\Rule
1114
{
1215

@@ -23,11 +26,6 @@ public function getNodeType(): string
2326
return Class_::class;
2427
}
2528

26-
/**
27-
* @param \PhpParser\Node\Stmt\Class_ $node
28-
* @param \PHPStan\Analyser\Scope $scope
29-
* @return string[] errors
30-
*/
3129
public function processNode(Node $node, Scope $scope): array
3230
{
3331
if (!isset($node->namespacedName)) {

src/Rule/Nette/RethrowExceptionRule.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
use PHPStan\Type\ObjectType;
1010
use PHPStan\Type\TypeCombinator;
1111

12+
/**
13+
* @implements \PHPStan\Rules\Rule<TryCatch>
14+
*/
1215
class RethrowExceptionRule implements \PHPStan\Rules\Rule
1316
{
1417

@@ -28,11 +31,6 @@ public function getNodeType(): string
2831
return TryCatch::class;
2932
}
3033

31-
/**
32-
* @param \PhpParser\Node\Stmt\TryCatch $node
33-
* @param \PHPStan\Analyser\Scope $scope
34-
* @return string[] errors
35-
*/
3634
public function processNode(Node $node, Scope $scope): array
3735
{
3836
$hasGeneralCatch = false;

0 commit comments

Comments
 (0)