Skip to content

Commit

Permalink
[Privatization] Skip on open-source abstract (#5516)
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasVotruba authored Feb 12, 2021
1 parent 8d97bdc commit fb1bf1f
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,10 @@ private function shouldSkip(ClassMethod $classMethod): bool
return true;
}

if ($currentClass->isAbstract() && $this->isOpenSourceProjectType()) {
return true;
}

$className = $classMethod->getAttribute(AttributeKey::CLASS_NAME);
if ($className === null) {
return true;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace Rector\Privatization\Tests\Rector\ClassMethod\MakeOnlyUsedByChildrenProtectedRector\FixtureOpenSource;

abstract class SkipAbstractClass
{
public function run()
{
}
}

final class SomeChild extends SkipAbstractClass
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

declare(strict_types=1);

namespace Rector\Privatization\Tests\Rector\ClassMethod\MakeOnlyUsedByChildrenProtectedRector;

use Iterator;
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
use Symplify\SmartFileSystem\SmartFileInfo;

final class OpenSourceRectorTest extends AbstractRectorTestCase
{
/**
* @dataProvider provideData()
*/
public function test(SmartFileInfo $fileInfo): void
{
$this->doTestFileInfo($fileInfo);
}

public function provideData(): Iterator
{
return $this->yieldFilesFromDirectory(__DIR__ . '/FixtureOpenSource');
}

protected function provideConfigFileInfo(): ?SmartFileInfo
{
return new SmartFileInfo(__DIR__ . '/config/configured_rule.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\ProjectType;
use Rector\Privatization\Rector\ClassMethod\MakeOnlyUsedByChildrenProtectedRector;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;

return static function (ContainerConfigurator $containerConfigurator): void {
$parameters = $containerConfigurator->parameters();
$parameters->set(Option::PROJECT_TYPE, ProjectType::OPEN_SOURCE);

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

0 comments on commit fb1bf1f

Please sign in to comment.