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
8 changes: 4 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,15 @@ script:
# Rector demo run
- |
if [[ $RUN_RECTOR == true ]]; then
bin/rector process src --level symfony40 --dry-run
bin/rector process src --set symfony40 --dry-run
composer docs
fi

# Eat your own dog food
- |
if [[ $DOG_FOOD == true ]]; then
bin/rector process src packages --level dead-code --dry-run
bin/rector process src packages --level code-quality --dry-run
bin/rector process src packages --set dead-code --dry-run
bin/rector process src packages --set code-quality --dry-run
fi

# Run standalone install in non-root package, ref https://github.com/rectorphp/rector/issues/732
Expand All @@ -79,7 +79,7 @@ script:
../rector-dir/vendor/bin/rector

# --hide-autoload-errors due to skipped dev deps and mixes tests in /src
../rector-dir/vendor/bin/rector process src --level code-quality --hide-autoload-errors --dry-run
../rector-dir/vendor/bin/rector process src --set code-quality --hide-autoload-errors --dry-run
fi

after_script:
Expand Down
12 changes: 6 additions & 6 deletions bin/container.php
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
<?php declare(strict_types=1);

use Rector\Console\Option\LevelOptionResolver;
use Rector\Console\Option\SetOptionResolver;
use Rector\Exception\Configuration\SetNotFoundException;
use Rector\HttpKernel\RectorKernel;
use Symfony\Component\Console\Input\ArgvInput;
use Symplify\PackageBuilder\Configuration\ConfigFileFinder;
use Symplify\PackageBuilder\Console\Input\InputDetector;
use Symplify\PackageBuilder\Console\ShellCode;
use Symplify\PackageBuilder\Console\Style\SymfonyStyleFactory;
use Symplify\PackageBuilder\Exception\Configuration\LevelNotFoundException;

$configFiles = [];

