-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Generalize to AST-based MemberUsageProvider
- Loading branch information
Showing
26 changed files
with
379 additions
and
268 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
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,43 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace ShipMonk\PHPStan\DeadCode\Collector; | ||
|
||
use PhpParser\Node; | ||
use PHPStan\Analyser\Scope; | ||
use PHPStan\Node\ClassMethodsNode; | ||
use ShipMonk\PHPStan\DeadCode\Graph\ClassMemberUsage; | ||
use function array_map; | ||
|
||
trait BufferedUsageCollector | ||
{ | ||
|
||
/** | ||
* @var list<ClassMemberUsage> | ||
*/ | ||
private array $usageBuffer = []; | ||
|
||
/** | ||
* @return non-empty-list<string>|null | ||
*/ | ||
private function tryFlushBuffer( | ||
Node $node, | ||
Scope $scope | ||
): ?array | ||
{ | ||
if (!$scope->isInClass() || $node instanceof ClassMethodsNode) { // @phpstan-ignore-line ignore BC promise | ||
$data = $this->usageBuffer; | ||
$this->usageBuffer = []; | ||
|
||
// collect data once per class to save memory & resultCache size | ||
return $data === [] | ||
? null | ||
: array_map( | ||
static fn (ClassMemberUsage $call): string => $call->serialize(), | ||
$data, | ||
); | ||
} | ||
|
||
return null; | ||
} | ||
|
||
} |
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
Oops, something went wrong.