Issues (22)

src/Exporter/AttributeAscii.php (1 issue)

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