Skip to content

Commit 99f4195

Browse files
committed
Fixed issue with universal object crate classes (removed obsolete code)
1 parent c21c37d commit 99f4195

File tree

3 files changed

+45
-4
lines changed

3 files changed

+45
-4
lines changed

Diff for: src/Reflection/Php/UniversalObjectCratesClassReflectionExtension.php

-4
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,6 @@ public function hasProperty(ClassReflection $classReflection, string $propertyNa
3939
return $this->broker->hasClass($class);
4040
}));
4141
}
42-
if ($classReflection->hasNativeProperty($propertyName)) {
43-
return false;
44-
}
45-
4642
foreach ($this->filteredClasses as $className) {
4743
if (
4844
$classReflection->getName() === $className

Diff for: tests/PHPStan/Analyser/AnalyserIntegrationTest.php

+8
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,14 @@ public function testAnonymousClassesWithComments()
9191
}
9292
}
9393

94+
public function testUniversalObjectCrateIssue()
95+
{
96+
$errors = $this->runAnalyse(__DIR__ . '/data/universal-object-crate.php');
97+
$this->assertCount(1, $errors);
98+
$this->assertSame('Parameter #1 $i of method UniversalObjectCrate\Foo::doBaz() expects int, string given.', $errors[0]->getMessage());
99+
$this->assertSame(19, $errors[0]->getLine());
100+
}
101+
94102
/**
95103
* @param string $file
96104
* @return \PHPStan\Analyser\Error[]
+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
namespace UniversalObjectCrate;
4+
5+
class Foo extends \stdClass
6+
{
7+
8+
/** @var string */
9+
private $name;
10+
11+
public function __construct(string $name)
12+
{
13+
$this->name = $name;
14+
}
15+
16+
public function doFoo()
17+
{
18+
$this->doBar($this->name);
19+
$this->doBaz($this->name); // reported - string passed to int
20+
}
21+
22+
public function doBar(string $name)
23+
{
24+
25+
}
26+
27+
public function doBaz(int $i)
28+
{
29+
30+
}
31+
32+
}
33+
34+
function () {
35+
$foo = new Foo('foo');
36+
$foo->doBaz($foo->name); // not reported, is mixed here
37+
};

0 commit comments

Comments
 (0)