Skip to content

Commit

Permalink
use php version right in config
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasVotruba committed Feb 9, 2021
1 parent 495b778 commit 698a3a4
Show file tree
Hide file tree
Showing 152 changed files with 466 additions and 2,625 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/code_analysis.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ jobs:

-
name: 'PHP Linter'
run: vendor/bin/parallel-lint src bin/rector config tests packages rules --colors --exclude packages/rector-generator/templates --exclude rules/psr4/tests/Rector/Namespace_/MultipleClassFileToPsr4ClassesRector/Source --exclude rules/autodiscovery/tests/Rector/FileNode/MoveInterfacesToContractNamespaceDirectoryRector/Expected --exclude packages/node-type-resolver/tests/PerNodeTypeResolver/PropertyFetchTypeResolver/Source/ClassWithNativeProps.php --exclude packages/node-type-resolver/tests/PerNodeTypeResolver/PropertyFetchTypeResolver/Source/ClassWithNativePropsPhp80.php --exclude packages/node-type-resolver/tests/PerNodeTypeResolver/PropertyFetchTypeResolver/Source/ClassWithTypedPropertyTypes.php
run: vendor/bin/parallel-lint src bin/rector config tests packages rules --colors --exclude packages/rector-generator/templates --exclude rules/psr4/tests/Rector/Namespace_/MultipleClassFileToPsr4ClassesRector/Source --exclude rules/autodiscovery/tests/Rector/FileNode/MoveInterfacesToContractNamespaceDirectoryRector/Expected --exclude packages/node-type-resolver/tests/PerNodeTypeResolver/PropertyFetchTypeResolver/Source/ClassWithNativeProps.php --exclude packages/node-type-resolver/tests/PerNodeTypeResolver/PropertyFetchTypeResolver/Source/ClassWithNativePropsPhp80.php --exclude packages/node-type-resolver/tests/PerNodeTypeResolver/PropertyFetchTypeResolver/Source/ClassWithTypedPropertyTypes.php --exclude rules/nette-kdyby/tests/Rector/MethodCall/ReplaceEventManagerWithEventSubscriberRector/Source/ExpectedSomeClassCopyEvent.php --exclude rules/nette-kdyby/tests/Rector/MethodCall/ReplaceMagicPropertyEventWithEventClassRector/Source/ExpectedFileManagerUploadEvent.php --exclude rules/nette-kdyby/tests/Rector/MethodCall/ReplaceMagicPropertyEventWithEventClassRector/Source/ExpectedDuplicatedEventParamsUploadEvent.php

name: ${{ matrix.actions.name }}
runs-on: ubuntu-latest
Expand Down
4 changes: 0 additions & 4 deletions packages/caching/tests/Detector/ChangedFilesDetectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ protected function setUp(): void

protected function tearDown(): void
{
parent::tearDown();

$this->changedFilesDetector->clear();
}

Expand All @@ -35,11 +33,9 @@ public function testHasFileChanged(): void
$smartFileInfo = new SmartFileInfo(__DIR__ . '/Source/file.php');

$this->assertTrue($this->changedFilesDetector->hasFileChanged($smartFileInfo));

$this->changedFilesDetector->addFileWithDependencies($smartFileInfo, []);

$this->assertFalse($this->changedFilesDetector->hasFileChanged($smartFileInfo));

$this->changedFilesDetector->invalidateFile($smartFileInfo);

$this->assertTrue($this->changedFilesDetector->hasFileChanged($smartFileInfo));
Expand Down
37 changes: 5 additions & 32 deletions packages/testing/src/PHPUnit/AbstractRectorTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
use Rector\Core\NonPhpFile\NonPhpFileProcessor;
use Rector\Core\PhpParser\Printer\BetterStandardPrinter;
use Rector\Core\Stubs\StubLoader;
use Rector\Core\ValueObject\PhpVersion;
use Rector\Core\ValueObject\StaticNonPhpFileSuffixes;
use Rector\Testing\Application\EnabledRectorsProvider;
use Rector\Testing\Contract\RunnableInterface;
Expand All @@ -41,11 +40,6 @@ abstract class AbstractRectorTestCase extends AbstractKernelTestCase
{
use MovingFilesTrait;

/**
* @var int
*/
private const PHP_VERSION_UNDEFINED = 0;

/**
* @var FileProcessor
*/
Expand All @@ -71,11 +65,6 @@ abstract class AbstractRectorTestCase extends AbstractKernelTestCase
*/
protected $runnableRectorFactory;

/**
* @var NodeScopeResolver
*/
protected $nodeScopeResolver;

/**
* @var FixtureGuard
*/
Expand Down Expand Up @@ -157,11 +146,6 @@ protected function setUp(): void
$this->betterStandardPrinter = $this->getService(BetterStandardPrinter::class);
$this->removedAndAddedFilesCollector = $this->getService(RemovedAndAddedFilesCollector::class);
$this->removedAndAddedFilesCollector->reset();

// needed for PHPStan, because the analyzed file is just create in /temp
$this->nodeScopeResolver = $this->getService(NodeScopeResolver::class);

$this->configurePhpVersionFeatures();
}

