Skip to content

Commit 4c62ddb

Browse files
committed
misc
1 parent 22bc586 commit 4c62ddb

2 files changed

Lines changed: 13 additions & 13 deletions

File tree

README.md

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,10 @@ composer require rector/rector --dev
1919
To add a set to your config, use `Rector\Set\ValueObject\DowngradeLevelSetList` class and pick target set:
2020

2121
```php
22-
use Rector\Set\ValueObject\DowngradeLevelSetList;
2322
use Rector\Config\RectorConfig;
2423

25-
return static function (RectorConfig $rectorConfig): void {
26-
$rectorConfig->sets([
27-
DowngradeLevelSetList::DOWN_TO_PHP_72
28-
]);
29-
};
24+
return RectorConfig::configure()
25+
->withDowngradeSets(php74: true);
3026
```
3127

3228
Then run Rector to downgrade your code to PHP 7.2!

rules/DowngradePhp73/Rector/ConstFetch/DowngradePhp73JsonConstRector.php

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,12 @@ public function getRuleDefinition(): RuleDefinition
6363
CODE_SAMPLE
6464
,
6565
<<<'CODE_SAMPLE'
66-
$json json_encode($content, 0);
66+
$json = json_encode($content);
6767
if (json_last_error() !== JSON_ERROR_NONE) {
6868
throw new \Exception(json_last_error_msg());
6969
}
7070
71-
$content = json_decode($json, null, 512, 0);
71+
$content = json_decode($json, null, 512);
7272
if (json_last_error() !== JSON_ERROR_NONE) {
7373
throw new \Exception(json_last_error_msg());
7474
}
@@ -149,22 +149,26 @@ private function resolveFuncCall(Expression $Expression): ?FuncCall
149149
*
150150
* @return null|array<Expression|If_>
151151
*/
152-
private function refactorStmt(Expression $Expression): ?array
152+
private function refactorStmt(Expression $expression): ?array
153153
{
154-
if ($Expression->getAttribute(AttributeKey::IS_IN_TRY_BLOCK) === true) {
154+
if ($expression->getAttribute(AttributeKey::IS_IN_TRY_BLOCK) === true) {
155155
return null;
156156
}
157157

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

161161
// Nothing to do if no `FuncCall` found
162162
if (! $funcCall instanceof FuncCall) {
163163
return null;
164164
}
165165

166+
if ($funcCall->isFirstClassCallable()) {
167+
return null;
168+
}
169+
166170
// Nothing to do if not a refactored function
167-
if (! in_array($this->getName($funcCall), self::REFACTOR_FUNCS, true)) {
171+
if (! $this->isNames($funcCall, self::REFACTOR_FUNCS)) {
168172
return null;
169173
}
170174

@@ -173,7 +177,7 @@ private function refactorStmt(Expression $Expression): ?array
173177
return null;
174178
}
175179

176-
$nodes = [$Expression];
180+
$nodes = [$expression];
177181
$nodes[] = new If_(
178182
new NotIdentical(
179183
new FuncCall(new Name('json_last_error')),

0 commit comments

Comments
 (0)