Skip to content
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
4 changes: 2 additions & 2 deletions packages/Testing/PHPUnit/AbstractTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,11 @@ protected function getService(string $type): object

try {
$object = self::$currentContainer->get($type);
} catch (Throwable $e) {
} catch (Throwable $throwable) {
// clear compiled container cache, to trigger re-discovery
RectorKernel::clearCache();

throw $e;
throw $throwable;
}

if ($object === null) {
Expand Down
5 changes: 5 additions & 0 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Rector\Naming\Rector\Foreach_\RenameForeachValueVariableToMatchExprVariableRector;
use Rector\Php55\Rector\String_\StringClassNameToClassConstantRector;
use Rector\PHPUnit\Set\PHPUnitSetList;
use Rector\Privatization\Rector\Property\ChangeReadOnlyPropertyWithDefaultValueToConstantRector;
use Rector\Set\ValueObject\LevelSetList;
use Rector\Set\ValueObject\SetList;
use Rector\TypeDeclaration\Rector\StmtsAwareInterface\DeclareStrictTypesRector;
Expand Down Expand Up @@ -87,6 +88,10 @@
\Rector\TypeDeclaration\Rector\ClassMethod\AddMethodCallBasedStrictParamTypeRector::class => [
__DIR__ . '/rules/DeadCode/Rector/If_/RemoveUnusedNonEmptyArrayBeforeForeachRector.php',
],

ChangeReadOnlyPropertyWithDefaultValueToConstantRector::class => [
__DIR__ . '/src/Kernel/RectorKernel.php',
],
]);

$rectorConfig->phpstanConfig(__DIR__ . '/phpstan-for-rector.neon');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Rector\EarlyReturn\Rector\Return_;

use PHPStan\Analyser\Scope;
use PhpParser\Node;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\BinaryOp\BooleanAnd;
Expand Down Expand Up @@ -72,7 +73,7 @@ public function getNodeTypes(): array
* @param Return_ $node
* @return null|Node[]
*/
public function refactorWithScope(Node $node, \PHPStan\Analyser\Scope $scope): ?array
public function refactorWithScope(Node $node, Scope $scope): ?array
{
if (! $node->expr instanceof BooleanOr) {
return null;
Expand Down
13 changes: 3 additions & 10 deletions src/Kernel/RectorKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,13 @@ final class RectorKernel
/**
* @var string
*/
private const CACHE_KEY = 'v7';
private const CACHE_KEY = 'v8';
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@staabm I increased the cache key, let see if it resolve the test error 👍

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@staabm it works 🎉


private ContainerInterface|null $container = null;

private bool $dumpFileCache = false;

/**
* @var string|null
*/
private static $defaultFilesHash;
private static ?string $defaultFilesHash = null;

public function __construct()
{
Expand Down Expand Up @@ -55,11 +52,7 @@ public function createFromConfigs(array $configFiles): ContainerInterface
return $this->buildContainer([]);
}

if ($this->dumpFileCache) {
$container = $this->buildCachedContainer($configFiles);
} else {
$container = $this->buildContainer($configFiles);
}
$container = $this->dumpFileCache ? $this->buildCachedContainer($configFiles) : $this->buildContainer($configFiles);

return $this->container = $container;
}
Expand Down
1 change: 0 additions & 1 deletion src/PhpParser/Node/AssignAndBinaryMap.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
use PhpParser\Node\Expr\BooleanNot;
use PhpParser\Node\Expr\Cast\Bool_;
use PHPStan\Analyser\Scope;
use Rector\NodeTypeResolver\Node\AttributeKey;

final class AssignAndBinaryMap
{
Expand Down
18 changes: 12 additions & 6 deletions src/PhpParser/Parser/InlineCodeParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
use Nette\Utils\Strings;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\BinaryOp\Concat;
use PhpParser\Node\Expr\Variable;
use PhpParser\Node\Scalar\Encapsed;
use PhpParser\Node\Scalar\String_;
use PhpParser\Node\Stmt;
use Rector\Core\Contract\PhpParser\NodePrinterInterface;
use Rector\Core\PhpParser\Node\Value\ValueResolver;
use Rector\Core\Provider\CurrentFileProvider;
use Rector\Core\Util\StringUtils;
use Rector\NodeTypeResolver\Node\AttributeKey;
use Rector\Core\ValueObject\Application\File;

final class InlineCodeParser
{
Expand Down Expand Up @@ -64,7 +64,8 @@ final class InlineCodeParser
public function __construct(
private readonly NodePrinterInterface $nodePrinter,
private readonly SimplePhpParser $simplePhpParser,
private readonly ValueResolver $valueResolver
private readonly ValueResolver $valueResolver,
private readonly CurrentFileProvider $currentFileProvider
) {
}

Expand Down Expand Up @@ -146,9 +147,14 @@ private function resolveConcatValue(Concat $concat): string
$concat->right->value = '.' . $concat->right->value;
}

if ($concat->right instanceof String_ && str_starts_with($concat->right->value, '($')) {
$node = $concat->getAttribute(AttributeKey::NEXT_NODE);
if ($node instanceof Variable) {
$file = $this->currentFileProvider->getFile();
if ($concat->right instanceof String_ &&
str_starts_with($concat->right->value, '($')
&& $file instanceof File) {
$oldTokens = $file->getOldTokens();
$endTokenPos = $concat->right->getEndTokenPos();

if (isset($oldTokens[$endTokenPos][1]) && str_starts_with((string) $oldTokens[$endTokenPos][1], "'($")) {
$concat->right->value .= '.';
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ final class ConfigurableArrayMissingTest extends AbstractTestCase
protected function setUp(): void
{
$rectorKernel = new RectorKernel();
$container = $rectorKernel->createBuilder([__DIR__ . '/config/configurable_array_missing.php']);
$this->emptyConfigurableRectorCollector = $container->get(EmptyConfigurableRectorCollector::class);
$containerBuilder = $rectorKernel->createBuilder([__DIR__ . '/config/configurable_array_missing.php']);
$this->emptyConfigurableRectorCollector = $containerBuilder->get(EmptyConfigurableRectorCollector::class);
}

public function test(): void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ final class EmptyConfigurableRectorCollectorTest extends AbstractTestCase
protected function setUp(): void
{
$rectorKernel = new RectorKernel();
$container = $rectorKernel->createBuilder([__DIR__ . '/config/configurable_array_has_values.php']);
$this->emptyConfigurableRectorCollector = $container->get(EmptyConfigurableRectorCollector::class);
$containerBuilder = $rectorKernel->createBuilder([__DIR__ . '/config/configurable_array_has_values.php']);
$this->emptyConfigurableRectorCollector = $containerBuilder->get(EmptyConfigurableRectorCollector::class);
}

public function test(): void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ final class EmptyConfigureTest extends AbstractTestCase
protected function setUp(): void
{
$rectorKernel = new RectorKernel();
$container = $rectorKernel->createBuilder([__DIR__ . '/config/empty_configure.php']);
$this->emptyConfigurableRectorCollector = $container->get(EmptyConfigurableRectorCollector::class);
$containerBuilder = $rectorKernel->createBuilder([__DIR__ . '/config/empty_configure.php']);
$this->emptyConfigurableRectorCollector = $containerBuilder->get(EmptyConfigurableRectorCollector::class);
}

public function test(): void
Expand Down