protected function getRectorClass(): string
Expand Down Expand Up @@ -194,12 +178,6 @@ protected function yieldFilesFromDirectory(string $directory, string $suffix = '
return StaticFixtureFinder::yieldDirectory($directory, $suffix);
}

protected function getPhpVersion(): int
{
// default value to be implemented for testing lower versions
return PhpVersion::PHP_10;
}

protected function doTestFileInfoWithoutAutoload(SmartFileInfo $fileInfo): void
{
$this->autoloadTestFixture = false;
Expand All @@ -220,7 +198,11 @@ protected function doTestFileInfo(SmartFileInfo $fixtureFileInfo, array $extraFi
);

$inputFileInfo = $inputFileInfoAndExpectedFileInfo->getInputFileInfo();
$this->nodeScopeResolver->setAnalysedFiles([$inputFileInfo->getRealPath()]);

// needed for PHPStan, because the analyzed file is just create in /temp
/** @var NodeScopeResolver $nodeScopeResolver */
$nodeScopeResolver = $this->getService(NodeScopeResolver::class);
$nodeScopeResolver->setAnalysedFiles([$inputFileInfo->getRealPath()]);

$expectedFileInfo = $inputFileInfoAndExpectedFileInfo->getExpectedFileInfo();

Expand Down Expand Up @@ -341,15 +323,6 @@ private function configureEnabledRectors(EnabledRectorsProvider $enabledRectorsP
}
}

private function configurePhpVersionFeatures(): void
{
if ($this->getPhpVersion() === self::PHP_VERSION_UNDEFINED) {
return;
}

$this->parameterProvider->changeParameter(Option::PHP_VERSION_FEATURES, $this->getPhpVersion());
}