// Detect configuration from --level
// Detect configuration from --set
try {
$configFiles[] = (new LevelOptionResolver())->detectFromInputAndDirectory(
$configFiles[] = (new SetOptionResolver())->detectFromInputAndDirectory(
new ArgvInput(),
__DIR__ . '/../config/set'
);
} catch (LevelNotFoundException $levelNotFoundException) {
} catch (SetNotFoundException $setNotFoundException) {
$symfonyStyle = (new SymfonyStyleFactory())->create();
$symfonyStyle->error($levelNotFoundException->getMessage());
$symfonyStyle->error($setNotFoundException->getMessage());
exit(ShellCode::ERROR);
}

Expand Down
2 changes: 1 addition & 1 deletion create-rector.yaml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ code_after: |

source: # e.g. link to RFC or headline in upgrade guide, 1 or more in the list
- ""
level: "" # e.g. symfony30.yaml, target config to append this rector to
set: "" # e.g. symfony30.yaml, target config to append this rector to
2 changes: 1 addition & 1 deletion docs/HowItWorks.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

## 1. Finds all files and Load Configured Rectors

- The application finds files in source you provide and registeres Rectors - from `--level`, `--config` or local `rector.yaml`
- The application finds files in source you provide and registered Rectors - from `--set`, `--config` or local `rector.yaml`
- Then it iterates all found files and applies relevant Rectors to them.
- *Rector* in this context is 1 single class that modifies 1 thing, e.g. changes class name

Expand Down
3 changes: 2 additions & 1 deletion packages/CodingStyle/src/Node/ConcatJoiner.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ final class ConcatJoiner
*/
public function joinToStringAndPlaceholderNodes(Concat $concat): array
{
if (! $concat->getAttribute(AttributeKey::PARENT_NODE) instanceof Concat) {
$parentNode = $concat->getAttribute(AttributeKey::PARENT_NODE);
if (! $parentNode instanceof Concat) {
$this->reset();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,8 @@ private function importNamesAndCollectNewUseStatements(Name $name): ?Name
}

if (! $this->useAddingCommander->hasImport($name, $fullyQualifiedName)) {
if ($name->getAttribute(AttributeKey::PARENT_NODE) instanceof FuncCall) {
$parentNode = $name->getAttribute(AttributeKey::PARENT_NODE);
if ($parentNode instanceof FuncCall) {
$this->useAddingCommander->addFunctionUseImport($name, $fullyQualifiedName);
} else {
$this->useAddingCommander->addUseImport($name, $fullyQualifiedName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ public function refactor(Node $node): ?Node

if ($node->expr instanceof Concat) {
// process only first concat
if ($node->getAttribute(AttributeKey::PARENT_NODE) instanceof Concat) {
$parentNode = $node->getAttribute(AttributeKey::PARENT_NODE);
if ($parentNode instanceof Concat) {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ public function refactor(Node $node): ?Node
private function resolveAssignedVariables(FunctionLike $functionLike): array
{
return $this->betterNodeFinder->find($functionLike, function (Node $node): bool {
if (! $node->getAttribute(AttributeKey::PARENT_NODE) instanceof Assign) {
$parentNode = $node->getAttribute(AttributeKey::PARENT_NODE);
if (! $parentNode instanceof Assign) {
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,8 @@ private function processFieldToFieldDirect(Assign $assign, FuncCall $funcCall):
{
foreach ($this->fieldToFieldDirect as $funcName => $property) {
if ($this->isName($funcCall, $funcName)) {
if ($funcCall->getAttribute(AttributeKey::PARENT_NODE) instanceof PropertyFetch) {
$parentNode = $funcCall->getAttribute(AttributeKey::PARENT_NODE);
if ($parentNode instanceof PropertyFetch) {
continue;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,9 @@ public function refactor(Node $node): ?Node
$methodName = $this->functionNameToMethodName[$this->getName($node)];
$matchStaticCall = $this->createMatchStaticCall($node, $methodName);

// skip assigns, might be used with differnt return value
if ($node->getAttribute(AttributeKey::PARENT_NODE) instanceof Assign) {
// skip assigns, might be used with different return value
$parentNode = $node->getAttribute(AttributeKey::PARENT_NODE);
if ($parentNode instanceof Assign) {
if ($methodName === 'matchAll') {
// use count
return new FuncCall(new Name('count'), [new Arg($matchStaticCall)]);
Expand Down
3 changes: 2 additions & 1 deletion packages/Php/src/Rector/Assign/MysqlAssignToMysqliRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,8 @@ private function processFieldToFieldDirect(Assign $assign, FuncCall $funcCall):
{
foreach ($this->fieldToFieldDirect as $funcName => $property) {
if ($this->isName($funcCall, $funcName)) {
if ($funcCall->getAttribute(AttributeKey::PARENT_NODE) instanceof PropertyFetch) {
$parentNode = $funcCall->getAttribute(AttributeKey::PARENT_NODE);
if ($parentNode instanceof PropertyFetch) {
continue;
}

Expand Down
3 changes: 2 additions & 1 deletion packages/Php/src/Rector/Each/ListEachRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ private function shouldSkip(Assign $assign): bool
}

// assign should be top level, e.g. not in a while loop
if (! $assign->getAttribute(AttributeKey::PARENT_NODE) instanceof Expression) {
$parentNode = $assign->getAttribute(AttributeKey::PARENT_NODE);
if (! $parentNode instanceof Expression) {
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,8 @@ private function resolveUseVariables(array $nodes, array $paramNodes): array
continue;
}

if ($variableNode->getAttribute(AttributeKey::PARENT_NODE) instanceof Assign) {
$parentNode = $variableNode->getAttribute(AttributeKey::PARENT_NODE);
if ($parentNode instanceof Assign) {
$alreadyAssignedVariables[] = $variableName;
}

Expand Down
1 change: 1 addition & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ parameters:
- '#Method Rector\\Symfony\\Bridge\\DefaultAnalyzedSymfonyApplicationContainer\:\:getService\(\) should return object but returns object\|null#'
- '#Method Rector\\BetterPhpDocParser\\PhpDocInfo\\PhpDocInfo\:\:(.*?)\(\) should return Rector\\DoctrinePhpDocParser\\Ast\\PhpDoc\\(.*?)\|null but returns PHPStan\\PhpDocParser\\Ast\\PhpDoc\\PhpDocTagValueNode\|null#'
- '#Call to function property_exists\(\) with string and (.*?) will always evaluate to false#'
- '#Method Rector\\Console\\Option\\SetOptionResolver\:\:separateVersionedAndUnversionedSets\(\) should return array<array<string\>\> but returns array<int, array<int\|string, array<int, string\>\|string\>\>#'

# PHP 7.4 1_000 support
- '#Property PhpParser\\Node\\Scalar\\DNumber\:\:\$value \(float\) does not accept string#'
Expand Down
8 changes: 0 additions & 8 deletions src/Console/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,14 +159,6 @@ private function addCustomOptions(InputDefinition $inputDefinition): void
'Finds config by shortcut name'
));

// same as "set", for BC
$inputDefinition->addOption(new InputOption(
'level',
'l',
InputOption::VALUE_REQUIRED,
'Finds config by shortcut name'
));

$inputDefinition->addOption(new InputOption(
'debug',
null,
Expand Down
187 changes: 0 additions & 187 deletions src/Console/Option/LevelOptionResolver.php

This file was deleted.

Loading