Skip to content

Commit ed5a66f

Browse files
committed
Latest round of compatibility fixes with PHPStan 0.9
1 parent 31139ab commit ed5a66f

File tree

2 files changed

+15
-19
lines changed

2 files changed

+15
-19
lines changed

src/Reflection/Nette/NetteObjectClassReflectionExtension.php

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,6 @@ public function hasProperty(ClassReflection $classReflection, string $propertyNa
1717
return false;
1818
}
1919

20-
if (substr($propertyName, 0, 2) === 'on' && strlen($propertyName) > 2) {
21-
return false; // prevent infinite loop from hasMethod
22-
}
23-
2420
$getterMethod = $this->getMethodByProperty($classReflection, $propertyName);
2521
if ($getterMethod === null) {
2622
return false;
@@ -40,11 +36,11 @@ public function hasProperty(ClassReflection $classReflection, string $propertyNa
4036
private function getMethodByProperty(ClassReflection $classReflection, string $propertyName)
4137
{
4238
$getterMethodName = sprintf('get%s', ucfirst($propertyName));
43-
if (!$classReflection->hasMethod($getterMethodName)) {
39+
if (!$classReflection->hasNativeMethod($getterMethodName)) {
4440
return null;
4541
}
4642

47-
return $classReflection->getMethod($getterMethodName);
43+
return $classReflection->getNativeMethod($getterMethodName);
4844
}
4945

5046
public function getProperty(ClassReflection $classReflection, string $propertyName): PropertyReflection
@@ -65,7 +61,7 @@ public function hasMethod(ClassReflection $classReflection, string $methodName):
6561
return false;
6662
}
6763

68-
return $classReflection->hasProperty($methodName) && $classReflection->getProperty($methodName)->isPublic();
64+
return $classReflection->hasNativeProperty($methodName) && $classReflection->getNativeProperty($methodName)->isPublic();
6965
}
7066

7167
public function getMethod(ClassReflection $classReflection, string $methodName): MethodReflection

tests/Reflection/Nette/NetteObjectClassReflectionExtensionTest.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
namespace PHPStan\Reflection\Nette;
44

55
use PHPStan\Reflection\ClassReflection;
6-
use PHPStan\Reflection\MethodReflection;
7-
use PHPStan\Reflection\PropertyReflection;
6+
use PHPStan\Reflection\Php\PhpMethodReflection;
7+
use PHPStan\Reflection\Php\PhpPropertyReflection;
88

99
class NetteObjectClassReflectionExtensionTest extends \PHPUnit\Framework\TestCase
1010
{
@@ -107,30 +107,30 @@ private function mockClassReflection(\ReflectionClass $class): ClassReflection
107107
{
108108
$classReflection = $this->createMock(ClassReflection::class);
109109
$classReflection->method('getNativeReflection')->will($this->returnValue($class));
110-
$classReflection->method('hasProperty')->will(
110+
$classReflection->method('hasNativeProperty')->will(
111111
$this->returnCallback(
112112
function (string $property) use ($class): bool {
113113
return $class->hasProperty($property);
114114
}
115115
)
116116
);
117-
$classReflection->method('getProperty')->will(
117+
$classReflection->method('getNativeProperty')->will(
118118
$this->returnCallback(
119-
function (string $property) use ($class): PropertyReflection {
119+
function (string $property) use ($class): PhpPropertyReflection {
120120
return $this->mockPropertyReflection($class->getProperty($property));
121121
}
122122
)
123123
);
124-
$classReflection->method('hasMethod')->will(
124+
$classReflection->method('hasNativeMethod')->will(
125125
$this->returnCallback(
126126
function (string $method) use ($class): bool {
127127
return $class->hasMethod($method);
128128
}
129129
)
130130
);
131-
$classReflection->method('getMethod')->will(
131+
$classReflection->method('getNativeMethod')->will(
132132
$this->returnCallback(
133-
function (string $method) use ($class): MethodReflection {
133+
function (string $method) use ($class): PhpMethodReflection {
134134
return $this->mockMethodReflection($class->getMethod($method));
135135
}
136136
)
@@ -139,17 +139,17 @@ function (string $method) use ($class): MethodReflection {
139139
return $classReflection;
140140
}
141141

142-
private function mockMethodReflection(\ReflectionMethod $method): MethodReflection
142+
private function mockMethodReflection(\ReflectionMethod $method): PhpMethodReflection
143143
{
144-
$methodReflection = $this->createMock(MethodReflection::class);
144+
$methodReflection = $this->createMock(PhpMethodReflection::class);
145145
$methodReflection->method('isPublic')->will($this->returnValue($method->isPublic()));
146146
$methodReflection->method('isStatic')->will($this->returnValue($method->isStatic()));
147147
return $methodReflection;
148148
}
149149

150-
private function mockPropertyReflection(\ReflectionProperty $property): PropertyReflection
150+
private function mockPropertyReflection(\ReflectionProperty $property): PhpPropertyReflection
151151
{
152-
$propertyReflection = $this->createMock(PropertyReflection::class);
152+
$propertyReflection = $this->createMock(PhpPropertyReflection::class);
153153
$propertyReflection->method('isPublic')->will($this->returnValue($property->isPublic()));
154154
return $propertyReflection;
155155
}

0 commit comments

Comments
 (0)