Skip to content

Commit

Permalink
Update codebase using rector/rector.
Browse files Browse the repository at this point in the history
  • Loading branch information
drupol committed Mar 11, 2020
1 parent d03f537 commit 03d63ec
Show file tree
Hide file tree
Showing 28 changed files with 99 additions and 95 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function it_can_import(): void
$this
->import($ast)
->count()
->shouldReturn(582);
->shouldReturn(586);

$file = __DIR__ . '/../../../../tests/sample.php';

Expand Down
2 changes: 1 addition & 1 deletion spec/loophp/phptree/Importer/NikicPhpAstSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function it_can_import(): void
$this
->import($ast)
->count()
->shouldReturn(542);
->shouldReturn(545);

$file = __DIR__ . '/../../../../tests/sample.php';
$ast = \ast\parse_file($file, 50);
Expand Down
2 changes: 1 addition & 1 deletion spec/loophp/phptree/Importer/NikicPhpParserSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function it_can_import(): void
$this
->import($ast)
->count()
->shouldReturn(563);
->shouldReturn(566);

$file = __DIR__ . '/../../../../tests/sample.php';

Expand Down
2 changes: 1 addition & 1 deletion src/Builder/BuilderInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ interface BuilderInterface
/**
* @param iterable<mixed> $nodes
*
* @return \loophp\phptree\Node\NodeInterface|null
* @return NodeInterface|null
*/
public static function create(iterable $nodes): ?NodeInterface;
}
2 changes: 1 addition & 1 deletion src/Builder/Random.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public static function create(iterable $nodes): ?NodeInterface
continue;
}

