Skip to content

Commit

Permalink
move to Declare_
Browse files Browse the repository at this point in the history
  • Loading branch information
samsonasik committed Apr 12, 2021
1 parent 16a7dc6 commit 28ba5d1
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

declare(strict_types=1);

namespace Rector\Tests\DowngradePhp70\Rector\Declare_\DowngradeStrictTypeDeclarationRector;

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

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

/**
* @return Iterator<SmartFileInfo>
*/
public function provideData(): Iterator
{
return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture');
}

public function provideConfigFilePath(): string
{
return __DIR__ . '/config/php_70.php';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace Rector\Tests\DowngradePhp70\Rector\Declare_\DowngradeStrictTypeDeclarationRector\Fixture;

declare(strict_types=1);

class Fixture
{
}

?>
-----
<?php

namespace Rector\Tests\DowngradePhp70\Rector\Declare_\DowngradeStrictTypeDeclarationRector\Fixture;

class Fixture
{
}

?>
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\DowngradePhp70\Rector\Declare_\DowngradeStrictTypeDeclarationRector;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;

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

$services = $containerConfigurator->services();
$services->set(DowngradeStrictTypeDeclarationRector::class);
};
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,18 @@

declare(strict_types=1);

namespace Rector\DowngradePhp70\Rector\FuncCall;
namespace Rector\DowngradePhp70\Rector\Declare_;

use PhpParser\Node;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\FuncCall;
use PhpParser\Node\Stmt\Declare_;
use Rector\Core\Rector\AbstractRector;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;

/**
* @see \Rector\Tests\DowngradePhp70\Rector\FuncCall\DowngradeStrictTypeDeclarationRector\DowngradeStrictTypeDeclarationRectorTest
* @see \Rector\Tests\DowngradePhp70\Rector\Declare_\DowngradeStrictTypeDeclarationRector\DowngradeStrictTypeDeclarationRectorTest
*/
final class DowngradeStrictTypeDeclarationRector extends AbstractRector
{
Expand All @@ -20,7 +22,7 @@ final class DowngradeStrictTypeDeclarationRector extends AbstractRector
*/
public function getNodeTypes(): array
{
return [FuncCall::class];
return [Declare_::class];
}

public function getRuleDefinition(): RuleDefinition
Expand All @@ -45,6 +47,24 @@ public function getRuleDefinition(): RuleDefinition
*/
public function refactor(Node $node): ?Node
{
dump($node);
if ($this->shouldSkip($node)) {
return null;
}

return $node;
}

private function shouldSkip(FuncCall $funcCall): bool
{
if (! $this->isName($funcCall, 'declare')) {
return true;
}

$args = $funcCall->args;
$assign = $args[0];

dump($assign);
return true;
}
}

0 comments on commit 28ba5d1

Please sign in to comment.