Skip to content

Commit

Permalink
[Naming] Keep underscore in RenameForeachValueVariableToMatchExprVari…
Browse files Browse the repository at this point in the history
…ableRector (#236)
  • Loading branch information
samsonasik committed Jun 17, 2021
1 parent 5e6a011 commit 6c3a521
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

namespace Rector\Tests\Naming\Rector\Foreach_\RenameForeachValueVariableToMatchExprVariableRector\Fixture;

class KeepUnderscore
{
public function run()
{
$customer_names = [];
foreach ($customer_names as $customer_name) {
echo $customer_name;
}
}
}

?>
-----
<?php

namespace Rector\Tests\Naming\Rector\Foreach_\RenameForeachValueVariableToMatchExprVariableRector\Fixture;

class KeepUnderscore
{
public function run()
{
$customer_names = [];
foreach ($customer_names as $customer_name) {
echo $customer_name;
}
}
}

?>
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ final class InflectorSingularResolver

/**
* @var string
* @see https://regex101.com/r/lbQaGC/1
* @see https://regex101.com/r/lbQaGC/3
*/
private const CAMELCASE_REGEX = '#(?<camelcase>([a-z]+|[A-Z]{1,}[a-z]+))#';
private const CAMELCASE_REGEX = '#(?<camelcase>([a-z]+|[A-Z]{1,}[a-z]+|_))#';

/**
* @var string
Expand Down Expand Up @@ -64,7 +64,7 @@ public function resolve(string $currentName): string
$singularValueVarName .= $this->inflector->singularize($camelCase['camelcase']);
}

if ($singularValueVarName === '') {
if ($singularValueVarName === '' || $singularValueVarName === '_') {
return $currentName;
}

Expand Down

0 comments on commit 6c3a521

Please sign in to comment.