Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removing parent classes #5714

Merged
merged 3 commits into from
Mar 1, 2021
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
36 changes: 19 additions & 17 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,16 @@
"symfony/finder": "^4.4.8|^5.1",
"symfony/http-kernel": "^4.4.8|^5.1",
"symfony/process": "^4.4.8|^5.1",
"symplify/astral": "^9.2.1",
"symplify/autowire-array-parameter": "^9.2.1",
"symplify/console-color-diff": "^9.2.1",
"symplify/package-builder": "^9.2.1",
"symplify/rule-doc-generator": "^9.2.1",
"symplify/set-config-resolver": "^9.2.1",
"symplify/simple-php-doc-parser": "^9.2.1",
"symplify/skipper": "^9.2.1",
"symplify/smart-file-system": "^9.2.1",
"symplify/symfony-php-config": "^9.2.1",
"symplify/astral": "dev-master",
"symplify/autowire-array-parameter": "dev-master",
"symplify/console-color-diff": "dev-master",
"symplify/package-builder": "dev-master",
"symplify/rule-doc-generator": "dev-master",
"symplify/set-config-resolver": "dev-master",
"symplify/simple-php-doc-parser": "dev-master",
"symplify/skipper": "dev-master",
"symplify/smart-file-system": "dev-master",
"symplify/symfony-php-config": "dev-master",
"webmozart/assert": "^1.9"
},
"require-dev": {
Expand All @@ -71,14 +71,14 @@
"phpunit/phpunit": "^9.5",
"symfony/security-core": "^5.2",
"symfony/security-http": "^5.2",
"symplify/changelog-linker": "^9.2.1",
"symplify/coding-standard": "^9.2.1",
"symplify/changelog-linker": "dev-master",
"symplify/coding-standard": "dev-master",
"symplify/easy-ci": "^9.1.0",
"symplify/easy-coding-standard": "^9.2.1",
"symplify/easy-testing": "^9.2.1",
"symplify/easy-coding-standard": "dev-master",
"symplify/easy-testing": "dev-master",
"symplify/monorepo-builder": "^9.2",
"symplify/phpstan-extensions": "^9.2.1",
"symplify/phpstan-rules": "^9.2.1",
"symplify/phpstan-extensions": "dev-master",
"symplify/phpstan-rules": "dev-master",
"tracy/tracy": "^2.8"
},
"replace": {
Expand Down Expand Up @@ -328,5 +328,7 @@
},
"config": {
"sort-packages": true
}
},
"minimum-stability": "dev",
"prefer-stable": true
}
12 changes: 9 additions & 3 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,12 @@ parameters:
paths:
- packages/node-type-resolver/tests

- '#Content of method "configure\(\)" is duplicated with method "configure\(\)" in "Rector\\Composer\\Rector\\AddPackageToRequireComposerRector" class\. Use unique content or abstract service instead#'
- '#Content of method "isConflicting\(\)" is duplicated with method "isConflicting\(\)" in "Rector\\Naming\\Guard\\PropertyConflictingNameGuard\\MatchPropertyTypeConflictingNameGuard" class\. Use unique content or abstract service instead#'
- '#Content of method "isConflicting\(\)" is duplicated with method "isConflicting\(\)" in "Rector\\Naming\\Guard\\PropertyConflictingNameGuard\\BoolPropertyConflictingNameGuard" class\. Use unique content or abstract service instead#'
- '#Content of method "configure\(\)" is duplicated with method "configure\(\)" in "Rector\\Composer\\Rector\\AddPackageToRequireComposerRector" class\. Use unique content or service instead#'
- '#Content of method "getFunctionLikePhpDocInfo\(\)" is duplicated with method "getFunctionLikePhpDocInfo\(\)" in "Rector\\TypeDeclaration\\TypeInferer\\ParamTypeInferer\\PHPUnitDataProviderParamTypeInferer" class\. Use unique content or service instead#'

- '#PHPDoc tag @return with type PhpParser\\Node\\Stmt\\ClassMethod\|PhpParser\\Node\\Stmt\\Function_\|Rector\\Naming\\Matcher\\Closure\|null is not subtype of native type PhpParser\\Node\\FunctionLike\|null#'

