Skip to content

Commit

Permalink
Fix unknown properties for class extending DateInterval|DatePeriod an…
Browse files Browse the repository at this point in the history
…d loaded with runtime reflection
  • Loading branch information
ondrejmirtes committed Jun 14, 2020
1 parent d8a0735 commit b21f537
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,17 @@ public function hasClass(string $className): bool
}
}

return $this->reflectionProvider->hasClass($className);
$has = $this->reflectionProvider->hasClass($className);
if (!$has) {
return false;
}

$classReflection = $this->reflectionProvider->getClass($className);
if ($classReflection->isSubclassOf(\DateInterval::class) || $classReflection->isSubclassOf(\DatePeriod::class)) {
return false;
}

return true;
}

public function getClass(string $className): ClassReflection
Expand Down
6 changes: 6 additions & 0 deletions tests/PHPStan/Analyser/AnalyserIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,12 @@ public function testBug3415Two(): void
$this->assertCount(0, $errors);
}

public function testBug3468(): void
{
$errors = $this->runAnalyse(__DIR__ . '/data/bug-3468.php');
$this->assertCount(0, $errors);
}

/**
* @param string $file
* @return \PHPStan\Analyser\Error[]
Expand Down
11 changes: 11 additions & 0 deletions tests/PHPStan/Analyser/data/bug-3468.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace Bug3468;

class NewInterval extends \DateInterval
{
}

function (NewInterval $ni): void {
$ni->f = 0.1;
};

0 comments on commit b21f537

Please sign in to comment.