if (false === ($root instanceof NodeInterface)) {
if (!$root instanceof NodeInterface) {
continue;
}

Expand Down
8 changes: 4 additions & 4 deletions src/Exporter/Graph.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,18 @@ public function export(NodeInterface $node): OriginalGraph
/**
* Create a vertex.
*
* @param \loophp\phptree\Node\NodeInterface $node
* @param NodeInterface $node
* The node
*
* @return \Fhaculty\Graph\Vertex
* @return Vertex
* A vertex
*/
private function createVertex(NodeInterface $node): Vertex
{
/** @var int $vertexId */
$vertexId = $this->createVertexId($node);

if (false === $this->getGraph()->hasVertex($vertexId)) {
if (!$this->getGraph()->hasVertex($vertexId)) {
$vertex = $this->getGraph()->createVertex($vertexId);

$vertex->setAttribute(
Expand All @@ -75,7 +75,7 @@ private function createVertex(NodeInterface $node): Vertex
/**
* Create a vertex ID.
*
* @param \loophp\phptree\Node\NodeInterface $node
* @param NodeInterface $node
* The node
*
* @return string
Expand Down
14 changes: 6 additions & 8 deletions src/Exporter/Gv.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ function ($key, $data) {
$edges[] = sprintf(
' "%s" %s "%s";',
$this->getHash($parent),
true === $this->getDirected() ? '->' : '--',
$this->getDirected() ? '->' : '--',
$this->getHash($child)
);
}
Expand Down Expand Up @@ -192,18 +192,16 @@ private function getGv(string $attributes = '', string $nodes = '', string $edge
'digraph' :
'graph';

return <<<EOF
{$graphType} PHPTreeGraph {
return sprintf('%s PHPTreeGraph {
// The graph attributes.
{$attributes}
%s
// The graph nodes.
{$nodes}
%s
// The graph edges.
{$edges}
}
EOF;
%s
}', $graphType, $attributes, $nodes, $edges);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Exporter/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ public function __construct()
}

/**
* @param \loophp\phptree\Node\NodeInterface $node
* @param NodeInterface $node
*
* @throws Exception
*
* @return string
*/
public function export(NodeInterface $node): string
{
if (false === $tmp = tempnam(sys_get_temp_dir(), 'phptree-export-')) {
if (!($tmp = tempnam(sys_get_temp_dir(), 'phptree-export-'))) {
return '';
}

Expand Down
2 changes: 1 addition & 1 deletion src/Exporter/SimpleArray.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ final class SimpleArray implements ExporterInterface
/**
* {@inheritdoc}
*/
public function export(NodeInterface $node)
public function export(NodeInterface $node): array
{
$children = [];

Expand Down
10 changes: 5 additions & 5 deletions src/Importer/MicrosoftTolerantPhpParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ final class MicrosoftTolerantPhpParser implements ImporterInterface
*
* @throws Exception
*
* @return \loophp\phptree\Node\NodeInterface
* @return NodeInterface
*/
public function import($data): NodeInterface
{
Expand All @@ -31,18 +31,18 @@ public function import($data): NodeInterface
/**
* @param array $attributes
*
* @return \loophp\phptree\Node\AttributeNodeInterface
* @return AttributeNodeInterface
*/
private function createNode(array $attributes): AttributeNodeInterface
{
return new AttributeNode($attributes);
}

/**
* @param \loophp\phptree\Node\AttributeNodeInterface $parent
* @param \Microsoft\PhpParser\Node ...$astNodes
* @param AttributeNodeInterface $parent
* @param Node ...$astNodes
*
* @return \loophp\phptree\Node\NodeInterface
* @return NodeInterface
*/
private function parseNode(AttributeNodeInterface $parent, Node ...$astNodes): NodeInterface
{
Expand Down
10 changes: 5 additions & 5 deletions src/Importer/NikicPhpAst.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ final class NikicPhpAst implements ImporterInterface
/**
* @var array<int, \ast\Metadata>
*/
private $metadata;
private $metadata = [];

/**
* @param Node $data
*
* @throws Exception
*
* @return \loophp\phptree\Node\NodeInterface
* @return NodeInterface
*/
public function import($data): NodeInterface
{
Expand All @@ -39,18 +39,18 @@ public function import($data): NodeInterface
/**
* @param array $attributes
*
* @return \loophp\phptree\Node\AttributeNodeInterface
* @return AttributeNodeInterface
*/
private function createNode(array $attributes): AttributeNodeInterface
{
return new AttributeNode($attributes);
}

/**
* @param \loophp\phptree\Node\AttributeNodeInterface $parent
* @param AttributeNodeInterface $parent
* @param Node ...$astNodes
*
* @return \loophp\phptree\Node\NodeInterface
* @return NodeInterface
*/
private function parseNode(AttributeNodeInterface $parent, Node ...$astNodes): NodeInterface
{
Expand Down
8 changes: 4 additions & 4 deletions src/Importer/NikicPhpParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ final class NikicPhpParser implements ImporterInterface
*
* @throws Exception
*
* @return \loophp\phptree\Node\NodeInterface
* @return NodeInterface
*/
public function import($data): NodeInterface
{
Expand All @@ -32,7 +32,7 @@ public function import($data): NodeInterface
/**
* @param array $attributes
*
* @return \loophp\phptree\Node\AttributeNodeInterface
* @return AttributeNodeInterface
*/
private function createNode(array $attributes): AttributeNodeInterface
{
Expand Down Expand Up @@ -69,10 +69,10 @@ static function (string $subNodeName) use ($astNode): array {
}

/**
* @param \loophp\phptree\Node\AttributeNodeInterface $parent
* @param AttributeNodeInterface $parent
* @param Node ...$astNodes
*
* @return \loophp\phptree\Node\NodeInterface
* @return NodeInterface
*/
private function parseNode(AttributeNodeInterface $parent, Node ...$astNodes): NodeInterface
{
Expand Down
4 changes: 2 additions & 2 deletions src/Importer/SimpleArray.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function import($data): NodeInterface
* @param mixed $data
* The arguments
*
* @return \loophp\phptree\Node\AttributeNodeInterface
* @return AttributeNodeInterface
* The node
*/
private function createNode($data): AttributeNodeInterface
Expand All @@ -38,7 +38,7 @@ private function createNode($data): AttributeNodeInterface
}

/**
* @param \loophp\phptree\Node\AttributeNodeInterface $parent
* @param AttributeNodeInterface $parent
* @param array ...$nodes
*
* @return \loophp\phptree\Node\NodeInterface
Expand Down
6 changes: 3 additions & 3 deletions src/Importer/Text.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function import($data): NodeInterface
* @param string $label
* The node label
*
* @return \loophp\phptree\Node\AttributeNodeInterface
* @return AttributeNodeInterface
* The node
*/
private function createNode(string $label): AttributeNodeInterface
Expand Down Expand Up @@ -58,7 +58,7 @@ private function parse(string $subject): array
}

// Todo: Improve the regex.
preg_match_all('~[^\[\]]+|\[(?<nested>(?R)*)]~', mb_substr($subject, $nextBracket, -1), $matches);
preg_match_all('#[^\[\]]+|\[(?<nested>(?R)*)]#', mb_substr($subject, $nextBracket, -1), $matches);

$result['children'] = array_map(
static function (string $match): string {
Expand All @@ -71,7 +71,7 @@ static function (string $match): string {
}

/**
* @param \loophp\phptree\Node\AttributeNodeInterface $parent
* @param AttributeNodeInterface $parent
* @param string ...$nodes
*
* @return \loophp\phptree\Node\NodeInterface
Expand Down
4 changes: 2 additions & 2 deletions src/Modifier/Apply.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ class Apply implements ModifierInterface
private $apply;

/**
* @var \loophp\phptree\Traverser\TraverserInterface|null
* @var TraverserInterface|null
*/
private $traverser;

/**
* Apply constructor.
*
* @param callable $apply
* @param \loophp\phptree\Traverser\TraverserInterface|null $traverser
* @param TraverserInterface|null $traverser
*/
public function __construct(callable $apply, ?TraverserInterface $traverser = null)
{
Expand Down
7 changes: 4 additions & 3 deletions src/Modifier/Filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use loophp\phptree\Node\NodeInterface;
use loophp\phptree\Traverser\PostOrder;
use loophp\phptree\Traverser\PreOrder;
use loophp\phptree\Traverser\TraverserInterface;

/**
Expand All @@ -19,15 +20,15 @@ class Filter implements ModifierInterface
private $filter;

/**
* @var \loophp\phptree\Traverser\PreOrder|\loophp\phptree\Traverser\TraverserInterface
* @var PreOrder|TraverserInterface
*/
private $traverser;

/**
* Filter constructor.
*
* @param callable $filter
* @param \loophp\phptree\Traverser\TraverserInterface|null $traverser
* @param TraverserInterface|null $traverser
*/
public function __construct(callable $filter, ?TraverserInterface $traverser = null)
{
Expand All @@ -45,7 +46,7 @@ public function modify(NodeInterface $tree): NodeInterface
continue;
}

if (false === (bool) ($this->filter)($item)) {
if (!(bool) ($this->filter)($item)) {
continue;
}

Expand Down
10 changes: 6 additions & 4 deletions src/Modifier/FulfillCapacity.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@

namespace loophp\phptree\Modifier;

use loophp\phptree\Node\NaryNodeInterface;
use loophp\phptree\Node\NodeInterface;
use loophp\phptree\Traverser\PostOrder;
use loophp\phptree\Traverser\PreOrder;
use loophp\phptree\Traverser\TraverserInterface;

/**
Expand All @@ -14,14 +16,14 @@
class FulfillCapacity implements ModifierInterface
{
/**
* @var \loophp\phptree\Traverser\PreOrder|\loophp\phptree\Traverser\TraverserInterface
* @var PreOrder|TraverserInterface
*/
private $traverser;

/**
* FulfillCapacity constructor.
*
* @param \loophp\phptree\Traverser\TraverserInterface|null $traverser
* @param TraverserInterface|null $traverser
*/
public function __construct(?TraverserInterface $traverser = null)
{
Expand All @@ -33,11 +35,11 @@ public function __construct(?TraverserInterface $traverser = null)
*/
public function modify(NodeInterface $tree): NodeInterface
{
/** @var \loophp\phptree\Node\NaryNodeInterface $item */
/** @var NaryNodeInterface $item */
foreach ($this->traverser->traverse($tree) as $item) {
$capacity = $item->capacity();

if (false === $item->isLeaf()) {
if (!$item->isLeaf()) {
$children = iterator_to_array($item->children());

while ($item->degree() !== $capacity) {
Expand Down
5 changes: 4 additions & 1 deletion src/Modifier/ModifierInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@

namespace loophp\phptree\Modifier;

use loophp\phptree\Node\AttributeNodeInterface;
use loophp\phptree\Node\MerkleNodeInterface;
use loophp\phptree\Node\NodeInterface;
use loophp\phptree\Node\ValueNodeInterface;

/**
* Interface ModifierInterface.
Expand All @@ -17,7 +20,7 @@ interface ModifierInterface
* @param NodeInterface $tree
* The original tree.
*
* @return \loophp\phptree\Node\AttributeNodeInterface|\loophp\phptree\Node\MerkleNodeInterface|\loophp\phptree\Node\ValueNodeInterface|NodeInterface
* @return AttributeNodeInterface|MerkleNodeInterface|NodeInterface|ValueNodeInterface
* A new tree.
*/
public function modify(NodeInterface $tree): NodeInterface;
Expand Down

0 comments on commit 03d63ec

Please sign in to comment.