add slash to repeated literal to class constant

This commit is contained in:
TomasVotruba 2020-05-09 21:33:17 +02:00
parent f229a7a3f5
commit 83ef24bd9d
2 changed files with 41 additions and 2 deletions

View File

@ -182,7 +182,7 @@ PHP
}
// is replaceable value?
$matches = Strings::match($value, '#(?<' . self::VALUE . '>[\w\-_]+)#');
$matches = Strings::match($value, '#(?<' . self::VALUE . '>[\w\-\/\\_]+)#');
if (! isset($matches[self::VALUE])) {
return true;
}
@ -199,7 +199,7 @@ PHP
private function createConstName(string $value): string
{
$value = StaticRectorStrings::camelCaseToUnderscore($value);
$value = Strings::replace($value, '#-#', '_');
$value = Strings::replace($value, '#[-\\\/]#', '_');
return strtoupper($value);
}

View File

@ -0,0 +1,39 @@
<?php
namespace Rector\SOLID\Tests\Rector\Class_\RepeatedLiteralToClassConstantRector\Fixture;
class WithSlash
{
public function run($key, $items)
{
if ($key === 'phpstan/phpstan') {
return $items['phpstan/phpstan'];
}
return $items['phpstan/phpstan'];
}
}
?>
-----
<?php
namespace Rector\SOLID\Tests\Rector\Class_\RepeatedLiteralToClassConstantRector\Fixture;
class WithSlash
{
/**
* @var string
*/
private const PHPSTAN_PHPSTAN = 'phpstan/phpstan';
public function run($key, $items)
{
if ($key === self::PHPSTAN_PHPSTAN) {
return $items[self::PHPSTAN_PHPSTAN];
}
return $items[self::PHPSTAN_PHPSTAN];
}
}
?>