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
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"symfony/security-core": "^6.4",
"symfony/security-http": "^6.4",
"symfony/validator": "^6.4",
"symplify/phpstan-rules": "^14.6",
"symplify/vendor-patches": "^11.3",
"tomasvotruba/class-leak": "^2.0",
"tomasvotruba/type-coverage": "^2.0",
Expand Down
4 changes: 1 addition & 3 deletions config/sets/symfony/symfony3/symfony31.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@

declare(strict_types=1);

use Rector\Arguments\Rector\ClassMethod\ReplaceArgumentDefaultValueRector;
use Rector\Arguments\ValueObject\ReplaceArgumentDefaultValue;
use Rector\Config\RectorConfig;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->import(__DIR__ . '/symfony30/symfony31-yaml.php');
$rectorConfig->import(__DIR__ . '/symfony31/symfony31-yaml.php');
};
3 changes: 3 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
rules:
- Symplify\PHPStanRules\Rules\StringFileAbsolutePathExistsRule

parameters:
level: 8

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,7 @@ public function refactor(Node $node): ?Node
}

// split by && and "and"
if (str_contains($content, ' && ')) {
$andItems = explode(' && ', $content);
} else {
$andItems = explode(' and ', $content);
}
$andItems = str_contains($content, ' && ') ? explode(' && ', $content) : explode(' and ', $content);

$accessRights = [];

