Completed
Push — master ( eb41aa...0b540b )
by Mike
03:38
created

FileDescriptor::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 2
dl 0
loc 7
ccs 0
cts 4
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
declare(strict_types=1);
3
4
/**
5
 * This file is part of phpDocumentor.
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 *
10
 * @author    Mike van Riel <[email protected]>
11
 * @copyright 2010-2018 Mike van Riel / Naenius (http://www.naenius.com)
12
 * @license   http://www.opensource.org/licenses/mit-license.php MIT
13
 * @link      http://phpdoc.org
14
 */
15
16
namespace phpDocumentor\Transformer\Router\UrlGenerator\Standard;
17
18
use phpDocumentor\Descriptor;
19
use phpDocumentor\Transformer\Router\UrlGenerator\UrlGeneratorInterface as UrlGenerator;
20
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
21
22
class FileDescriptor implements UrlGenerator
23
{
24
    private $urlGenerator;
25
    private $converter;
26
27
    public function __construct(
28
        UrlGeneratorInterface $urlGenerator,
29
        QualifiedNameToUrlConverter $converter
30
    ) {
31
        $this->urlGenerator = $urlGenerator;
32
        $this->converter = $converter;
33
    }
34
35
    /**
36
     * Generates a URL from the given node or returns false if unable.
37
     *
38
     * @param string|Descriptor\FileDescriptor $node
39
     *
40
     * @return string|false
41
     */
42 1
    public function __invoke($node)
43
    {
44 1
        return $this->urlGenerator->generate(
45 1
            'file',
46
            [
47 1
                'name' => $this->converter->fromFile($node->getPath())
0 ignored issues
show
Bug introduced by
It seems like $node is not always an object, but can also be of type string. Maybe add an additional type check?

If a variable is not always an object, we recommend to add an additional type check to ensure your method call is safe:

function someFunction(A $objectMaybe = null)
{
    if ($objectMaybe instanceof A) {
        $objectMaybe->doSomething();
    }
}
Loading history...
48
            ]
49
        );
50
    }
51
}
52