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

Update to PHPStan 0.12.9 and fix scoping deps #2800

Merged
merged 6 commits into from
Feb 6, 2020
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
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# temporary disabled till PHPStan autolaod bug is fixed
# https://github.com/rectorphp/rector/pull/2800
name: Test With Doctrine

on:
Expand Down Expand Up @@ -27,6 +29,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
Expand Down
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
5 changes: 5 additions & 0 deletions compiler/build/scoper.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@
->in(__DIR__ . '/../../vendor/jetbrains/phpstorm-stubs');

foreach ($stubFinder->getIterator() as $fileInfo) {
// mirrors https://github.com/phpstan/phpstan-src/commit/04f777bc4445725d17dac65c989400485454b145
if ($file->getPathName() === '../../vendor/jetbrains/phpstorm-stubs/PhpStormStubsMap.php') {
continue;
}

/** @var SplFileInfo $fileInfo */
$stubs[] = $fileInfo->getPathName();
}
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"nikic/php-parser": "^4.3",
"ondram/ci-detector": "^3.1",
"phpstan/phpdoc-parser": "^0.4",
"phpstan/phpstan": "0.12.7",
"phpstan/phpstan": "^0.12.9",
"phpstan/phpstan-phpunit": "^0.12",
"sebastian/diff": "^3.0",
"symfony/console": "^4.4|^5.0",
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);
}
}
2 changes: 2 additions & 0 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

require_once __DIR__ . '/../vendor/autoload.php';

require_once 'phar://vendor/phpstan/phpstan/phpstan.phar/vendor/jetbrains/phpstorm-stubs/PhpStormStubsMap.php';

// silent deprecations, since we test them
error_reporting(E_ALL ^ E_DEPRECATED);

Expand Down