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
52 changes: 17 additions & 35 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,18 @@ PRs and issues are linked, so you can find more about it. Thanks to [ChangelogLi
- [#3134] Add DoctrineAnnotationParserSyncer to prevent doctrine/annotation constant by-value override
- [#3114] move property adding to PostRector
- [#3141] [PHPUnit 9.1] Add assertFileNotExists() method rename

### Changed
- [#3080] [CodeQuality] Add ArrayKeysAndInArrayToIssetRector
- [#3070] [DeadCode] Add empty() + count($values) > 0 checks to RemoveUnusedNonEmptyArrayBeforeForeachRector
- [#3068] [DeadCode] Add RemoveAssignOfVoidReturnFunctionRector
- [#3062] [DeadCode] Add RemoveUnusedFunctionRector
- [#3066] [DeadCode] Add RemoveUnusedNonEmptyArrayBeforeForeachRector
- [#3047] [PHPUnit] Add CreateMockToCreateStubRector
- [#3081] [TypeDeclaration] Add class method param type resolving by property
- [#3058] [PHP 7.4] Add default null type on properties
- [#3059] [PHP 7.4] Add restoration null default only
- [#3057] [PHP 7.4] Add id tag support + remove array on collection property
- [#3078] Add Safe 0.7 set
- [#3072] [PHP 8.0] Add StrContainsRector

- [#3111] [API] NodeRemovingCommander to PostRector
- [#3084] [Privatization] Privatize methods that are used only locally
Expand All @@ -129,39 +139,6 @@ PRs and issues are linked, so you can find more about it. Thanks to [ChangelogLi
- [#3128] Allow PHPStan generics
- [#3115] move node-replacing to PostRector
- [#3146] Make sure doctrine alias rector works in symfony controllers, Thanks to [@acrobat]

### Fixed

- [#3132] Fix Gedmo annotation printing
- [#3130] Fix missing array key in ArrayMergeOfNonArraysToSimpleArrayRector
- [#3096] Fix [@Route] localized paths
- [#3129] fix missing host at [@Route] annotation

### Removed

- [#3122] remove json rector dump formatter, not needed

<!-- dumped content end -->

## v0.7.17 - 2020-04-23

### Added

- [#3080] [CodeQuality] Add ArrayKeysAndInArrayToIssetRector
- [#3070] [DeadCode] Add empty() + count($values) > 0 checks to RemoveUnusedNonEmptyArrayBeforeForeachRector
- [#3068] [DeadCode] Add RemoveAssignOfVoidReturnFunctionRector
- [#3062] [DeadCode] Add RemoveUnusedFunctionRector
- [#3066] [DeadCode] Add RemoveUnusedNonEmptyArrayBeforeForeachRector
- [#3047] [PHPUnit] Add CreateMockToCreateStubRector
- [#3081] [TypeDeclaration] Add class method param type resolving by property
- [#3058] [PHP 7.4] Add default null type on properties
- [#3059] [PHP 7.4] Add restoration null default only
- [#3057] [PHP 7.4] Add id tag support + remove array on collection property
- [#3078] Add Safe 0.7 set
- [#3072] [PHP 8.0] Add StrContainsRector

### Changed

- [#3082] [CodeQuality] use array_key_exists instead of isset
- [#3056] [PHP 7.4] Improve TypedPropertyRector for Doctrine collection
- [#3051] improve GeneratedValueTagValueNode
Expand All @@ -181,9 +158,14 @@ PRs and issues are linked, so you can find more about it. Thanks to [ChangelogLi
- [#3077] Fix auto import
- [#3079] Fix annotation in requirements of [@Route]
- [#3064] [PHP 7.4] Fix ChangeReflectionTypeToStringToGetNameRector
- [#3132] Fix Gedmo annotation printing
- [#3130] Fix missing array key in ArrayMergeOfNonArraysToSimpleArrayRector
- [#3096] Fix [@Route] localized paths
- [#3129] fix missing host at [@Route] annotation

### Removed

- [#3122] remove json rector dump formatter, not needed
- [#3071] remove ctor dependency on property/assign removal
- [#3076] [PHP 8.0] drop preg_match support from StrContains, too vague

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@
"bin/rector dump-rectors > docs/AllRectorsOverview.md",
"bin/rector dump-nodes > docs/NodesOverview.md"
],
"rector-ci": "bin/rector process --config rector-ci.yaml --dry-run",
"rector-ci": "bin/rector process --config rector-ci.yaml --dry-run --ansi",
"rector": "bin/rector process --config rector-ci.yaml --ansi"
},
"config": {
Expand Down
1 change: 1 addition & 0 deletions config/set/php/php80.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
services:
Rector\Php80\Rector\FunctionLike\UnionTypesRector: null
Rector\Php80\Rector\NotIdentical\StrContainsRector: null
Rector\Php80\Rector\Identical\StrStartsWithRector: null
25 changes: 24 additions & 1 deletion docs/AllRectorsOverview.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# All 499 Rectors Overview
# All 500 Rectors Overview

- [Projects](#projects)
- [General](#general)
Expand Down Expand Up @@ -7872,6 +7872,29 @@ Replace strpos() !== false and strstr() with str_contains()

<br>

### `StrStartsWithRector`

- class: [`Rector\Php80\Rector\Identical\StrStartsWithRector`](/../master/rules/php80/src/Rector/Identical/StrStartsWithRector.php)
- [test fixtures](/../master/rules/php80/tests/Rector/Identical/StrStartsWithRector/Fixture)

Change helper functions to str_starts_with()

```diff
class SomeClass
{
public function run()
{
- $isMatch = substr($haystack, 0, strlen($needle)) === $needle;
+ $isMatch = str_starts_with($haystack, $needle);

- $isNotMatch = substr($haystack, 0, strlen($needle)) !== $needle;
+ $isMatch = ! str_starts_with($haystack, $needle);
}
}
```

<br>

### `UnionTypesRector`

- class: [`Rector\Php80\Rector\FunctionLike\UnionTypesRector`](/../master/rules/php80/src/Rector/FunctionLike/UnionTypesRector.php)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

use PhpParser\Node;
use PHPStan\Type\ObjectType;
use Rector\Core\Exception\ShouldNotHappenException;
use Rector\NodeTypeResolver\FileSystem\CurrentFileInfoProvider;
use Rector\NodeTypeResolver\Node\AttributeKey;
use Rector\PHPStan\Type\AliasedObjectType;
Expand Down Expand Up @@ -60,7 +59,7 @@ public function addUseImport(Node $positionNode, ObjectType $objectType): void
// fallback for freshly created Name nodes
$fileInfo = $this->currentFileInfoProvider->getSmartFileInfo();
if ($fileInfo === null) {
throw new ShouldNotHappenException();
return;
}
}

Expand Down
1 change: 0 additions & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -250,4 +250,3 @@ parameters:
- '#Method Rector\\Caching\\ChangedFilesDetector\:\:hashFile\(\) should return string but returns string\|false#'

- '#If condition is always false#'
- '#Parameter \#1 \$stmts of method Rector\\Core\\PhpParser\\Printer\\BetterStandardPrinter\:\:prettyPrintFile\(\) expects array<PhpParser\\Node\>, PhpParser\\Node\\Stmt\\Class_\|PhpParser\\Node\\Stmt\\Namespace_ given#'
2 changes: 2 additions & 0 deletions rector.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ parameters:
# bleeding edge feature
is_cache_enabled: true

auto_import_names: true

paths:
- src
- tests
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ private function createInArrayFunction(Node $node, BinaryOp $binaryOp, Foreach_
$arguments[] = $this->createArg($this->createTrue());
}

return $this->createFunction('in_array', $arguments);
return $this->createFuncCall('in_array', $arguments);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,6 @@ public function refactor(Node $node): ?Node
return $node;
}

return $this->createFunction('func_num_args');
return $this->createFuncCall('func_num_args');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ function (Node $node): bool {
/** @var ConstFetch $boolConstFetch */
[$arraySearchFuncCall, $boolConstFetch] = $matchedNodes;

$inArrayFuncCall = $this->createFunction('in_array', [
$inArrayFuncCall = $this->createFuncCall('in_array', [
$arraySearchFuncCall->args[0],
$arraySearchFuncCall->args[1],
]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,6 @@ public function refactor(Node $node): ?Node
$args = [];
$args[] = new Arg($node->args[1]->value, false, true);

return $this->createFunction($functionName, $args);
return $this->createFuncCall($functionName, $args);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function refactor(Node $node): ?Node
if (array_key_exists($classname, $this->getClassmap())) {
$newClassname = new ClassConstFetch(new FullyQualified($this->getClassmap()[$classname]), 'class');

return $this->createFunction('oxNew', array_merge([$newClassname], $arguments));
return $this->createFuncCall('oxNew', array_merge([$newClassname], $arguments));
}

return $node;
Expand Down
4 changes: 2 additions & 2 deletions rules/php70/src/Rector/FuncCall/EregToPregMatchRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ private function processStringPattern(FuncCall $funcCall, String_ $patternNode,

private function processVariablePattern(FuncCall $funcCall, Variable $variable, string $functionName): void
{
$pregQuotePatternNode = $this->createFunction('preg_quote', [
$pregQuotePatternNode = $this->createFuncCall('preg_quote', [
new Arg($variable),
new Arg(new String_('#')),
]);
Expand Down Expand Up @@ -161,7 +161,7 @@ private function processSplitLimitArgument(FuncCall $funcCall, string $functionN
private function createTernaryWithStrlenOfFirstMatch(FuncCall $funcCall): Ternary
{
$arrayDimFetch = new ArrayDimFetch($funcCall->args[2]->value, new LNumber(0));
$strlenFuncCall = $this->createFunction('strlen', [$arrayDimFetch]);
$strlenFuncCall = $this->createFuncCall('strlen', [$arrayDimFetch]);

return new Ternary($funcCall, $strlenFuncCall, $this->createFalse());
}
Expand Down
2 changes: 1 addition & 1 deletion rules/php70/src/Rector/FuncCall/RandomFunctionRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function refactor(Node $node): ?Node
// special case: random_int(); → random_int(0, getrandmax());
if ($newFunctionName === 'random_int' && count($node->args) === 0) {
$node->args[0] = new Arg(new LNumber(0));
$node->args[1] = new Arg($this->createFunction('mt_getrandmax'));
$node->args[1] = new Arg($this->createFuncCall('mt_getrandmax'));
}

return $node;
Expand Down
2 changes: 1 addition & 1 deletion rules/php70/src/Rector/List_/ListSplitStringRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function refactor(Node $node): ?Node
return null;
}

$node->expr = $this->createFunction('str_split', [$node->expr]);
$node->expr = $this->createFuncCall('str_split', [$node->expr]);

return $node;
}
Expand Down
2 changes: 1 addition & 1 deletion rules/php70/src/Rector/List_/ListSwapArrayOrderRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public function refactor(Node $node): ?Node
}

// wrap with array_reverse, to reflect reverse assign order in left
$node->expr = $this->createFunction('array_reverse', [$node->expr]);
$node->expr = $this->createFuncCall('array_reverse', [$node->expr]);

return $node;
}
Expand Down
2 changes: 1 addition & 1 deletion rules/php71/src/Rector/FuncCall/CountOnNullRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public function refactor(Node $node): ?Node
$conditionNode = new FuncCall(new Name('is_countable'), [new Arg($countedNode)]);
} else {
$conditionNode = new BooleanOr(
$this->createFunction('is_array', [new Arg($countedNode)]),
$this->createFuncCall('is_array', [new Arg($countedNode)]),
new Instanceof_($countedNode, new FullyQualified('Countable'))
);
}
Expand Down
12 changes: 6 additions & 6 deletions rules/php72/src/Rector/Each/ListEachRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,16 @@ public function refactor(Node $node): ?Node

// only key: list($key, ) = each($values);
if ($listNode->items[0] && $listNode->items[1] === null) {
$keyFuncCall = $this->createFunction('key', $eachFuncCall->args);
$keyFuncCall = $this->createFuncCall('key', $eachFuncCall->args);
return new Assign($listNode->items[0]->value, $keyFuncCall);
}

// only value: list(, $value) = each($values);
if ($listNode->items[1] && $listNode->items[0] === null) {
$nextFuncCall = $this->createFunction('next', $eachFuncCall->args);
$nextFuncCall = $this->createFuncCall('next', $eachFuncCall->args);
$this->addNodeAfterNode($nextFuncCall, $node);

$currentFuncCall = $this->createFunction('current', $eachFuncCall->args);
$currentFuncCall = $this->createFuncCall('current', $eachFuncCall->args);
return new Assign($listNode->items[1]->value, $currentFuncCall);
}

Expand All @@ -93,16 +93,16 @@ public function refactor(Node $node): ?Node
// $key = key($values);
// $value = current($values);
// next($values); - only inside a loop
$currentFuncCall = $this->createFunction('current', $eachFuncCall->args);
$currentFuncCall = $this->createFuncCall('current', $eachFuncCall->args);
$assignCurrentNode = new Assign($listNode->items[1]->value, $currentFuncCall);
$this->addNodeAfterNode($assignCurrentNode, $node);

if ($this->isInsideDoWhile($node)) {
$nextFuncCall = $this->createFunction('next', $eachFuncCall->args);
$nextFuncCall = $this->createFuncCall('next', $eachFuncCall->args);
$this->addNodeAfterNode($nextFuncCall, $node);
}

$keyFuncCall = $this->createFunction('key', $eachFuncCall->args);
$keyFuncCall = $this->createFuncCall('key', $eachFuncCall->args);
return new Assign($listNode->items[0]->value, $keyFuncCall);
}

Expand Down
2 changes: 1 addition & 1 deletion rules/php72/src/Rector/Each/WhileEachToForeachRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public function refactor(Node $node): ?Node
/** @var List_ $listNode */
$listNode = $assignNode->var;

$foreachedExpr = count($listNode->items) === 1 ? $this->createFunction(
$foreachedExpr = count($listNode->items) === 1 ? $this->createFuncCall(
'array_keys',
[$eachFuncCall->args[0]]
) : $eachFuncCall->args[0]->value;
Expand Down
2 changes: 1 addition & 1 deletion rules/php72/src/Rector/Unset_/UnsetCastRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function refactor(Node $node): ?Node
$unset = $node->expr;

if ($this->areNodesEqual($node->var, $unset->expr)) {
return $this->createFunction('unset', [$node->var]);
return $this->createFuncCall('unset', [$node->var]);
}
}

Expand Down
10 changes: 10 additions & 0 deletions rules/php80/config/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
services:
_defaults:
public: true
autowire: true

Rector\Php80\:
resource: '../src'
exclude:
- '../src/Rector/**/*Rector.php'
- '../src/ValueObject/*'
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

declare(strict_types=1);

namespace Rector\Php80\MatchAndRefactor\StrStartsWithMatchAndRefactor;

use PhpParser\Node;
use PhpParser\Node\Expr\FuncCall;
use Rector\Core\PhpParser\Node\Value\ValueResolver;
use Rector\Core\PhpParser\Printer\BetterStandardPrinter;
use Rector\NodeNameResolver\NodeNameResolver;

abstract class AbstractMatchAndRefactor
{
/**
* @var NodeNameResolver
*/
protected $nodeNameResolver;

/**
* @var ValueResolver
*/
protected $valueResolver;

/**
* @var BetterStandardPrinter
*/
protected $betterStandardPrinter;

/**
* @required
*/
public function autowireAbstractMatchAndRefactor(
NodeNameResolver $nodeNameResolver,
ValueResolver $valueResolver,
BetterStandardPrinter $betterStandardPrinter
): void {
$this->nodeNameResolver = $nodeNameResolver;
$this->valueResolver = $valueResolver;
$this->betterStandardPrinter = $betterStandardPrinter;
}

protected function isFuncCallName(Node $node, string $name): bool
{
if (! $node instanceof FuncCall) {
return false;
}

return $this->nodeNameResolver->isName($node, $name);
}
}
Loading