Conditions | 10 |
Paths | 12 |
Total Lines | 40 |
Code Lines | 30 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
99 | protected function processClass($class) |
||
100 | { |
||
101 | try { |
||
102 | $reflectionClass = new \ReflectionClass($class); |
||
103 | } catch (\Exception $e) { |
||
104 | $this->logger->err($e->getMessage()); |
||
105 | return null; |
||
106 | } |
||
107 | if (!$reflectionClass->isInstantiable()) { |
||
108 | return null; |
||
109 | } |
||
110 | foreach ($this->identifiers as $identifier) { |
||
111 | if ($reflectionClass->implementsInterface($identifier)) { |
||
112 | $name = $reflectionClass->getName(); |
||
113 | $baseType = $functionalType = $identifier; |
||
114 | if (isset($this->typePreferences[$identifier])) { |
||
115 | foreach ($this->typePreferences[$identifier] as $preference) { |
||
116 | if ($reflectionClass->implementsInterface($preference)) { |
||
117 | $functionalType = $preference; |
||
118 | break; |
||
119 | } |
||
120 | } |
||
121 | } |
||
122 | $hierarchy = []; |
||
123 | $rClass = $reflectionClass; |
||
124 | while ($rClass && ($pClass = $rClass->getParentClass()) != false) { |
||
125 | $hierarchy[] = $pClass->getName(); |
||
126 | $rClass = $pClass->getParentClass(); |
||
127 | } |
||
128 | $hierarchy[] = $functionalType; |
||
129 | $hierarchy[] = $baseType; |
||
130 | $hierarchy = array_unique($hierarchy); |
||
131 | $componentClass = new ComponentClass($name, $baseType, $functionalType, $hierarchy); |
||
132 | $this->logger->debug('Extracted Magium component', ['object' => serialize($componentClass)]); |
||
133 | return $componentClass; |
||
134 | } |
||
135 | } |
||
136 | $this->logger->debug(sprintf('File %s was not a Magium component class', $class)); |
||
137 | return null; |
||
138 | } |
||
139 | |||
176 |
In PHP, under loose comparison (like
==
, or!=
, orswitch
conditions), values of different types might be equal.For
string
values, the empty string''
is a special case, in particular the following results might be unexpected: