Skip to content

Commit 03d63ec

Browse files
committed
Update codebase using rector/rector.
1 parent d03f537 commit 03d63ec

28 files changed

+99
-95
lines changed

spec/loophp/phptree/Importer/MicrosoftTolerantPhpParserSpec.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public function it_can_import(): void
2525
$this
2626
->import($ast)
2727
->count()
28-
->shouldReturn(582);
28+
->shouldReturn(586);
2929

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

spec/loophp/phptree/Importer/NikicPhpAstSpec.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public function it_can_import(): void
2222
$this
2323
->import($ast)
2424
->count()
25-
->shouldReturn(542);
25+
->shouldReturn(545);
2626

2727
$file = __DIR__ . '/../../../../tests/sample.php';
2828
$ast = \ast\parse_file($file, 50);

spec/loophp/phptree/Importer/NikicPhpParserSpec.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public function it_can_import(): void
3333
$this
3434
->import($ast)
3535
->count()
36-
->shouldReturn(563);
36+
->shouldReturn(566);
3737

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

src/Builder/BuilderInterface.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ interface BuilderInterface
1414
/**
1515
* @param iterable<mixed> $nodes
1616
*
17-
* @return \loophp\phptree\Node\NodeInterface|null
17+
* @return NodeInterface|null
1818
*/
1919
public static function create(iterable $nodes): ?NodeInterface;
2020
}

src/Builder/Random.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public static function create(iterable $nodes): ?NodeInterface
2727
continue;
2828
}
2929

