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: 2 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,10 @@ composer require rector/rector --dev
To add a set to your config, use `Rector\Set\ValueObject\DowngradeLevelSetList` class and pick target set:

```php
use Rector\Set\ValueObject\DowngradeLevelSetList;
use Rector\Config\RectorConfig;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->sets([
DowngradeLevelSetList::DOWN_TO_PHP_72
]);
};
return RectorConfig::configure()
->withDowngradeSets(php72: true);
```

Then run Rector to downgrade your code to PHP 7.2!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,8 @@ public function refactor(Node $node): null|Expr|array
return null;
}

// if ($node instanceof TryCatch) {
// SimpleNodeTraverser::decorateWithAttributeValue($node->stmts, self::IS_EXPRESSION_INSIDE_TRY_CATCH, true);
// return null;
// }

if ($node instanceof Expression) {
return $this->refactorStmt($node);
return $this->refactorExpression($node);
}

return $this->jsonConstCleaner->clean($node, [JsonConstant::THROW_ON_ERROR]);
Expand Down Expand Up @@ -154,14 +149,14 @@ private function resolveFuncCall(Expression $Expression): ?FuncCall
*
* @return null|array<Expression|If_>
*/
private function refactorStmt(Expression $Expression): ?array
private function refactorExpression(Expression $expression): ?array
{
if ($Expression->getAttribute(AttributeKey::IS_IN_TRY_BLOCK) === true) {
if ($expression->getAttribute(AttributeKey::IS_IN_TRY_BLOCK) === true) {
return null;
}

// retrieve a `FuncCall`, if any, from the statement
$funcCall = $this->resolveFuncCall($Expression);
$funcCall = $this->resolveFuncCall($expression);

// Nothing to do if no `FuncCall` found
if (! $funcCall instanceof FuncCall) {
Expand All @@ -178,7 +173,7 @@ private function refactorStmt(Expression $Expression): ?array
return null;
}

$nodes = [$Expression];
$nodes = [$expression];
$nodes[] = new If_(
new NotIdentical(
new FuncCall(new Name('json_last_error')),
Expand Down Expand Up @@ -228,26 +223,18 @@ private function hasConstFetchInArgs(array $args, string $constName): bool
/**
* Search if a given constant is set within a `BitwiseOr`
*/
private function hasConstFetchInBitwiseOr(BitwiseOr $bitwiseOr, string $constName): bool
private function hasConstFetchInBitwiseOr(BitwiseOr $bitwiseOr, string $constantName): bool
{
$found = false;

foreach ([$bitwiseOr->left, $bitwiseOr->right] as $subNode) {
$found = match (true) {
$subNode instanceof BitwiseOr => (
$this->hasConstFetchInBitwiseOr($subNode, $constName)
),
$subNode instanceof ConstFetch => (
$this->getName($subNode) === $constName
),
default => false
};
if ($subNode instanceof BitwiseOr && $this->hasConstFetchInBitwiseOr($subNode, $constantName)) {
return true;
}

if ($found) {
break;
if ($subNode instanceof ConstFetch && $this->isName($subNode, $constantName)) {
return true;
}
}

return $found;
return false;
}
}