Complex classes like MixinDefinitionNode 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.
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 MixinDefinitionNode, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 19 | class MixinDefinitionNode extends RulesetNode |
||
| 20 | { |
||
| 21 | /** |
||
| 22 | * Node type. |
||
| 23 | * |
||
| 24 | * @var string |
||
| 25 | */ |
||
| 26 | protected $type = 'MixinDefinition'; |
||
| 27 | |||
| 28 | /** |
||
| 29 | * The definition name. |
||
| 30 | * |
||
| 31 | * @var string |
||
| 32 | */ |
||
| 33 | public $name; |
||
| 34 | |||
| 35 | /** |
||
| 36 | * Array of selectors. |
||
| 37 | * |
||
| 38 | * @var array |
||
| 39 | */ |
||
| 40 | public $selectors; |
||
| 41 | |||
| 42 | /** |
||
| 43 | * Array of parameters. |
||
| 44 | * |
||
| 45 | * @var array |
||
| 46 | */ |
||
| 47 | public $params = []; |
||
| 48 | |||
| 49 | /** |
||
| 50 | * The arity. |
||
| 51 | * |
||
| 52 | * @var int |
||
| 53 | */ |
||
| 54 | public $arity = 0; |
||
| 55 | |||
| 56 | /** |
||
| 57 | * Array of rules. |
||
| 58 | * |
||
| 59 | * @var array |
||
| 60 | */ |
||
| 61 | public $rules = []; |
||
| 62 | |||
| 63 | /** |
||
| 64 | * Lookups cache array. |
||
| 65 | * |
||
| 66 | * @var array |
||
| 67 | */ |
||
| 68 | public $lookups = []; |
||
| 69 | |||
| 70 | /** |
||
| 71 | * Number of required parameters. |
||
| 72 | * |
||
| 73 | * @var int |
||
| 74 | */ |
||
| 75 | public $required = 0; |
||
| 76 | |||
| 77 | /** |
||
| 78 | * Frames array. |
||
| 79 | * |
||
| 80 | * @var array |
||
| 81 | */ |
||
| 82 | public $frames = []; |
||
| 83 | |||
| 84 | /** |
||
| 85 | * The condition. |
||
| 86 | * |
||
| 87 | * @var ConditionNode |
||
| 88 | */ |
||
| 89 | public $condition; |
||
| 90 | |||
| 91 | /** |
||
| 92 | * Variadic flag. |
||
| 93 | * |
||
| 94 | * @var bool |
||
| 95 | */ |
||
| 96 | public $variadic = false; |
||
| 97 | |||
| 98 | /** |
||
| 99 | * @var bool |
||
| 100 | */ |
||
| 101 | public $compileFirst = true; |
||
| 102 | |||
| 103 | /** |
||
| 104 | * @var array |
||
| 105 | */ |
||
| 106 | protected $optionalParameters = []; |
||
| 107 | |||
| 108 | /** |
||
| 109 | * Constructor. |
||
| 110 | * |
||
| 111 | * @param string $name |
||
| 112 | * @param array $params Array of parameters |
||
| 113 | * @param array $rules |
||
| 114 | * @param ConditionNode $condition |
||
| 115 | * @param bool $variadic |
||
| 116 | */ |
||
| 117 | public function __construct( |
||
| 147 | |||
| 148 | /** |
||
| 149 | * {@inheritdoc} |
||
| 150 | */ |
||
| 151 | public function accept(VisitorInterface $visitor) |
||
| 163 | |||
| 164 | /** |
||
| 165 | * Compiles the node. |
||
| 166 | * |
||
| 167 | * @param Context $context The context |
||
| 168 | * @param array|null $arguments Array of arguments |
||
| 169 | * @param bool|null $important Important flag |
||
| 170 | * |
||
| 171 | * @return MixinDefinitionNode |
||
| 172 | */ |
||
| 173 | public function compile(Context $context, $arguments = null, $important = null) |
||
| 184 | |||
| 185 | /** |
||
| 186 | * {@inheritdoc} |
||
| 187 | */ |
||
| 188 | public function compileCall(Context $context, $arguments = null, $important = null) |
||
| 212 | |||
| 213 | /** |
||
| 214 | * Compile parameters. |
||
| 215 | * |
||
| 216 | * @param Context $context The context |
||
| 217 | * @param Context $mixinEnv The mixin environment |
||
| 218 | * @param array $arguments Array of arguments |
||
| 219 | * @param array $compiledArguments The compiled arguments |
||
| 220 | * |
||
| 221 | * @throws |
||
| 222 | * |
||
| 223 | * @return mixed |
||
| 224 | */ |
||
| 225 | public function compileParams( |
||
| 319 | |||
| 320 | /** |
||
| 321 | * Match a condition. |
||
| 322 | * |
||
| 323 | * @param array $arguments |
||
| 324 | * @param Context $context |
||
| 325 | * |
||
| 326 | * @return bool |
||
| 327 | */ |
||
| 328 | public function matchCondition(array $arguments, Context $context) |
||
| 350 | |||
| 351 | /** |
||
| 352 | * Matches arguments. |
||
| 353 | * |
||
| 354 | * @param array $args |
||
| 355 | * @param Context $context |
||
| 356 | * |
||
| 357 | * @return bool |
||
| 358 | */ |
||
| 359 | public function matchArgs(array $args, Context $context) |
||
| 395 | |||
| 396 | /** |
||
| 397 | * Returns ruleset with nodes marked as important. |
||
| 398 | * |
||
| 399 | * @return MixinDefinitionNode |
||
| 400 | */ |
||
| 401 | public function makeImportant() |
||
| 415 | } |
||
| 416 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..