Skip to content

Commit a8e9ec0

Browse files
committed
rector and codesniffer fixes
1 parent 78a2651 commit a8e9ec0

File tree

8 files changed

+13
-27
lines changed

8 files changed

+13
-27
lines changed

inc/TreeBuilder/AbstractBuilder.php

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace dokuwiki\TreeBuilder;
44

5-
65
use dokuwiki\test\mock\Doku_Renderer;
76
use dokuwiki\TreeBuilder\Node\AbstractNode;
87
use dokuwiki\TreeBuilder\Node\ExternalLink;
@@ -145,7 +144,7 @@ public function getTop(): Top
145144
public function getAll(): array
146145
{
147146
if (!$this->generated) throw new \RuntimeException('need to call generate() first');
148-
if (empty($this->nodes)) {
147+
if ($this->nodes === []) {
149148
$this->nodes = [];
150149
foreach ($this->top->getDescendants() as $node) {
151150
$this->nodes[$node->getId()] = $node;
@@ -163,9 +162,7 @@ public function getAll(): array
163162
public function getLeaves(): array
164163
{
165164
if (!$this->generated) throw new \RuntimeException('need to call generate() first');
166-
return array_filter($this->getAll(), function ($page) {
167-
return !$page->getChildren();
168-
});
165+
return array_filter($this->getAll(), fn($page) => !$page->getChildren());
169166
}
170167

171168
/**
@@ -176,9 +173,7 @@ public function getLeaves(): array
176173
public function getBranches(): array
177174
{
178175
if (!$this->generated) throw new \RuntimeException('need to call generate() first');
179-
return array_filter($this->getAll(), function ($page) {
180-
return !!$page->getChildren();
181-
});
176+
return array_filter($this->getAll(), fn($page) => (bool) $page->getChildren());
182177
}
183178

184179
/**
@@ -218,7 +213,7 @@ public function render(Doku_Renderer $R, $top = null, $level = 1): void
218213
foreach ($top->getChildren() as $node) {
219214
$R->listitem_open(1, $node->hasChildren());
220215
$R->listcontent_open();
221-
if (is_a($node, ExternalLink::class)) {
216+
if ($node instanceof ExternalLink) {
222217
$R->externallink($node->getId(), $node->getTitle());
223218
} else {
224219
$R->internallink($node->getId(), $node->getTitle());
@@ -261,6 +256,6 @@ protected function applyRecursionDecision(AbstractNode $node, int $depth): bool
261256
*/
262257
public function __toString(): string
263258
{
264-
return join("\n", $this->getAll());
259+
return implode("\n", $this->getAll());
265260
}
266261
}

inc/TreeBuilder/ControlPageBuilder.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717
class ControlPageBuilder extends AbstractBuilder
1818
{
1919
/** @var int do not include internal links */
20-
const FLAG_NOINTERNAL = 1;
20+
public const FLAG_NOINTERNAL = 1;
2121
/** @var int do not include external links */
22-
const FLAG_NOEXTERNAL = 2;
22+
public const FLAG_NOEXTERNAL = 2;
2323

2424
/** @var string */
2525
protected string $controlPage;
@@ -66,7 +66,7 @@ public function generate(): void
6666
break;
6767
case 'listu_close':
6868
// if we had a node on this level, remove it from the parents
69-
if(isset($parents[$level])) {
69+
if (isset($parents[$level])) {
7070
unset($parents[$level]);
7171
}
7272
$level--; // close list level
@@ -89,7 +89,7 @@ public function generate(): void
8989
);
9090
}
9191

92-
if($level) {
92+
if ($level) {
9393
// remember this page as the parent for this level
9494
$parents[$level] = $newpage;
9595
// parent is the last page on the previous level
@@ -102,7 +102,7 @@ public function generate(): void
102102

103103
$newpage->setParent($parent);
104104
$newpage = $this->applyNodeProcessor($newpage);
105-
if($newpage instanceof AbstractNode) {
105+
if ($newpage instanceof AbstractNode) {
106106
$parent->addChild($newpage);
107107
}
108108
break;

inc/TreeBuilder/Node/AbstractNode.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public function getChildren(): array
9191
*/
9292
public function hasChildren(): bool
9393
{
94-
return !empty($this->children);
94+
return $this->children !== [];
9595
}
9696

9797
/**
@@ -178,10 +178,7 @@ public function setProperty(string $name, $value): void
178178
*/
179179
public function getProperty(string $name, $default = null)
180180
{
181-
if (isset($this->properties[$name])) {
182-
return $this->properties[$name];
183-
}
184-
return $default;
181+
return $this->properties[$name] ?? $default;
185182
}
186183

187184
/**

inc/TreeBuilder/Node/ExternalLink.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,4 @@
77
*/
88
class ExternalLink extends AbstractNode
99
{
10-
1110
}

inc/TreeBuilder/Node/WikiNamespace.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,4 @@
77
*/
88
class WikiNamespace extends AbstractNode
99
{
10-
1110
}

inc/TreeBuilder/Node/WikiPage.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,4 @@
77
*/
88
class WikiPage extends AbstractNode
99
{
10-
1110
}

inc/TreeBuilder/Node/WikiStartpage.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,4 @@ public function getNs(): string
3434
{
3535
return $this->originalNamespace;
3636
}
37-
3837
}

inc/TreeBuilder/PageTreeBuilder.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ protected function namespacePath(string $namespace): string
232232
$dir = wikiFN($namespace . ':xxx');
233233
$dir = substr($dir, strlen($base));
234234
$dir = dirname($dir); // remove the 'xxx' part
235-
if($dir === '.') $dir = ''; // dirname returns '.' for root namespace
235+
if ($dir === '.') $dir = ''; // dirname returns '.' for root namespace
236236
return $dir;
237237
}
238238

@@ -255,6 +255,4 @@ protected function applyNodeProcessor(AbstractNode $node): ?AbstractNode
255255
}
256256
return parent::applyNodeProcessor($node);
257257
}
258-
259-
260258
}

0 commit comments

Comments
 (0)