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; |
12
|
|
|
use Hal\Component\OOP\Reflected\ReflectedInterface; |
13
|
|
|
use Hal\Component\Result\ExportableInterface; |
14
|
|
|
|
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Result |
18
|
|
|
* |
19
|
|
|
* @author Jean-François Lépine <https://twitter.com/Halleck45> |
20
|
|
|
*/ |
21
|
|
|
class Result implements ExportableInterface { |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @var array |
25
|
|
|
*/ |
26
|
|
|
private $classes = array(); |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @inheritdoc |
30
|
|
|
*/ |
31
|
|
|
public function asArray() { |
32
|
|
|
|
33
|
|
|
$nom = 0; |
34
|
|
|
foreach($this->getClasses() as $class) { |
35
|
|
|
$nom += sizeof($class->getMethods(), COUNT_NORMAL); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
return array( |
39
|
|
|
'noc' => sizeof($this->classes, COUNT_NORMAL) |
40
|
|
|
, 'noca' => sizeof($this->getAbstractClasses(), COUNT_NORMAL) |
41
|
|
|
, 'nocc' => sizeof($this->getConcreteClasses(), COUNT_NORMAL) |
42
|
|
|
, 'noc-anon' => sizeof($this->getAnonymousClasses(), COUNT_NORMAL) |
43
|
|
|
, 'noi' => sizeof($this->getInterfaces(), COUNT_NORMAL) |
44
|
|
|
, 'nom' => $nom |
45
|
|
|
); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Push class |
50
|
|
|
* |
51
|
|
|
* @param ReflectedClass $class |
52
|
|
|
* @return $this |
53
|
|
|
*/ |
54
|
|
|
public function pushClass(ReflectedClass $class) { |
55
|
|
|
array_push($this->classes, $class); |
56
|
|
|
return $this; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @return array |
61
|
|
|
*/ |
62
|
|
|
public function getClasses() |
63
|
|
|
{ |
64
|
|
|
return $this->classes; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Get abstract classes |
69
|
|
|
* |
70
|
|
|
* @return array |
71
|
|
|
*/ |
72
|
|
|
public function getAbstractClasses() { |
73
|
|
|
$result = array(); |
74
|
|
|
foreach($this->getClasses() as $class) { |
75
|
|
|
if($class->isAbstract() ||$class instanceof ReflectedInterface) { |
76
|
|
|
array_push($result, $class); |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
return $result; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* Get anonymous classes |
84
|
|
|
* |
85
|
|
|
* @return array |
86
|
|
|
*/ |
87
|
|
View Code Duplication |
public function getAnonymousClasses() { |
|
|
|
|
88
|
|
|
$result = array(); |
89
|
|
|
foreach($this->getClasses() as $class) { |
90
|
|
|
if($class instanceof ReflectedClass\ReflectedAnonymousClass) { |
91
|
|
|
array_push($result, $class); |
92
|
|
|
} |
93
|
|
|
} |
94
|
|
|
return $result; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* Get abstract classes |
99
|
|
|
* |
100
|
|
|
* @return array |
101
|
|
|
*/ |
102
|
|
View Code Duplication |
public function getInterfaces() { |
|
|
|
|
103
|
|
|
$result = array(); |
104
|
|
|
foreach($this->getClasses() as $class) { |
105
|
|
|
if($class instanceof ReflectedInterface) { |
106
|
|
|
array_push($result, $class); |
107
|
|
|
} |
108
|
|
|
} |
109
|
|
|
return $result; |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* Get concretes classes |
114
|
|
|
* |
115
|
|
|
* @return array |
116
|
|
|
*/ |
117
|
|
|
public function getConcreteClasses() { |
118
|
|
|
$result = array(); |
119
|
|
|
foreach($this->getClasses() as $class) { |
120
|
|
|
if(!$class->isAbstract() &&!$class instanceof ReflectedInterface && !$class instanceof ReflectedClass\ReflectedAnonymousClass) { |
121
|
|
|
array_push($result, $class); |
122
|
|
|
} |
123
|
|
|
} |
124
|
|
|
return $result; |
125
|
|
|
} |
126
|
|
|
} |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.