Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,28 @@
final class CallToConstructorStatementWithoutImpurePointsRule implements Rule
{

public function __construct(private PossiblyPureCallTransitivePurityResolver $purityResolver)
{
}

public function getNodeType(): string
{
return CollectedDataNode::class;
}

public function processNode(Node $node, Scope $scope): array
{
$pureKeys = $this->purityResolver->getPureCallableKeys($node);

$classesWithConstructors = [];
foreach ($node->get(ConstructorWithoutImpurePointsCollector::class) as [$class]) {
$classesWithConstructors[strtolower($class)] = $class;
foreach ($node->get(ConstructorWithoutImpurePointsCollector::class) as $collected) {
foreach ($collected as [$class]) {
if (!isset($pureKeys[PossiblyPureCallTransitivePurityResolver::methodKey($class, '__construct')])) {
continue;
}

$classesWithConstructors[strtolower($class)] = $class;
}
}

$errors = [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,28 @@
final class CallToFunctionStatementWithoutImpurePointsRule implements Rule
{

public function __construct(private PossiblyPureCallTransitivePurityResolver $purityResolver)
{
}

public function getNodeType(): string
{
return CollectedDataNode::class;
}

public function processNode(Node $node, Scope $scope): array
{
$pureKeys = $this->purityResolver->getPureCallableKeys($node);

$functions = [];
foreach ($node->get(FunctionWithoutImpurePointsCollector::class) as [$functionName]) {
$functions[strtolower($functionName)] = $functionName;
foreach ($node->get(FunctionWithoutImpurePointsCollector::class) as $collected) {
foreach ($collected as [$functionName]) {
if (!isset($pureKeys[PossiblyPureCallTransitivePurityResolver::functionKey($functionName)])) {
continue;
}

$functions[strtolower($functionName)] = $functionName;
}
}

$errors = [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,27 @@
final class CallToMethodStatementWithoutImpurePointsRule implements Rule
{

public function __construct(private PossiblyPureCallTransitivePurityResolver $purityResolver)
{
}

public function getNodeType(): string
{
return CollectedDataNode::class;
}

public function processNode(Node $node, Scope $scope): array
{
$pureKeys = $this->purityResolver->getPureCallableKeys($node);

$methods = [];
foreach ($node->get(MethodWithoutImpurePointsCollector::class) as $collected) {
foreach ($collected as [$className, $methodName, $classDisplayName]) {
$className = strtolower($className);
$methods[$className][strtolower($methodName)] = $classDisplayName . '::' . $methodName;
if (!isset($pureKeys[PossiblyPureCallTransitivePurityResolver::methodKey($className, $methodName)])) {
continue;
}

$methods[strtolower($className)][strtolower($methodName)] = $classDisplayName . '::' . $methodName;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,27 @@
final class CallToStaticMethodStatementWithoutImpurePointsRule implements Rule
{

public function __construct(private PossiblyPureCallTransitivePurityResolver $purityResolver)
{
}

public function getNodeType(): string
{
return CollectedDataNode::class;
}

public function processNode(Node $node, Scope $scope): array
{
$pureKeys = $this->purityResolver->getPureCallableKeys($node);

$methods = [];
foreach ($node->get(MethodWithoutImpurePointsCollector::class) as $collected) {
foreach ($collected as [$className, $methodName, $classDisplayName]) {
$lowerClassName = strtolower($className);
$methods[$lowerClassName][strtolower($methodName)] = $classDisplayName . '::' . $methodName;
if (!isset($pureKeys[PossiblyPureCallTransitivePurityResolver::methodKey($className, $methodName)])) {
continue;
}

$methods[strtolower($className)][strtolower($methodName)] = $classDisplayName . '::' . $methodName;
}
}

Expand Down
24 changes: 14 additions & 10 deletions src/Rules/DeadCode/ConstructorWithoutImpurePointsCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,16 @@
use function count;

/**
* @implements Collector<MethodReturnStatementsNode, string>
* @implements Collector<MethodReturnStatementsNode, array{string, list<string>}>
*/
#[RegisteredCollector(level: 4)]
final class ConstructorWithoutImpurePointsCollector implements Collector
{

public function __construct(private PossiblyPureCallTransitivePurityResolver $purityResolver)
{
}

public function getNodeType(): string
{
return MethodReturnStatementsNode::class;
Expand All @@ -32,14 +36,6 @@ public function processNode(Node $node, Scope $scope)
return null;
}

if (count($node->getImpurePoints()) !== 0) {
return null;
}

if (count($node->getStatementResult()->getThrowPoints()) !== 0) {
return null;
}

foreach ($method->getParameters() as $parameter) {
if (!$parameter->passedByReference()->createsNewVariable()) {
continue;
Expand All @@ -52,7 +48,15 @@ public function processNode(Node $node, Scope $scope)
return null;
}

return $method->getDeclaringClass()->getName();
$dependencies = $this->purityResolver->resolveDependencies(
$node->getImpurePoints(),
$node->getStatementResult()->getThrowPoints(),
);
if ($dependencies === null) {
return null;
}

return [$method->getDeclaringClass()->getName(), $dependencies];
}

}
24 changes: 14 additions & 10 deletions src/Rules/DeadCode/FunctionWithoutImpurePointsCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,16 @@
use function count;

/**
* @implements Collector<FunctionReturnStatementsNode, string>
* @implements Collector<FunctionReturnStatementsNode, array{string, list<string>}>
*/
#[RegisteredCollector(level: 4)]
final class FunctionWithoutImpurePointsCollector implements Collector
{

public function __construct(private PossiblyPureCallTransitivePurityResolver $purityResolver)
{
}

public function getNodeType(): string
{
return FunctionReturnStatementsNode::class;
Expand All @@ -31,14 +35,6 @@ public function processNode(Node $node, Scope $scope)
return null;
}

if (count($node->getImpurePoints()) !== 0) {
return null;
}

if (count($node->getStatementResult()->getThrowPoints()) !== 0) {
return null;
}

foreach ($function->getParameters() as $parameter) {
if (!$parameter->passedByReference()->createsNewVariable()) {
continue;
Expand All @@ -51,7 +47,15 @@ public function processNode(Node $node, Scope $scope)
return null;
}

return $function->getName();
$dependencies = $this->purityResolver->resolveDependencies(
$node->getImpurePoints(),
$node->getStatementResult()->getThrowPoints(),
);
if ($dependencies === null) {
return null;
}

return [$function->getName(), $dependencies];
}

}
24 changes: 14 additions & 10 deletions src/Rules/DeadCode/MethodWithoutImpurePointsCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,16 @@
use function count;

/**
* @implements Collector<MethodReturnStatementsNode, array{class-string, string, string}>
* @implements Collector<MethodReturnStatementsNode, array{class-string, string, string, list<string>}>
*/
#[RegisteredCollector(level: 4)]
final class MethodWithoutImpurePointsCollector implements Collector
{

public function __construct(private PossiblyPureCallTransitivePurityResolver $purityResolver)
{
}

public function getNodeType(): string
{
return MethodReturnStatementsNode::class;
Expand All @@ -31,14 +35,6 @@ public function processNode(Node $node, Scope $scope)
return null;
}

if (count($node->getImpurePoints()) !== 0) {
return null;
}

if (count($node->getStatementResult()->getThrowPoints()) !== 0) {
return null;
}

foreach ($method->getParameters() as $parameter) {
if (!$parameter->passedByReference()->createsNewVariable()) {
continue;
Expand All @@ -55,7 +51,15 @@ public function processNode(Node $node, Scope $scope)
return null;
}

return [$method->getDeclaringClass()->getName(), $method->getName(), $method->getDeclaringClass()->getDisplayName()];
$dependencies = $this->purityResolver->resolveDependencies(
$node->getImpurePoints(),
$node->getStatementResult()->getThrowPoints(),
);
if ($dependencies === null) {
return null;
}

return [$method->getDeclaringClass()->getName(), $method->getName(), $method->getDeclaringClass()->getDisplayName(), $dependencies];
}

}
Loading
Loading