Skip to content

Commit

Permalink
Remove useless parameter & Refactor node cloning (#134)
Browse files Browse the repository at this point in the history
  • Loading branch information
theofidry authored Dec 26, 2017
1 parent 74281d9 commit 6be5c00
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 62 deletions.
5 changes: 1 addition & 4 deletions src/NodeVisitor/NamespaceStmtPrefixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,15 @@ final class NamespaceStmtPrefixer extends NodeVisitorAbstract
{
private $prefix;
private $namespaceStatements;
private $whitelist;

/**
* @param string $prefix
* @param NamespaceStmtCollection $namespaceStatements
* @param string[] $whitelist
*/
public function __construct(string $prefix, NamespaceStmtCollection $namespaceStatements, array $whitelist)
public function __construct(string $prefix, NamespaceStmtCollection $namespaceStatements)
{
$this->prefix = $prefix;
$this->namespaceStatements = $namespaceStatements;
$this->whitelist = $whitelist;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Scoper/TraverserFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function create(string $prefix, array $whitelist, callable $globalWhiteli

$traverser->addVisitor(new NodeVisitor\AppendParentNode());

$traverser->addVisitor(new NodeVisitor\NamespaceStmtPrefixer($prefix, $namespaceStatements, $whitelist));
$traverser->addVisitor(new NodeVisitor\NamespaceStmtPrefixer($prefix, $namespaceStatements));

$traverser->addVisitor(new NodeVisitor\UseStmt\UseStmtCollector($namespaceStatements, $useStatements));
$traverser->addVisitor(new NodeVisitor\UseStmt\UseStmtPrefixer($prefix, $whitelist, $globalWhitelister));
Expand Down
58 changes: 1 addition & 57 deletions src/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
use PhpParser\ParserFactory;
use Symfony\Component\Console\Application as SymfonyApplication;
use Symfony\Component\Filesystem\Filesystem;
use UnexpectedValueException;

/**
* @private
Expand Down Expand Up @@ -185,60 +184,5 @@ function deep_clone($node)
return $node;
}

if ($node instanceof Node\Stmt\Namespace_) {
return new Node\Stmt\Namespace_(
deep_clone($node->name)
);
}

if ($node instanceof Node\Name\Relative) {
return new Node\Name\Relative(
deep_clone($node->toString())
);
}

if ($node instanceof Node\Name\FullyQualified) {
return new Node\Name\FullyQualified(
deep_clone($node->toString())
);
}

if ($node instanceof Node\Name) {
return new Node\Name(
deep_clone($node->toString())
);
}

if ($node instanceof Node\Stmt\Use_) {
return new Node\Stmt\Use_(
deep_clone($node->uses),
$node->type
);
}

if ($node instanceof Node\Stmt\UseUse) {
return new Node\Stmt\UseUse(
deep_clone($node->name),
$node->alias,
$node->type
);
}

if ($node instanceof Node\Stmt\Class_) {
return new Node\Stmt\Class_(
deep_clone($node->name),
[
'flags' => deep_clone($node->flags),
'extends' => deep_clone($node->extends),
'implements' => deep_clone($node->implements),
]
);
}

throw new UnexpectedValueException(
sprintf(
'Cannot clone element "%s".',
get_class($node)
)
);
return unserialize(serialize($node));
}

0 comments on commit 6be5c00

Please sign in to comment.