Complex classes like ArgsInput 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 ArgsInput, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 26 | class ArgsInput implements InputInterface |
||
| 27 | { |
||
| 28 | /** |
||
| 29 | * @var RawArgs |
||
| 30 | */ |
||
| 31 | private $rawArgs; |
||
| 32 | |||
| 33 | /** |
||
| 34 | * @var Args |
||
| 35 | */ |
||
| 36 | private $args; |
||
| 37 | |||
| 38 | /** |
||
| 39 | * @var bool |
||
| 40 | */ |
||
| 41 | private $interactive = true; |
||
| 42 | |||
| 43 | /** |
||
| 44 | * Creates the adapter. |
||
| 45 | * |
||
| 46 | * @param RawArgs $rawArgs The unparsed console arguments. |
||
| 47 | * @param Args $args The parsed console arguments. |
||
|
|
|||
| 48 | */ |
||
| 49 | 16 | public function __construct(RawArgs $rawArgs, Args $args = null) |
|
| 54 | |||
| 55 | /** |
||
| 56 | * @return RawArgs |
||
| 57 | */ |
||
| 58 | 2 | public function getRawArgs() |
|
| 62 | |||
| 63 | /** |
||
| 64 | * @return Args |
||
| 65 | */ |
||
| 66 | 2 | public function getArgs() |
|
| 70 | |||
| 71 | /** |
||
| 72 | * {@inheritdoc} |
||
| 73 | */ |
||
| 74 | 2 | public function getFirstArgument() |
|
| 80 | |||
| 81 | /** |
||
| 82 | * {@inheritdoc} |
||
| 83 | */ |
||
| 84 | 2 | public function hasParameterOption($values, $onlyParams = false) |
|
| 105 | |||
| 106 | /** |
||
| 107 | * {@inheritdoc} |
||
| 108 | */ |
||
| 109 | 1 | public function getParameterOption($values, $default = false, $onlyParams = false) |
|
| 143 | |||
| 144 | /** |
||
| 145 | * {@inheritdoc} |
||
| 146 | */ |
||
| 147 | public function bind(InputDefinition $definition) |
||
| 150 | |||
| 151 | /** |
||
| 152 | * {@inheritdoc} |
||
| 153 | */ |
||
| 154 | public function validate() |
||
| 157 | |||
| 158 | /** |
||
| 159 | * {@inheritdoc} |
||
| 160 | */ |
||
| 161 | 1 | public function getArguments() |
|
| 165 | |||
| 166 | /** |
||
| 167 | * {@inheritdoc} |
||
| 168 | */ |
||
| 169 | 2 | public function getArgument($name) |
|
| 173 | |||
| 174 | /** |
||
| 175 | * {@inheritdoc} |
||
| 176 | */ |
||
| 177 | 1 | public function setArgument($name, $value) |
|
| 183 | |||
| 184 | /** |
||
| 185 | * {@inheritdoc} |
||
| 186 | */ |
||
| 187 | 1 | public function hasArgument($name) |
|
| 191 | |||
| 192 | /** |
||
| 193 | * {@inheritdoc} |
||
| 194 | */ |
||
| 195 | 1 | public function getOptions() |
|
| 199 | |||
| 200 | /** |
||
| 201 | * {@inheritdoc} |
||
| 202 | */ |
||
| 203 | 2 | public function getOption($name) |
|
| 207 | |||
| 208 | /** |
||
| 209 | * {@inheritdoc} |
||
| 210 | */ |
||
| 211 | 1 | public function setOption($name, $value) |
|
| 217 | |||
| 218 | /** |
||
| 219 | * {@inheritdoc} |
||
| 220 | */ |
||
| 221 | 1 | public function hasOption($name) |
|
| 225 | |||
| 226 | /** |
||
| 227 | * {@inheritdoc} |
||
| 228 | */ |
||
| 229 | 1 | public function isInteractive() |
|
| 233 | |||
| 234 | /** |
||
| 235 | * {@inheritdoc} |
||
| 236 | */ |
||
| 237 | 1 | public function setInteractive($interactive) |
|
| 241 | } |
||
| 242 |
This check looks for
@paramannotations where the type inferred by our type inference engine differs from the declared type.It makes a suggestion as to what type it considers more descriptive.
Most often this is a case of a parameter that can be null in addition to its declared types.