-
message: '#Do not use "array_filter" function with complex content, make it more readable with extracted method or single\-line statement#'
paths:
- src/Application/ActiveRectorsProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,17 @@ public function refactor(Node $node): ?Node
private function shouldRefactor(Array_ $array): bool
{
// Check that any item in the array is the spread
return array_filter($array->items, function (?ArrayItem $item): bool {
if ($item === null) {
return false;
foreach ($array->items as $item) {
if (! $item instanceof ArrayItem) {
continue;
}

if ($item->unpack) {
return true;
}
return $item->unpack;
}) !== [];
}

return false;
}

private function refactorNode(Array_ $array): Node
Expand Down
22 changes: 0 additions & 22 deletions rules/naming/src/Contract/Matcher/MatcherInterface.php

This file was deleted.

95 changes: 0 additions & 95 deletions rules/naming/src/Matcher/AbstractMatcher.php

This file was deleted.

36 changes: 36 additions & 0 deletions rules/naming/src/Matcher/CallMatcher.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

declare(strict_types=1);

namespace Rector\Naming\Matcher;

use PhpParser\Node;
use PhpParser\Node\Expr\Assign;
use PhpParser\Node\Expr\FuncCall;
use PhpParser\Node\Expr\MethodCall;
use PhpParser\Node\Expr\StaticCall;
use PhpParser\Node\Stmt\Foreach_;

final class CallMatcher
{
/**
* @param Assign|Foreach_ $node
* @return FuncCall|StaticCall|MethodCall|null
*/
public function matchCall(Node $node): ?Node
{
if ($node->expr instanceof MethodCall) {
return $node->expr;
}

if ($node->expr instanceof StaticCall) {
return $node->expr;
}

if ($node->expr instanceof FuncCall) {
return $node->expr;
}

return null;
}
}
56 changes: 45 additions & 11 deletions rules/naming/src/Matcher/ForeachMatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,65 @@

namespace Rector\Naming\Matcher;

use PhpParser\Node;
use PhpParser\Node\Expr\Closure;
use PhpParser\Node\Expr\Variable;
use PhpParser\Node\FunctionLike;
use PhpParser\Node\Stmt\ClassMethod;
use PhpParser\Node\Stmt\Foreach_;
use PhpParser\Node\Stmt\Function_;
use Rector\Naming\ValueObject\VariableAndCallForeach;
use Rector\NodeNameResolver\NodeNameResolver;
use Rector\NodeTypeResolver\Node\AttributeKey;

final class ForeachMatcher extends AbstractMatcher
final class ForeachMatcher
{
/**
* @param Foreach_ $node
* @var NodeNameResolver
*/
public function getVariableName(Node $node): ?string
private $nodeNameResolver;

/**
* @var CallMatcher
*/
private $callMatcher;

public function __construct(NodeNameResolver $nodeNameResolver, CallMatcher $callMatcher)
{
if (! $node->valueVar instanceof Variable) {
$this->nodeNameResolver = $nodeNameResolver;
$this->callMatcher = $callMatcher;
}

public function match(Foreach_ $foreach): ?VariableAndCallForeach
{
$call = $this->callMatcher->matchCall($foreach);
if ($call === null) {
return null;
}

if (! $foreach->valueVar instanceof Variable) {
return null;
}

$functionLike = $this->getFunctionLike($foreach);
if ($functionLike === null) {
return null;
}

$variableName = $this->nodeNameResolver->getName($foreach->valueVar);
if ($variableName === null) {
return null;
}

return $this->nodeNameResolver->getName($node->valueVar);
return new VariableAndCallForeach($foreach->valueVar, $call, $variableName, $functionLike);
}

/**
* @param Foreach_ $node
* @return ClassMethod|Function_|Closure|null
*/
public function getVariable(Node $node): Variable
private function getFunctionLike(Foreach_ $foreach): ?FunctionLike
{
/** @var Variable $variable */
$variable = $node->valueVar;
return $variable;
return $foreach->getAttribute(AttributeKey::CLOSURE_NODE) ??
$foreach->getAttribute(AttributeKey::METHOD_NODE) ??
$foreach->getAttribute(AttributeKey::FUNCTION_NODE);
}
}
Loading