Complex classes like ReflectionFunctionLikeTrait often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use ReflectionFunctionLikeTrait, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 28 | trait ReflectionFunctionLikeTrait |
||
| 29 | { |
||
| 30 | use InitializationTrait; |
||
| 31 | |||
| 32 | /** |
||
| 33 | * @var FunctionLike |
||
| 34 | */ |
||
| 35 | protected $functionLikeNode; |
||
| 36 | |||
| 37 | /** |
||
| 38 | * Namespace name |
||
| 39 | * |
||
| 40 | * @var string |
||
| 41 | */ |
||
| 42 | protected $namespaceName = ''; |
||
| 43 | |||
| 44 | /** |
||
| 45 | * @var array|ReflectionParameter[] |
||
| 46 | */ |
||
| 47 | protected $parameters; |
||
| 48 | |||
| 49 | /** |
||
| 50 | * {@inheritDoc} |
||
| 51 | */ |
||
| 52 | 2 | public function getClosureScopeClass() |
|
| 58 | |||
| 59 | /** |
||
| 60 | * {@inheritDoc} |
||
| 61 | */ |
||
| 62 | 2 | public function getClosureThis() |
|
| 68 | |||
| 69 | 2 | public function getDocComment() |
|
| 75 | |||
| 76 | 2 | public function getEndLine() |
|
| 80 | |||
| 81 | 2 | public function getExtension() |
|
| 85 | |||
| 86 | 2 | public function getExtensionName() |
|
| 90 | |||
| 91 | 9 | public function getFileName() |
|
| 95 | |||
| 96 | /** |
||
| 97 | * {@inheritDoc} |
||
| 98 | */ |
||
| 99 | 23 | public function getName() |
|
| 109 | |||
| 110 | /** |
||
| 111 | * {@inheritDoc} |
||
| 112 | */ |
||
| 113 | 9 | public function getNamespaceName() |
|
| 117 | |||
| 118 | /** |
||
| 119 | * Get the number of parameters that a function defines, both optional and required. |
||
| 120 | * |
||
| 121 | * @link http://php.net/manual/en/reflectionfunctionabstract.getnumberofparameters.php |
||
| 122 | * |
||
| 123 | * @return int |
||
| 124 | */ |
||
| 125 | 2 | public function getNumberOfParameters() |
|
| 129 | |||
| 130 | /** |
||
| 131 | * Get the number of required parameters that a function defines. |
||
| 132 | * |
||
| 133 | * @link http://php.net/manual/en/reflectionfunctionabstract.getnumberofrequiredparameters.php |
||
| 134 | * |
||
| 135 | * @return int |
||
| 136 | */ |
||
| 137 | 2 | public function getNumberOfRequiredParameters() |
|
| 148 | |||
| 149 | /** |
||
| 150 | * {@inheritDoc} |
||
| 151 | */ |
||
| 152 | 10 | public function getParameters() |
|
| 173 | |||
| 174 | /** |
||
| 175 | * Gets the specified return type of a function |
||
| 176 | * |
||
| 177 | * @return \ReflectionType |
||
| 178 | * |
||
| 179 | * @link http://php.net/manual/en/reflectionfunctionabstract.getreturntype.php |
||
| 180 | */ |
||
| 181 | 1 | public function getReturnType() |
|
| 193 | |||
| 194 | /** |
||
| 195 | * {@inheritDoc} |
||
| 196 | */ |
||
| 197 | 2 | public function getShortName() |
|
| 205 | |||
| 206 | 2 | public function getStartLine() |
|
| 210 | |||
| 211 | /** |
||
| 212 | * {@inheritDoc} |
||
| 213 | */ |
||
| 214 | 2 | public function getStaticVariables() |
|
| 225 | |||
| 226 | /** |
||
| 227 | * Checks if the function has a specified return type |
||
| 228 | * |
||
| 229 | * @return bool |
||
| 230 | * |
||
| 231 | * @link http://php.net/manual/en/reflectionfunctionabstract.hasreturntype.php |
||
| 232 | */ |
||
| 233 | 3 | public function hasReturnType() |
|
| 239 | |||
| 240 | /** |
||
| 241 | * {@inheritDoc} |
||
| 242 | */ |
||
| 243 | 2 | public function inNamespace() |
|
| 247 | |||
| 248 | /** |
||
| 249 | * {@inheritDoc} |
||
| 250 | */ |
||
| 251 | 1 | public function isClosure() |
|
| 255 | |||
| 256 | /** |
||
| 257 | * {@inheritDoc} |
||
| 258 | */ |
||
| 259 | 1 | public function isDeprecated() |
|
| 264 | |||
| 265 | /** |
||
| 266 | * {@inheritDoc} |
||
| 267 | */ |
||
| 268 | 1 | public function isGenerator() |
|
| 279 | |||
| 280 | /** |
||
| 281 | * {@inheritDoc} |
||
| 282 | */ |
||
| 283 | 1 | public function isInternal() |
|
| 288 | |||
| 289 | /** |
||
| 290 | * {@inheritDoc} |
||
| 291 | */ |
||
| 292 | 1 | public function isUserDefined() |
|
| 297 | |||
| 298 | /** |
||
| 299 | * {@inheritDoc} |
||
| 300 | */ |
||
| 301 | 1 | public function isVariadic() |
|
| 311 | |||
| 312 | /** |
||
| 313 | * {@inheritDoc} |
||
| 314 | */ |
||
| 315 | 2 | public function returnsReference() |
|
| 319 | } |
||
| 320 |