InterfaceExtractor::extract()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 5
rs 9.4286
cc 1
eloc 3
nc 1
nop 2
1
<?php
2
3
/*
4
 * (c) Jean-François Lépine <https://twitter.com/Halleck45>
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 */
9
10
namespace Hal\Component\OOP\Extractor;
11
use Hal\Component\OOP\Reflected\ReflectedInterface;
12
use Hal\Component\Token\TokenCollection;
13
14
15
/**
16
 * @author Jean-François Lépine <https://twitter.com/Halleck45>
17
 */
18
class InterfaceExtractor implements ExtractorInterface {
19
20
    /**
21
     * @var Searcher
22
     */
23
    private $searcher;
24
25
    /**
26
     * @var string
27
     */
28
    private $namespace;
29
30
    /**
31
     * Constructor
32
     *
33
     * @param Searcher $searcher
34
     */
35
    public function __construct(Searcher $searcher)
36
    {
37
        $this->searcher = $searcher;
38
    }
39
40
    /**
41
     * Extract class from position
42
     *
43
     * @param $n
44
     * @param TokenCollection $tokens
45
     * @return ReflectedInterface
46
     */
47
    public function extract(&$n, TokenCollection $tokens)
48
    {
49
        $classname = $this->searcher->getFollowingName($n, $tokens);
50
        return new ReflectedInterface($this->namespace, trim($classname));
51
    }
52
53
    /**
54
     * @param string $namespace
55
     */
56
    public function setNamespace($namespace)
57
    {
58
        $this->namespace = (string) $namespace;
59
    }
60
61
};