Skip to content

Commit

Permalink
implemented
Browse files Browse the repository at this point in the history
  • Loading branch information
samsonasik committed Apr 12, 2021
1 parent 28ba5d1 commit a33006a
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,9 @@

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

declare(strict_types=1);
declare(ticks=1);

class Fixture
{
}

?>
-----
<?php

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

class Fixture
class SkipDifferentDeclare
{
}

Expand Down
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
Expand Up @@ -7,6 +7,7 @@
use PhpParser\Node;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\FuncCall;
use PhpParser\Node\Identifier;
use PhpParser\Node\Stmt\Declare_;
use Rector\Core\Rector\AbstractRector;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
Expand Down Expand Up @@ -43,28 +44,28 @@ public function getRuleDefinition(): RuleDefinition
}

/**
* @param FuncCall $node
* @param Declare_ $node
*/
public function refactor(Node $node): ?Node
{
dump($node);
if ($this->shouldSkip($node)) {
return null;
}

$this->removeNode($node);
return $node;
}

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

$args = $funcCall->args;
$assign = $args[0];
foreach ($declares as $declare) {
if ($declare->key instanceof Identifier && $this->isName($declare->key, 'strict_types')) {
return false;
}
}

dump($assign);
return true;
}
}

0 comments on commit a33006a

Please sign in to comment.