Conditions | 13 |
Paths | 96 |
Total Lines | 41 |
Code Lines | 30 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 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 |
||
68 | public function getDeclarationLine(ClassReflection $class) |
||
69 | { |
||
70 | $usesNames = $this->getUseArray($class); |
||
71 | |||
72 | $declaration = ''; |
||
73 | if ($class->isAbstract() && !$class->isInterface() && !$class->isTrait()) { |
||
74 | $declaration .= 'abstract '; |
||
75 | } |
||
76 | if ($class->isFinal()) { |
||
77 | $declaration .= 'final '; |
||
78 | } |
||
79 | if ($class->isInterface()) { |
||
80 | $declaration .= 'interface '; |
||
81 | } elseif ($class->isTrait()) { |
||
82 | $declaration .= 'trait '; |
||
83 | } else { |
||
84 | $declaration .= 'class '; |
||
85 | } |
||
86 | $declaration .= $class->getShortName(); |
||
87 | $parentName = false; |
||
88 | if ($parent = $class->getParentClass()) { |
||
89 | $parentName = $this->getClassNameInContext($parent, $class->getNamespaceName(), $usesNames); |
||
90 | } |
||
91 | if ($parentName) { |
||
92 | $declaration .= " extends {$parentName}"; |
||
93 | } |
||
94 | $interfaces = array_diff($class->getInterfaceNames(), $parent ? $parent->getInterfaceNames() : array()); |
||
95 | if (count($interfaces)) { |
||
96 | foreach ($interfaces as $interface) { |
||
97 | $iReflection = new ClassReflection($interface); |
||
98 | $interfaces = array_diff($interfaces, $iReflection->getInterfaceNames()); |
||
99 | } |
||
100 | $declaration .= $class->isInterface() ? ' extends ' : ' implements '; |
||
101 | $declaration .= implode(', ', array_map(function($interface) use ($usesNames, $class) { |
||
102 | $iReflection = new ClassReflection($interface); |
||
103 | return $this->getClassNameInContext($iReflection, $class->getNamespaceName(), $usesNames); |
||
104 | }, $interfaces)); |
||
105 | } |
||
106 | |||
107 | return $declaration; |
||
108 | } |
||
109 | } |
||
110 |