private function ensureRectorClassIsValid(string $rectorClass, string $methodName): void
{
if (is_a($rectorClass, PhpRectorInterface::class, true)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

use Iterator;
use Rector\Autodiscovery\Rector\FileNode\MoveEntitiesToEntityDirectoryRector;
use Rector\Core\ValueObject\PhpVersionFeature;
use Rector\FileSystemRector\ValueObject\AddedFileWithContent;
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
use Symplify\SmartFileSystem\SmartFileInfo;
Expand Down Expand Up @@ -42,9 +41,4 @@ protected function getRectorClass(): string
{
return MoveEntitiesToEntityDirectoryRector::class;
}

protected function getPhpVersion(): int
{
return PhpVersionFeature::TYPED_PROPERTIES - 1;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
namespace Rector\Autodiscovery\Tests\Rector\FileNode\MoveInterfacesToContractNamespaceDirectoryRector;

use Iterator;
use Rector\Autodiscovery\Rector\FileNode\MoveInterfacesToContractNamespaceDirectoryRector;
use Rector\Core\ValueObject\PhpVersionFeature;
use Rector\FileSystemRector\ValueObject\AddedFileWithContent;
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
use Rector\Testing\ValueObject\InputFilePathWithExpectedFile;
Expand Down Expand Up @@ -108,13 +106,8 @@ public function provideData(): Iterator
yield [new SmartFileInfo(__DIR__ . '/Source/Contract/Foo/KeepThisSomeInterface.php'), null];
}

protected function getRectorClass(): string
protected function provideConfigFileInfo(): ?SmartFileInfo
{
return MoveInterfacesToContractNamespaceDirectoryRector::class;
}

protected function getPhpVersion(): int
{
return PhpVersionFeature::TYPED_PROPERTIES - 1;
return new SmartFileInfo(__DIR__ . '/config/some_config.php');
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

declare(strict_types=1);

use Rector\Autodiscovery\Rector\FileNode\MoveInterfacesToContractNamespaceDirectoryRector;
use Rector\Core\Configuration\Option;
use Rector\Core\ValueObject\PhpVersionFeature;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;

return static function (ContainerConfigurator $containerConfigurator): void {
$parameters = $containerConfigurator->parameters();
$parameters->set(Option::PHP_VERSION_FEATURES, PhpVersionFeature::TYPED_PROPERTIES - 1);

$services = $containerConfigurator->services();
$services->set(MoveInterfacesToContractNamespaceDirectoryRector::class);
};
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
namespace Rector\CodeQuality\Tests\Rector\Class_\CompleteDynamicPropertiesRector;

use Iterator;
use Rector\CodeQuality\Rector\Class_\CompleteDynamicPropertiesRector;
use Rector\Core\ValueObject\PhpVersionFeature;
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
use Symplify\SmartFileSystem\SmartFileInfo;

Expand All @@ -25,13 +23,8 @@ public function provideData(): Iterator
return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture');
}

protected function getRectorClass(): string
protected function provideConfigFileInfo(): ?SmartFileInfo
{
return CompleteDynamicPropertiesRector::class;
}

protected function getPhpVersion(): int
{
return PhpVersionFeature::UNION_TYPES - 1;
return new SmartFileInfo(__DIR__ . '/config/pre_union_types.php');
}
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

declare(strict_types=1);

use Rector\CodeQuality\Rector\Class_\CompleteDynamicPropertiesRector;
use Rector\Core\Configuration\Option;
use Rector\Core\ValueObject\PhpVersionFeature;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;

return static function (ContainerConfigurator $containerConfigurator): void {
$parameters = $containerConfigurator->parameters();
$parameters->set(Option::PHP_VERSION_FEATURES, PhpVersionFeature::UNION_TYPES - 1);

$services = $containerConfigurator->services();
$services->set(CompleteDynamicPropertiesRector::class);
};
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
namespace Rector\CodingStyle\Tests\Rector\ClassMethod\MakeInheritedMethodVisibilitySameAsParentRector;

use Iterator;
use Rector\CodingStyle\Rector\ClassMethod\MakeInheritedMethodVisibilitySameAsParentRector;
use Rector\Core\ValueObject\PhpVersionFeature;
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
use Symplify\SmartFileSystem\SmartFileInfo;

Expand All @@ -28,13 +26,8 @@ public function provideData(): Iterator
return $this->yieldFilesFromDirectory(__DIR__ . '/FixtureForPhp72');
}

protected function getRectorClass(): string
protected function provideConfigFileInfo(): ?SmartFileInfo
{
return MakeInheritedMethodVisibilitySameAsParentRector::class;
}

protected function getPhpVersion(): int
{
return PhpVersionFeature::PARENT_VISIBILITY_OVERRIDE;
return new SmartFileInfo(__DIR__ . '/config/php_72.php');
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

declare(strict_types=1);

use Rector\CodingStyle\Rector\ClassMethod\MakeInheritedMethodVisibilitySameAsParentRector;
use Rector\Core\Configuration\Option;
use Rector\Core\ValueObject\PhpVersionFeature;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;

return static function (ContainerConfigurator $containerConfigurator): void {
$parameters = $containerConfigurator->parameters();
$parameters->set(Option::PHP_VERSION_FEATURES, PhpVersionFeature::PARENT_VISIBILITY_OVERRIDE);

$services = $containerConfigurator->services();
$services->set(MakeInheritedMethodVisibilitySameAsParentRector::class);
};
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,10 @@ public function refactor(Node $node): ?Node
if ($node->stmts === null) {
return null;
}

$stmtValues = array_values($node->stmts);
$lastStmt = end($stmtValues);

if (! $lastStmt instanceof Return_) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
namespace Rector\DeadCode\Tests\Rector\ClassMethod\RemoveDeadConstructorRector;

use Iterator;
use Rector\Core\ValueObject\PhpVersionFeature;
use Rector\DeadCode\Rector\ClassMethod\RemoveDeadConstructorRector;
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
use Symplify\SmartFileSystem\SmartFileInfo;

Expand All @@ -26,13 +24,8 @@ public function provideData(): Iterator
return $this->yieldFilesFromDirectory(__DIR__ . '/FixturePhp80');
}

protected function getRectorClass(): string
protected function provideConfigFileInfo(): ?SmartFileInfo
{
return RemoveDeadConstructorRector::class;
}

protected function getPhpVersion(): int
{
return PhpVersionFeature::PROPERTY_PROMOTION;
return new SmartFileInfo(__DIR__ . '/config/property_promotion.php');
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

declare(strict_types=1);

use Rector\Core\Configuration\Option;
use Rector\Core\ValueObject\PhpVersionFeature;
use Rector\DeadCode\Rector\ClassMethod\RemoveDeadConstructorRector;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;

return static function (ContainerConfigurator $containerConfigurator): void {
$parameters = $containerConfigurator->parameters();
$parameters->set(Option::PHP_VERSION_FEATURES, PhpVersionFeature::PROPERTY_PROMOTION);

$services = $containerConfigurator->services();
$services->set(RemoveDeadConstructorRector::class);
};
Loading

0 comments on commit 698a3a4

Please sign in to comment.