|
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\ReflectedClass\ReflectedAnonymousClass; |
|
12
|
|
|
use Hal\Component\OOP\Reflected\ReflectedClass; |
|
13
|
|
|
use Hal\Component\Token\TokenCollection; |
|
14
|
|
|
|
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* @author Jean-François Lépine <https://twitter.com/Halleck45> |
|
18
|
|
|
*/ |
|
19
|
|
|
class ClassExtractor implements ExtractorInterface { |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* @var Searcher |
|
23
|
|
|
*/ |
|
24
|
|
|
private $searcher; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* @var string |
|
28
|
|
|
*/ |
|
29
|
|
|
private $namespace; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* Constructor |
|
33
|
|
|
* |
|
34
|
|
|
* @param Searcher $searcher |
|
35
|
|
|
*/ |
|
36
|
|
|
public function __construct(Searcher $searcher) |
|
37
|
|
|
{ |
|
38
|
|
|
$this->searcher = $searcher; |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* Extract class from position |
|
43
|
|
|
* |
|
44
|
|
|
* @param $n |
|
45
|
|
|
* @param TokenCollection $tokens |
|
46
|
|
|
* @return ReflectedClass |
|
47
|
|
|
*/ |
|
48
|
|
|
public function extract(&$n, TokenCollection $tokens) |
|
49
|
|
|
{ |
|
50
|
|
|
// is PHP7 ? |
|
51
|
|
|
$previous = $tokens->get($n - 2); |
|
52
|
|
|
if($previous && T_NEW === $previous->getType()) { |
|
53
|
|
|
// anonymous class |
|
54
|
|
|
$class = new ReflectedAnonymousClass($this->namespace, 'class@anonymous'); |
|
55
|
|
|
return $class; |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
// is abstract ? |
|
59
|
|
|
$prev = $this->searcher->getPrevious($n, $tokens); |
|
|
|
|
|
|
60
|
|
|
$isAbstract = $prev && T_ABSTRACT === $prev->getType(); |
|
61
|
|
|
|
|
62
|
|
|
$classname = $this->searcher->getFollowingName($n, $tokens); |
|
63
|
|
|
$class = new ReflectedClass($this->namespace, trim($classname)); |
|
64
|
|
|
$class->setAbstract($isAbstract); |
|
65
|
|
|
return $class; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* @param string $namespace |
|
70
|
|
|
*/ |
|
71
|
|
|
public function setNamespace($namespace) |
|
72
|
|
|
{ |
|
73
|
|
|
$this->namespace = (string) $namespace; |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
}; |
This check looks for function or method calls that always return null and whose return value is assigned to a variable.
The method
getObject()can return nothing but null, so it makes no sense to assign that value to a variable.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.