AttributeAscii::getNodeRepresentation()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
cc 2
eloc 2
nc 2
nop 1
dl 0
loc 4
ccs 0
cts 4
cp 0
crap 6
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace drupol\phpvfs\Exporter;
6
7
use drupol\phptree\Exporter\Ascii;
8
use drupol\phptree\Node\NodeInterface;
9
use drupol\phpvfs\Node\FilesystemNodeInterface;
10
11
/**
12
 * Class AttributeAscii.
13
 */
14
final class AttributeAscii extends Ascii
15
{
16
    /**
17
     * @param \drupol\phptree\Node\NodeInterface $node
18
     *   The node.
19
     *
20
     * @return string
21
     *   The node representation.
22
     */
23
    protected function getNodeRepresentation(NodeInterface $node): string
24
    {
25
        if ($node instanceof FilesystemNodeInterface) {
26
            return $node->getAttribute('label');
27
        }
0 ignored issues
show
Bug Best Practice introduced by
The function implicitly returns null when the if condition on line 25 is false. This is incompatible with the type-hinted return string. Consider adding a return statement or allowing null as return value.

For hinted functions/methods where all return statements with the correct type are only reachable via conditions, ?null? gets implicitly returned which may be incompatible with the hinted type. Let?s take a look at an example:

interface ReturnsInt {
    public function returnsIntHinted(): int;
}

class MyClass implements ReturnsInt {
    public function returnsIntHinted(): int
    {
        if (foo()) {
            return 123;
        }
        // here: null is implicitly returned
    }
}
Loading history...
28
    }
29
}
30