Conditions | 7 |
Paths | 5 |
Total Lines | 52 |
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 |
||
92 | public function getDocComment() |
||
93 | { |
||
94 | |||
95 | if (false === $this->docCommentProcessed) { |
||
96 | $this->docComment = null; |
||
97 | |||
98 | |||
99 | /** |
||
100 | * |
||
101 | * The first constant can have additional docblock |
||
102 | * |
||
103 | * /** |
||
104 | * * This belongs to the first |
||
105 | * * / |
||
106 | * const |
||
107 | * |
||
108 | * FOO = 'foo', |
||
109 | * BAR = 'bar' |
||
110 | * |
||
111 | * |
||
112 | * const |
||
113 | * /** |
||
114 | * * This belongs to the first |
||
115 | * * / |
||
116 | * FOO = "foo"; |
||
117 | * |
||
118 | */ |
||
119 | // Then we take every comments from the constant node |
||
120 | // Then if it's the first of the list we tank everything from the classConstNode |
||
121 | // (and we order it from the closest to the further |
||
122 | |||
123 | $comments = array_reverse($this->constNode->getAttribute('comments', [])); |
||
124 | if ($this->classConstNode->consts[0] == $this->constNode) { |
||
125 | $comments += array_reverse($this->classConstNode->getAttribute('comments', [])); |
||
126 | } |
||
127 | |||
128 | if (count($comments) > 0) { |
||
129 | // we can have many doc comment for one statement |
||
130 | // We only take the closest one |
||
131 | while ($this->docComment === null && $currentComment = current($comments)) { |
||
132 | if (substr($currentComment, 0, 3) == '/**') { |
||
133 | $this->docComment = $currentComment; |
||
134 | } |
||
135 | next($comments); |
||
136 | } |
||
137 | |||
138 | } |
||
139 | $this->docCommentProcessed = true; |
||
140 | } |
||
141 | |||
142 | return $this->docComment; |
||
143 | } |
||
144 | |||
159 |