Skip to content

Commit

Permalink
fix array expr
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasVotruba committed Feb 6, 2020
1 parent e706559 commit cd76d98
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 11 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/test_with_doctrine.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,7 @@ jobs:
# do not intall doctrine/orm phpstan, it conflicts with Retor's one
composer install -d orm --no-dev
# remove phpstan/phpstan to prevent autolaod conflicts
composer remove phpstan/phpstan -d orm
- run: bin/rector process orm/lib --set dead-code --autoload-file orm/vendor/autoload.php
3 changes: 2 additions & 1 deletion bin/rector
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
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;
Expand All @@ -13,6 +14,8 @@
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
Expand Down Expand Up @@ -62,21 +65,27 @@ public function refactor(Node $node): ?Node
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);
Expand All @@ -85,8 +94,9 @@ function ($token): string {
},
explode('/', $table)
);

$table = implode('/', $table);

return new String_(sprintf('%s.%s', $prefix, $table), $name->getAttributes());
$string->value = sprintf('%s.%s', $prefix, $table);
}
}
6 changes: 3 additions & 3 deletions rector-ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ parameters:
- 'nette-utils-code-quality'

paths:
- 'src'
- 'packages'
- 'tests'
- 'src/Application'
# - 'packages'
# - 'tests'

exclude_paths:
- '/Fixture/'
Expand Down

0 comments on commit cd76d98

Please sign in to comment.