30-
if (false === ($root instanceof NodeInterface)) {
30+
if (!$root instanceof NodeInterface) {
3131
continue;
3232
}
3333

src/Exporter/Graph.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -43,18 +43,18 @@ public function export(NodeInterface $node): OriginalGraph
4343
/**
4444
* Create a vertex.
4545
*
46-
* @param \loophp\phptree\Node\NodeInterface $node
46+
* @param NodeInterface $node
4747
* The node
4848
*
49-
* @return \Fhaculty\Graph\Vertex
49+
* @return Vertex
5050
* A vertex
5151
*/
5252
private function createVertex(NodeInterface $node): Vertex
5353
{
5454
/** @var int $vertexId */
5555
$vertexId = $this->createVertexId($node);
5656

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

6060
$vertex->setAttribute(
@@ -75,7 +75,7 @@ private function createVertex(NodeInterface $node): Vertex
7575
/**
7676
* Create a vertex ID.
7777
*
78-
* @param \loophp\phptree\Node\NodeInterface $node
78+
* @param NodeInterface $node
7979
* The node
8080
*
8181
* @return string

src/Exporter/Gv.php

+6-8
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ function ($key, $data) {
7272
$edges[] = sprintf(
7373
' "%s" %s "%s";',
7474
$this->getHash($parent),
75-
true === $this->getDirected() ? '->' : '--',
75+
$this->getDirected() ? '->' : '--',
7676
$this->getHash($child)
7777
);
7878
}
@@ -192,18 +192,16 @@ private function getGv(string $attributes = '', string $nodes = '', string $edge
192192
'digraph' :
193193
'graph';
194194

195-
return <<<EOF
196-
{$graphType} PHPTreeGraph {
195+
return sprintf('%s PHPTreeGraph {
197196
// The graph attributes.
198-
{$attributes}
197+
%s
199198
200199
// The graph nodes.
201-
{$nodes}
200+
%s
202201
203202
// The graph edges.
204-
{$edges}
205-
}
206-
EOF;
203+
%s
204+
}', $graphType, $attributes, $nodes, $edges);
207205
}
208206

209207
/**

src/Exporter/Image.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,15 @@ public function __construct()
3535
}
3636

3737
/**
38-
* @param \loophp\phptree\Node\NodeInterface $node
38+
* @param NodeInterface $node
3939
*
4040
* @throws Exception
4141
*
4242
* @return string
4343
*/
4444
public function export(NodeInterface $node): string
4545
{
46-
if (false === $tmp = tempnam(sys_get_temp_dir(), 'phptree-export-')) {
46+
if (!($tmp = tempnam(sys_get_temp_dir(), 'phptree-export-'))) {
4747
return '';
4848
}
4949

src/Exporter/SimpleArray.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ final class SimpleArray implements ExporterInterface
1414
/**
1515
* {@inheritdoc}
1616
*/
17-
public function export(NodeInterface $node)
17+
public function export(NodeInterface $node): array
1818
{
1919
$children = [];
2020

src/Importer/MicrosoftTolerantPhpParser.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ final class MicrosoftTolerantPhpParser implements ImporterInterface
2121
*
2222
* @throws Exception
2323
*
24-
* @return \loophp\phptree\Node\NodeInterface
24+
* @return NodeInterface
2525
*/
2626
public function import($data): NodeInterface
2727
{
@@ -31,18 +31,18 @@ public function import($data): NodeInterface
3131
/**
3232
* @param array $attributes
3333
*
34-
* @return \loophp\phptree\Node\AttributeNodeInterface
34+
* @return AttributeNodeInterface
3535
*/
3636
private function createNode(array $attributes): AttributeNodeInterface
3737
{
3838
return new AttributeNode($attributes);
3939
}
4040

4141
/**
42-
* @param \loophp\phptree\Node\AttributeNodeInterface $parent
43-
* @param \Microsoft\PhpParser\Node ...$astNodes
42+
* @param AttributeNodeInterface $parent
43+
* @param Node ...$astNodes
4444
*
45-
* @return \loophp\phptree\Node\NodeInterface
45+
* @return NodeInterface
4646
*/
4747
private function parseNode(AttributeNodeInterface $parent, Node ...$astNodes): NodeInterface
4848
{

src/Importer/NikicPhpAst.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@ final class NikicPhpAst implements ImporterInterface
2020
/**
2121
* @var array<int, \ast\Metadata>
2222
*/
23-
private $metadata;
23+
private $metadata = [];
2424

2525
/**
2626
* @param Node $data
2727
*
2828
* @throws Exception
2929
*
30-
* @return \loophp\phptree\Node\NodeInterface
30+
* @return NodeInterface
3131
*/
3232
public function import($data): NodeInterface
3333
{
@@ -39,18 +39,18 @@ public function import($data): NodeInterface
3939
/**
4040
* @param array $attributes
4141
*
42-
* @return \loophp\phptree\Node\AttributeNodeInterface
42+
* @return AttributeNodeInterface
4343
*/
4444
private function createNode(array $attributes): AttributeNodeInterface
4545
{
4646
return new AttributeNode($attributes);
4747
}
4848

4949
/**
50-
* @param \loophp\phptree\Node\AttributeNodeInterface $parent
50+
* @param AttributeNodeInterface $parent
5151
* @param Node ...$astNodes
5252
*
53-
* @return \loophp\phptree\Node\NodeInterface
53+
* @return NodeInterface
5454
*/
5555
private function parseNode(AttributeNodeInterface $parent, Node ...$astNodes): NodeInterface
5656
{

src/Importer/NikicPhpParser.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ final class NikicPhpParser implements ImporterInterface
2222
*
2323
* @throws Exception
2424
*
25-
* @return \loophp\phptree\Node\NodeInterface
25+
* @return NodeInterface
2626
*/
2727
public function import($data): NodeInterface
2828
{
@@ -32,7 +32,7 @@ public function import($data): NodeInterface
3232
/**
3333
* @param array $attributes
3434
*
35-
* @return \loophp\phptree\Node\AttributeNodeInterface
35+
* @return AttributeNodeInterface
3636
*/
3737
private function createNode(array $attributes): AttributeNodeInterface
3838
{
@@ -69,10 +69,10 @@ static function (string $subNodeName) use ($astNode): array {
6969
}
7070

7171
/**
72-
* @param \loophp\phptree\Node\AttributeNodeInterface $parent
72+
* @param AttributeNodeInterface $parent
7373
* @param Node ...$astNodes
7474
*
75-
* @return \loophp\phptree\Node\NodeInterface
75+
* @return NodeInterface
7676
*/
7777
private function parseNode(AttributeNodeInterface $parent, Node ...$astNodes): NodeInterface
7878
{

src/Importer/SimpleArray.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public function import($data): NodeInterface
2727
* @param mixed $data
2828
* The arguments
2929
*
30-
* @return \loophp\phptree\Node\AttributeNodeInterface
30+
* @return AttributeNodeInterface
3131
* The node
3232
*/
3333
private function createNode($data): AttributeNodeInterface
@@ -38,7 +38,7 @@ private function createNode($data): AttributeNodeInterface
3838
}
3939

4040
/**
41-
* @param \loophp\phptree\Node\AttributeNodeInterface $parent
41+
* @param AttributeNodeInterface $parent
4242
* @param array ...$nodes
4343
*
4444
* @return \loophp\phptree\Node\NodeInterface

src/Importer/Text.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public function import($data): NodeInterface
2727
* @param string $label
2828
* The node label
2929
*
30-
* @return \loophp\phptree\Node\AttributeNodeInterface
30+
* @return AttributeNodeInterface
3131
* The node
3232
*/
3333
private function createNode(string $label): AttributeNodeInterface
@@ -58,7 +58,7 @@ private function parse(string $subject): array
5858
}
5959

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

6363
$result['children'] = array_map(
6464
static function (string $match): string {
@@ -71,7 +71,7 @@ static function (string $match): string {
7171
}
7272

7373
/**
74-
* @param \loophp\phptree\Node\AttributeNodeInterface $parent
74+
* @param AttributeNodeInterface $parent
7575
* @param string ...$nodes
7676
*
7777
* @return \loophp\phptree\Node\NodeInterface

src/Modifier/Apply.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@ class Apply implements ModifierInterface
1919
private $apply;
2020

2121
/**
22-
* @var \loophp\phptree\Traverser\TraverserInterface|null
22+
* @var TraverserInterface|null
2323
*/
2424
private $traverser;
2525

2626
/**
2727
* Apply constructor.
2828
*
2929
* @param callable $apply
30-
* @param \loophp\phptree\Traverser\TraverserInterface|null $traverser
30+
* @param TraverserInterface|null $traverser
3131
*/
3232
public function __construct(callable $apply, ?TraverserInterface $traverser = null)
3333
{

src/Modifier/Filter.php

+4-3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use loophp\phptree\Node\NodeInterface;
88
use loophp\phptree\Traverser\PostOrder;
9+
use loophp\phptree\Traverser\PreOrder;
910
use loophp\phptree\Traverser\TraverserInterface;
1011

1112
/**
@@ -19,15 +20,15 @@ class Filter implements ModifierInterface
1920
private $filter;
2021

2122
/**
22-
* @var \loophp\phptree\Traverser\PreOrder|\loophp\phptree\Traverser\TraverserInterface
23+
* @var PreOrder|TraverserInterface
2324
*/
2425
private $traverser;
2526

2627
/**
2728
* Filter constructor.
2829
*
2930
* @param callable $filter
30-
* @param \loophp\phptree\Traverser\TraverserInterface|null $traverser
31+
* @param TraverserInterface|null $traverser
3132
*/
3233
public function __construct(callable $filter, ?TraverserInterface $traverser = null)
3334
{
@@ -45,7 +46,7 @@ public function modify(NodeInterface $tree): NodeInterface
4546
continue;
4647
}
4748

48-
if (false === (bool) ($this->filter)($item)) {
49+
if (!(bool) ($this->filter)($item)) {
4950
continue;
5051
}
5152

src/Modifier/FulfillCapacity.php

+6-4
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44

55
namespace loophp\phptree\Modifier;
66

7+
use loophp\phptree\Node\NaryNodeInterface;
78
use loophp\phptree\Node\NodeInterface;
89
use loophp\phptree\Traverser\PostOrder;
10+
use loophp\phptree\Traverser\PreOrder;
911
use loophp\phptree\Traverser\TraverserInterface;
1012

1113
/**
@@ -14,14 +16,14 @@
1416
class FulfillCapacity implements ModifierInterface
1517
{
1618
/**
17-
* @var \loophp\phptree\Traverser\PreOrder|\loophp\phptree\Traverser\TraverserInterface
19+
* @var PreOrder|TraverserInterface
1820
*/
1921
private $traverser;
2022

2123
/**
2224
* FulfillCapacity constructor.
2325
*
24-
* @param \loophp\phptree\Traverser\TraverserInterface|null $traverser
26+
* @param TraverserInterface|null $traverser
2527
*/
2628
public function __construct(?TraverserInterface $traverser = null)
2729
{
@@ -33,11 +35,11 @@ public function __construct(?TraverserInterface $traverser = null)
3335
*/
3436
public function modify(NodeInterface $tree): NodeInterface
3537
{
36-
/** @var \loophp\phptree\Node\NaryNodeInterface $item */
38+
/** @var NaryNodeInterface $item */
3739
foreach ($this->traverser->traverse($tree) as $item) {
3840
$capacity = $item->capacity();
3941

40-
if (false === $item->isLeaf()) {
42+
if (!$item->isLeaf()) {
4143
$children = iterator_to_array($item->children());
4244

4345
while ($item->degree() !== $capacity) {

src/Modifier/ModifierInterface.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44

55
namespace loophp\phptree\Modifier;
66

7+
use loophp\phptree\Node\AttributeNodeInterface;
8+
use loophp\phptree\Node\MerkleNodeInterface;
79
use loophp\phptree\Node\NodeInterface;
10+
use loophp\phptree\Node\ValueNodeInterface;
811

912
/**
1013
* Interface ModifierInterface.
@@ -17,7 +20,7 @@ interface ModifierInterface
1720
* @param NodeInterface $tree
1821
* The original tree.
1922
*
20-
* @return \loophp\phptree\Node\AttributeNodeInterface|\loophp\phptree\Node\MerkleNodeInterface|\loophp\phptree\Node\ValueNodeInterface|NodeInterface
23+
* @return AttributeNodeInterface|MerkleNodeInterface|NodeInterface|ValueNodeInterface
2124
* A new tree.
2225
*/
2326
public function modify(NodeInterface $tree): NodeInterface;

0 commit comments

Comments
 (0)