| Conditions | 16 |
| Paths | 50 |
| Total Lines | 81 |
| Code Lines | 42 |
| 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 |
||
| 129 | usort($constraints, 'version_compare'); |
||
| 130 | |||
| 131 | return array_pop($constraints); |
||
| 132 | } |
||
| 133 | |||
| 134 | /** |
||
| 135 | * Check whether the package type is "allowed", which will include it in reports. If the type is not allowed |
||
| 136 | * then the package will be skipped. |
||
| 137 | * |
||
| 138 | * @param string $type |
||
| 139 | * @return bool |
||
| 140 | */ |
||
| 141 | protected function isAllowedType($type) |
||
| 142 | { |
||
| 143 | $allowedTypes = Config::inst()->get(__CLASS__, 'allowed_types'); |
||
| 144 | |||
| 145 | return in_array($type, $allowedTypes); |
||
| 146 | } |
||
| 147 | |||
| 148 | /** |
||
| 149 | * prints a message during the run of the task |
||
| 150 | * |
||
| 151 | * @param string $text |
||
| 152 | */ |
||
| 153 | protected function message($text) |
||
| 154 | { |
||
| 155 | if (!Director::is_cli()) { |
||
| 156 | $text = '<p>' . $text . '</p>'; |
||
| 157 | } |
||
| 158 | |||
| 159 | echo $text . PHP_EOL; |
||
| 160 | } |
||
| 161 | |||
| 162 | /** |
||
| 163 | * @param ComposerLoader $composerLoader |
||
| 164 | * @return $this |
||
| 165 | */ |
||
| 166 | public function setComposerLoader(ComposerLoader $composerLoader) |
||
| 167 | { |
||
| 168 | $this->composerLoader = $composerLoader; |
||
| 169 | return $this; |
||
| 170 | } |
||
| 171 | |||
| 172 | /** |
||
| 173 | * @return ComposerLoader |
||
| 174 | */ |
||
| 175 | public function getComposerLoader() |
||
| 176 | { |
||
| 177 | return $this->composerLoader; |
||
| 178 | } |
||
| 179 | |||
| 180 | /** |
||
| 181 | * @param UpdateChecker $updateChecker |
||
| 182 | * @return $this |
||
| 183 | */ |
||
| 184 | public function setUpdateChecker(UpdateChecker $updateChecker) |
||
| 185 | { |
||
| 186 | $this->updateChecker = $updateChecker; |
||
| 187 | return $this; |
||
| 188 | } |
||
| 189 | |||
| 190 | /** |
||
| 191 | * @return UpdateChecker |
||
| 192 | */ |
||
| 193 | public function getUpdateChecker() |
||
| 194 | { |
||
| 195 | return $this->updateChecker; |
||
| 196 | } |
||
| 197 | } |
||
| 198 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.