Expand Down
36 changes: 14 additions & 22 deletions rules/Symfony73/Rector/Class_/CommandHelpToAttributeRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use PhpParser\Node;
use PhpParser\Node\Arg;
use PhpParser\Node\Attribute;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\MethodCall;
use PhpParser\Node\Expr\Variable;
use PhpParser\Node\Identifier;
Expand All @@ -19,6 +20,7 @@
use PhpParser\NodeVisitor;
use PHPStan\Reflection\ReflectionProvider;
use PHPStan\Type\ObjectType;
use Rector\Doctrine\NodeAnalyzer\AttributeFinder;
use Rector\NodeTypeResolver\Node\AttributeKey;
use Rector\Rector\AbstractRector;
use Rector\Symfony\Enum\CommandMethodName;
Expand All @@ -38,6 +40,7 @@ final class CommandHelpToAttributeRector extends AbstractRector implements MinPh
{
public function __construct(
private readonly ReflectionProvider $reflectionProvider,
private readonly AttributeFinder $attributeFinder
) {
}

Expand All @@ -53,8 +56,10 @@ public function getRuleDefinition(): RuleDefinition
[
new CodeSample(
<<<'CODE_SAMPLE'
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;

#[AsCommand(name: 'app:some')]
final class SomeCommand extends Command
{
protected function configure(): void
Expand Down Expand Up @@ -105,8 +110,8 @@ public function refactor(Node $node): ?Node
return null;
}

$asCommandAttribute = $this->getAsCommandAttribute($node);
if ($asCommandAttribute === null) {
$asCommandAttribute = $this->attributeFinder->findAttributeByClass($node, SymfonyAttribute::AS_COMMAND);
if (! $asCommandAttribute instanceof Attribute) {
return null;
}

Expand All @@ -126,15 +131,15 @@ public function refactor(Node $node): ?Node
return null;
}

$wrappedHelp = new String_(
$wrappedHelpString = new String_(
$helpExpr->value,
[
Attributekey::KIND => String_::KIND_NOWDOC,
AttributeKey::DOC_LABEL => 'TXT',
]
);

$asCommandAttribute->args[] = new Arg($wrappedHelp, false, false, [], new Identifier('help'));
$asCommandAttribute->args[] = new Arg($wrappedHelpString, false, false, [], new Identifier('help'));

if ($configureClassMethod->stmts === []) {
unset($configureClassMethod);
Expand All @@ -143,29 +148,16 @@ public function refactor(Node $node): ?Node
return $node;
}

private function getAsCommandAttribute(Class_ $class): ?Attribute
{
foreach ($class->attrGroups as $attrGroup) {
foreach ($attrGroup->attrs as $attribute) {
if ($this->nodeNameResolver->isName($attribute->name, SymfonyAttribute::AS_COMMAND)) {
return $attribute;
}
}
}

return null;
}

/**
* Returns the argument passed to setHelp() and removes the MethodCall node.
*/
private function findAndRemoveSetHelpExpr(ClassMethod $configureMethod): ?String_
private function findAndRemoveSetHelpExpr(ClassMethod $configureClassMethod): ?String_
{
$helpString = null;

$this->traverseNodesWithCallable(
(array) $configureMethod->stmts,
function (Node $node) use (&$helpString) {
(array) $configureClassMethod->stmts,
function (Node $node) use (&$helpString): int|null|Expr {
if ($node instanceof Class_ || $node instanceof Function_) {
return NodeVisitor::DONT_TRAVERSE_CURRENT_AND_CHILDREN;
}
Expand Down Expand Up @@ -196,9 +188,9 @@ function (Node $node) use (&$helpString) {
}
);

foreach ((array) $configureMethod->stmts as $key => $stmt) {
foreach ((array) $configureClassMethod->stmts as $key => $stmt) {
if ($this->isExpressionVariableThis($stmt)) {
unset($configureMethod->stmts[$key]);
unset($configureClassMethod->stmts[$key]);
}
}

Expand Down
4 changes: 2 additions & 2 deletions rules/Symfony73/Rector/Class_/InvokableCommandRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -248,9 +248,9 @@ private function replaceInputArgumentOptionFetchWithVariables(ClassMethod $execu
});
}

private function isFluentArgumentOptionChain(MethodCall $call): bool
private function isFluentArgumentOptionChain(MethodCall $methodCall): bool
{
$current = $call;
$current = $methodCall;

while ($current instanceof MethodCall) {
// every link must be addArgument() or addOption()
Expand Down
37 changes: 18 additions & 19 deletions src/Set/SetProvider/SymfonySetProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,106 +42,105 @@ public function provide(): array
SetGroup::SYMFONY,
'symfony/symfony',
'3.0',
__DIR__ . '/../../../config/sets/symfony/symfony30.php'
__DIR__ . '/../../../config/sets/symfony/symfony3/symfony30.php'
),

new ComposerTriggeredSet(
SetGroup::SYMFONY,
'symfony/bridge-swift-mailer',
'3.0',
__DIR__ . '/../../../config/sets/symfony/symfony30/symfony30-bridge-swift-mailer.php'
__DIR__ . '/../../../config/sets/symfony/symfony3/symfony30/symfony30-bridge-swift-mailer.php'
),

new ComposerTriggeredSet(
SetGroup::SYMFONY,
'symfony/class-loader',
'3.0',
__DIR__ . '/../../../config/sets/symfony/symfony30/symfony30-class-loader.php'
__DIR__ . '/../../../config/sets/symfony/symfony3/symfony30/symfony30-class-loader.php'
),

new ComposerTriggeredSet(
SetGroup::SYMFONY,
'symfony/console',
'3.0',
__DIR__ . '/../../../config/sets/symfony/symfony30/symfony30-console.php'
__DIR__ . '/../../../config/sets/symfony/symfony3/symfony30/symfony30-console.php'
),

new ComposerTriggeredSet(
SetGroup::SYMFONY,
'symfony/forms',
'3.0',
__DIR__ . '/../../../config/sets/symfony/symfony30/symfony30-forms.php'
__DIR__ . '/../../../config/sets/symfony/symfony3/symfony30/symfony30-forms.php'
),

new ComposerTriggeredSet(
SetGroup::SYMFONY,
'symfony/http-foundation',
'3.0',
__DIR__ . '/../../../config/sets/symfony/symfony30/symfony30-http-foundation.php'
__DIR__ . '/../../../config/sets/symfony/symfony3/symfony30/symfony30-http-foundation.php'
),

new ComposerTriggeredSet(
SetGroup::SYMFONY,
'symfony/http-kernel',
'3.0',
__DIR__ . '/../../../config/sets/symfony/symfony30/symfony30-http-kernel.php'
__DIR__ . '/../../../config/sets/symfony/symfony3/symfony30/symfony30-http-kernel.php'
),

new ComposerTriggeredSet(
SetGroup::SYMFONY,
'symfony/process',
'3.0',
__DIR__ . '/../../../config/sets/symfony/symfony30/symfony30-process.php'
__DIR__ . '/../../../config/sets/symfony/symfony3/symfony30/symfony30-process.php'
),

new ComposerTriggeredSet(
SetGroup::SYMFONY,
'symfony/property-access',
'3.0',
__DIR__ . '/../../../config/sets/symfony/symfony30/symfony30-property-access.php'
__DIR__ . '/../../../config/sets/symfony/symfony3/symfony30/symfony30-property-access.php'
),

new ComposerTriggeredSet(
SetGroup::SYMFONY,
'symfony/security',
'3.0',
__DIR__ . '/../../../config/sets/symfony/symfony30/symfony30-security.php'
__DIR__ . '/../../../config/sets/symfony/symfony3/symfony30/symfony30-security.php'
),

new ComposerTriggeredSet(
SetGroup::SYMFONY,
'symfony/translation',
'3.0',
__DIR__ . '/../../../config/sets/symfony/symfony30/symfony30-translation.php'
__DIR__ . '/../../../config/sets/symfony/symfony3/symfony30/symfony30-translation.php'
),

new ComposerTriggeredSet(
SetGroup::SYMFONY,
'symfony/twig-bundle',
'3.0',
__DIR__ . '/../../../config/sets/symfony/symfony30/symfony30-twig-bundle.php'
__DIR__ . '/../../../config/sets/symfony/symfony3/symfony30/symfony30-twig-bundle.php'
),

new ComposerTriggeredSet(
SetGroup::SYMFONY,
'symfony/validator',
'3.0',
__DIR__ . '/../../../config/sets/symfony/symfony30/symfony30-validator.php'
__DIR__ . '/../../../config/sets/symfony/symfony3/symfony30/symfony30-validator.php'
),


new ComposerTriggeredSet(
SetGroup::SYMFONY,
'symfony/symfony',
'3.1',
__DIR__ . '/../../../config/sets/symfony/symfony31.php'
__DIR__ . '/../../../config/sets/symfony/symfony3/symfony31.php'
),

new ComposerTriggeredSet(
SetGroup::SYMFONY,
'symfony/yaml',
'3.1',
__DIR__ . '/../../../config/sets/symfony/symfony31-yaml.php'
__DIR__ . '/../../../config/sets/symfony/symfony3/symfony31/symfony31-yaml.php'
),

// @todo split rest
Expand All @@ -150,19 +149,19 @@ public function provide(): array
SetGroup::SYMFONY,
'symfony/*',
'3.2',
__DIR__ . '/../../../config/sets/symfony/symfony32.php'
__DIR__ . '/../../../config/sets/symfony/symfony3/symfony32.php'
),
new ComposerTriggeredSet(
SetGroup::SYMFONY,
'symfony/*',
'3.3',
__DIR__ . '/../../../config/sets/symfony/symfony33.php'
__DIR__ . '/../../../config/sets/symfony/symfony3/symfony33.php'
),
new ComposerTriggeredSet(
SetGroup::SYMFONY,
'symfony/*',
'3.4',
__DIR__ . '/../../../config/sets/symfony/symfony34.php'
__DIR__ . '/../../../config/sets/symfony/symfony3/symfony34.php'
),
new ComposerTriggeredSet(
SetGroup::SYMFONY,
Expand Down
12 changes: 7 additions & 5 deletions src/Set/SymfonySetList.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
namespace Rector\Symfony\Set;

/**
* @deprecated Set list are too generic and do not handle package differences. Use ->withComposerBased(symfony: true) instead
*
* @api
*/
final class SymfonySetList
Expand Down Expand Up @@ -37,27 +39,27 @@ final class SymfonySetList
/**
* @var string
*/
final public const SYMFONY_30 = __DIR__ . '/../../config/sets/symfony/symfony30.php';
final public const SYMFONY_30 = __DIR__ . '/../../config/sets/symfony/symfony3/symfony30.php';

/**
* @var string
*/
final public const SYMFONY_31 = __DIR__ . '/../../config/sets/symfony/symfony31.php';
final public const SYMFONY_31 = __DIR__ . '/../../config/sets/symfony/symfony3/symfony31.php';

/**
* @var string
*/
final public const SYMFONY_32 = __DIR__ . '/../../config/sets/symfony/symfony32.php';
final public const SYMFONY_32 = __DIR__ . '/../../config/sets/symfony/symfony3/symfony32.php';

/**
* @var string
*/
final public const SYMFONY_33 = __DIR__ . '/../../config/sets/symfony/symfony33.php';
final public const SYMFONY_33 = __DIR__ . '/../../config/sets/symfony/symfony3/symfony33.php';

/**
* @var string
*/
final public const SYMFONY_34 = __DIR__ . '/../../config/sets/symfony/symfony34.php';
final public const SYMFONY_34 = __DIR__ . '/../../config/sets/symfony/symfony3/symfony34.php';

/**
* @var string
Expand Down

This file was deleted.

Loading