-
Notifications
You must be signed in to change notification settings - Fork 438
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/1.10.x' into 1.11.x
- Loading branch information
Showing
14 changed files
with
128 additions
and
16 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
includes: | ||
- ../../conf/bleedingEdge.neon | ||
|
||
parameters: | ||
level: 8 | ||
ignoreErrors: | ||
- | ||
message: "#^Trait OnlyFilesNotAnalysedTrait\\\\BarTrait is used zero times and is not analysed\\.$#" | ||
count: 1 | ||
path: src/BarTrait.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,5 @@ | ||
includes: | ||
- ../../conf/bleedingEdge.neon | ||
|
||
parameters: | ||
level: 8 |
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,8 @@ | ||
<?php | ||
|
||
namespace OnlyFilesNotAnalysedTrait; | ||
|
||
trait BarTrait | ||
{ | ||
|
||
} |
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,8 @@ | ||
<?php | ||
|
||
namespace OnlyFilesNotAnalysedTrait; | ||
|
||
class Foo | ||
{ | ||
|
||
} |
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
rules: | ||
- PHPStan\Rules\Playground\FunctionNeverRule | ||
- PHPStan\Rules\Playground\MethodNeverRule | ||
- PHPStan\Rules\Playground\NotAnalysedTraitRule | ||
- PHPStan\Rules\Playground\NoPhpCodeRule |
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,62 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace PHPStan\Rules\Playground; | ||
|
||
use PhpParser\Node; | ||
use PHPStan\Analyser\Scope; | ||
use PHPStan\Node\CollectedDataNode; | ||
use PHPStan\Rules\Rule; | ||
use PHPStan\Rules\RuleErrorBuilder; | ||
use PHPStan\Rules\Traits\TraitDeclarationCollector; | ||
use PHPStan\Rules\Traits\TraitUseCollector; | ||
use function sprintf; | ||
use function strtolower; | ||
|
||
/** | ||
* @implements Rule<CollectedDataNode> | ||
*/ | ||
class NotAnalysedTraitRule implements Rule | ||
{ | ||
|
||
public function getNodeType(): string | ||
{ | ||
return CollectedDataNode::class; | ||
} | ||
|
||
public function processNode(Node $node, Scope $scope): array | ||
{ | ||
$traitDeclarationData = $node->get(TraitDeclarationCollector::class); | ||
$traitUseData = $node->get(TraitUseCollector::class); | ||
|
||
$declaredTraits = []; | ||
foreach ($traitDeclarationData as $file => $declaration) { | ||
foreach ($declaration as [$name, $line]) { | ||
$declaredTraits[strtolower($name)] = [$file, $name, $line]; | ||
} | ||
} | ||
|
||
foreach ($traitUseData as $usedNamesData) { | ||
foreach ($usedNamesData as $usedNames) { | ||
foreach ($usedNames as $usedName) { | ||
unset($declaredTraits[strtolower($usedName)]); | ||
} | ||
} | ||
} | ||
|
||
$errors = []; | ||
foreach ($declaredTraits as [$file, $name, $line]) { | ||
$errors[] = RuleErrorBuilder::message(sprintf( | ||
'Trait %s is used zero times and is not analysed.', | ||
$name, | ||
)) | ||
->identifier('phpstanPlayground.traitUnused') | ||
->file($file) | ||
->line($line) | ||
->tip('See: https://phpstan.org/blog/how-phpstan-analyses-traits') | ||
->build(); | ||
} | ||
|
||
return $errors; | ||
} | ||
|
||
} |
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