-
Notifications
You must be signed in to change notification settings - Fork 494
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Report nonexistent classes and functions based on
@since
and `@remo…
…ved` in phpstorm-stubs while respecting `phpVersion` parameter
- Loading branch information
1 parent
aa92b5b
commit 4eecc4f
Showing
14 changed files
with
169 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
src/Reflection/BetterReflection/SourceLocator/PhpVersionBlacklistSourceLocator.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace PHPStan\Reflection\BetterReflection\SourceLocator; | ||
|
||
use Roave\BetterReflection\Identifier\Identifier; | ||
use Roave\BetterReflection\Identifier\IdentifierType; | ||
use Roave\BetterReflection\Reflection\Reflection; | ||
use Roave\BetterReflection\Reflector\Reflector; | ||
use Roave\BetterReflection\SourceLocator\SourceStubber\PhpStormStubsSourceStubber; | ||
use Roave\BetterReflection\SourceLocator\Type\SourceLocator; | ||
|
||
class PhpVersionBlacklistSourceLocator implements SourceLocator | ||
{ | ||
|
||
private SourceLocator $sourceLocator; | ||
|
||
private PhpStormStubsSourceStubber $phpStormStubsSourceStubber; | ||
|
||
public function __construct( | ||
SourceLocator $sourceLocator, | ||
PhpStormStubsSourceStubber $phpStormStubsSourceStubber | ||
) | ||
{ | ||
$this->sourceLocator = $sourceLocator; | ||
$this->phpStormStubsSourceStubber = $phpStormStubsSourceStubber; | ||
} | ||
|
||
public function locateIdentifier(Reflector $reflector, Identifier $identifier): ?Reflection | ||
{ | ||
if ($identifier->isClass()) { | ||
if ($this->phpStormStubsSourceStubber->isPresentClass($identifier->getName()) === false) { | ||
return null; | ||
} | ||
} | ||
|
||
if ($identifier->isFunction()) { | ||
if ($this->phpStormStubsSourceStubber->isPresentFunction($identifier->getName()) === false) { | ||
return null; | ||
} | ||
} | ||
|
||
return $this->sourceLocator->locateIdentifier($reflector, $identifier); | ||
} | ||
|
||
public function locateIdentifiersByType(Reflector $reflector, IdentifierType $identifierType): array | ||
{ | ||
return $this->sourceLocator->locateIdentifiersByType($reflector, $identifierType); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace PHPStan\Analyser; | ||
|
||
class AnalyserPhp74IntegrationTest extends \PHPStan\Testing\TestCase | ||
{ | ||
|
||
public function testErrors(): void | ||
{ | ||
$errors = $this->runAnalyse(__DIR__ . '/data/removedOnPhp80.php'); | ||
$this->assertCount(0, $errors); | ||
} | ||
|
||
/** | ||
* @return string[] | ||
*/ | ||
public static function getAdditionalConfigFiles(): array | ||
{ | ||
return [ | ||
__DIR__ . '/php74.neon', | ||
]; | ||
} | ||
|
||
|
||
/** | ||
* @param string $file | ||
* @return \PHPStan\Analyser\Error[] | ||
*/ | ||
private function runAnalyse(string $file): array | ||
{ | ||
$file = $this->getFileHelper()->normalizePath($file); | ||
/** @var \PHPStan\Analyser\Analyser $analyser */ | ||
$analyser = self::getContainer()->getByType(Analyser::class); | ||
|
||
return $analyser->analyse([$file])->getErrors(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace PHPStan\Analyser; | ||
|
||
class AnalyserPhp80IntegrationTest extends \PHPStan\Testing\TestCase | ||
{ | ||
|
||
public function testErrors(): void | ||
{ | ||
$errors = $this->runAnalyse(__DIR__ . '/data/removedOnPhp80.php'); | ||
$this->assertCount(2, $errors); | ||
} | ||
|
||
/** | ||
* @return string[] | ||
*/ | ||
public static function getAdditionalConfigFiles(): array | ||
{ | ||
return [ | ||
__DIR__ . '/php80.neon', | ||
]; | ||
} | ||
|
||
|
||
/** | ||
* @param string $file | ||
* @return \PHPStan\Analyser\Error[] | ||
*/ | ||
private function runAnalyse(string $file): array | ||
{ | ||
$file = $this->getFileHelper()->normalizePath($file); | ||
/** @var \PHPStan\Analyser\Analyser $analyser */ | ||
$analyser = self::getContainer()->getByType(Analyser::class); | ||
|
||
return $analyser->analyse([$file])->getErrors(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?php | ||
|
||
function (): void { | ||
gmp_random(); | ||
|
||
new DOMImplementationSource(); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
parameters: | ||
phpVersion: 70400 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
parameters: | ||
phpVersion: 80000 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters