fix array expr

This commit is contained in:
TomasVotruba 2020-02-06 01:15:14 +01:00
parent e706559d1f
commit 3b2cfbf2c7
4 changed files with 23 additions and 11 deletions

View File

@ -27,6 +27,7 @@ jobs:
# remove phsptan config to prevent rector loading configs
rm phpstan.neon
rm orm/phpstan.neon.dist
# do not intall doctrine/orm phpstan, it conflicts with Retor's one
composer install -d orm --no-dev

View File

@ -19,7 +19,8 @@ error_reporting(E_ALL);
ini_set('display_errors', 'stderr');
gc_disable();
define('__RECTOR_RUNNING__', true);
// temporary hackaround
@include_once 'phar://vendor/phpstan/phpstan/phpstan.phar/vendor/jetbrains/phpstorm-stubs/PhpStormStubsMap.php';
// Require Composer autoload.php
$autoloadIncluder = new AutoloadIncluder();

View File

@ -5,6 +5,7 @@ declare(strict_types=1);
namespace Rector\CakePHP\Rector\Name;
use PhpParser\Node;
use PhpParser\Node\Expr\Array_;
use PhpParser\Node\Scalar\String_;
use PhpParser\Node\Stmt\Property;
use Rector\NodeTypeResolver\Node\AttributeKey;
@ -13,6 +14,8 @@ use Rector\RectorDefinition\CodeSample;
use Rector\RectorDefinition\RectorDefinition;
/**
* @see \Rector\CakePHP\Tests\Rector\Name\ChangeSnakedFixtureNameToCamel\ChangeSnakedFixtureNameToCamelTest
*
* @see https://book.cakephp.org/3.0/en/appendices/3-7-migration-guide.html
*/
final class ChangeSnakedFixtureNameToCamelRector extends AbstractRector
@ -62,21 +65,27 @@ PHP
return null;
}
foreach ($node->props as $i => $prop) {
if (! isset($prop->default->items)) {
foreach ($node->props as $prop) {
if (! $prop->default instanceof Array_) {
continue;
}
foreach ($prop->default->items as $j => $item) {
$node->props[$i]->default->items[$j]->value = $this->renameFixtureName($item->value);
foreach ($prop->default->items as $item) {
if (! $item->value instanceof String_) {
continue;
}
$this->renameFixtureName($item->value);
}
}
return $node;
}
private function renameFixtureName(String_ $name): String_
private function renameFixtureName(String_ $string): void
{
[$prefix, $table] = explode('.', $name->value);
[$prefix, $table] = explode('.', $string->value);
$table = array_map(
function ($token): string {
$tokens = explode('_', $token);
@ -85,8 +94,9 @@ PHP
},
explode('/', $table)
);
$table = implode('/', $table);
return new String_(sprintf('%s.%s', $prefix, $table), $name->getAttributes());
$string->value = sprintf('%s.%s', $prefix, $table);
}
}

View File

@ -6,9 +6,9 @@ parameters:
- 'nette-utils-code-quality'
paths:
- 'src'
- 'packages'
- 'tests'
- 'src/Application'
# - 'packages'
# - 'tests'
exclude_paths:
- '/Fixture/'