Completed
Push — master ( cd87d1...9e95a6 )
by Marco
12s
created

StubClassSourceLocator::createLocatedSource()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 18
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 11
nc 3
nop 1
dl 0
loc 18
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Roave\BackwardCompatibility\SourceLocator;
6
7
use Roave\BetterReflection\Identifier\Identifier;
8
use Roave\BetterReflection\SourceLocator\Located\LocatedSource;
9
use Roave\BetterReflection\SourceLocator\Type\AbstractSourceLocator;
10
use function array_slice;
11
use function count;
12
use function explode;
13
use function implode;
14
use function sprintf;
15
16
final class StubClassSourceLocator extends AbstractSourceLocator
17
{
18
    /**
19
     * {@inheritDoc}
20
     */
21
    protected function createLocatedSource(Identifier $identifier) : ?LocatedSource
22
    {
23
        if (! $identifier->isClass()) {
24
            return null;
25
        }
26
27
        if ($identifier->getName() === Identifier::WILDCARD) {
28
            return null;
29
        }
30
31
        $fqcn           = $identifier->getName();
32
        $classNameParts = explode('\\', $fqcn);
33
        $shortName      = array_slice($classNameParts, -1)[0];
34
        $namespaceName  = implode('\\', array_slice($classNameParts, 0, count($classNameParts) - 1));
35
36
        return new LocatedSource(
37
            sprintf('<?php namespace %s{interface %s {}}', $namespaceName, $shortName),
38
            null
39
        );
40
    }
41
}
42