Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix name resolution in ArrayKeyFirstLastRector #2489

Merged
merged 1 commit into from
Dec 26, 2019
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
10 changes: 8 additions & 2 deletions packages/Php73/src/Rector/FuncCall/ArrayKeyFirstLastRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Rector\Rector\AbstractRector;
use Rector\RectorDefinition\CodeSample;
use Rector\RectorDefinition\RectorDefinition;
use Rector\ValueObject\PhpVersionFeature;

/**
* @see https://www.tomasvotruba.cz/blog/2018/08/16/whats-new-in-php-73-in-30-seconds-in-diffs/#2-first-and-last-array-key
Expand Down Expand Up @@ -121,13 +122,18 @@ public function refactor(Node $node): ?Node

private function shouldSkip(FuncCall $funcCall): bool
{
if ($this->isAtLeastPhpVersion('7.3')) {
if (! $this->isNames($funcCall, ['reset', 'end'])) {
return true;
}

if ($this->isAtLeastPhpVersion(PhpVersionFeature::ARRAY_KEY_FIRST_LAST)) {
return false;
}

if (function_exists(self::ARRAY_KEY_FIRST) && function_exists(self::ARRAY_KEY_LAST)) {
return false;
}
return $this->isNames($funcCall, ['reset', 'end']);

return true;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace Rector\Php73\Tests\Rector\FuncCall\ArrayKeyFirstLastRector\Fixture;

class SkipOtherFunctionName
{
public function run()
{
$a = [];
ksort($a);
key($a);
}
}
5 changes: 5 additions & 0 deletions src/ValueObject/PhpVersionFeature.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ final class PhpVersionFeature
*/
public const IS_COUNTABLE = '7.3';

/**
* @var string
*/
public const ARRAY_KEY_FIRST_LAST = '7.3';

/**
* @var string
*/
Expand Down