| Total Complexity | 43 |
| Total Lines | 164 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Complex classes like Theme 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 Theme, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 13 | final class Theme |
||
| 14 | { |
||
| 15 | /** |
||
| 16 | * @param array[] $fieldConfigs |
||
| 17 | */ |
||
| 18 | public function __construct( |
||
| 19 | private ?string $containerTag = null, |
||
| 20 | private array $containerAttributes = [], |
||
| 21 | private string|array|null $containerClass = null, |
||
| 22 | private ?bool $useContainer = null, |
||
| 23 | private ?string $template = null, |
||
| 24 | private ?string $templateBegin = null, |
||
| 25 | private ?string $templateEnd = null, |
||
| 26 | private ?bool $setInputId = null, |
||
| 27 | private array $inputAttributes = [], |
||
| 28 | private string|array|null $inputClass = null, |
||
| 29 | private ?string $inputContainerTag = null, |
||
| 30 | private array $inputContainerAttributes = [], |
||
| 31 | private string|array|null $inputContainerClass = null, |
||
| 32 | string|array|null $labelClass = null, |
||
| 33 | private array $labelConfig = [], |
||
| 34 | string|array|null $hintClass = null, |
||
| 35 | private array $hintConfig = [], |
||
| 36 | string|array|null $errorClass = null, |
||
| 37 | private array $errorConfig = [], |
||
| 38 | private ?bool $usePlaceholder = null, |
||
| 39 | private ?string $validClass = null, |
||
| 40 | private ?string $invalidClass = null, |
||
| 41 | private ?string $inputValidClass = null, |
||
| 42 | private ?string $inputInvalidClass = null, |
||
| 43 | private ?bool $enrichmentFromRules = null, |
||
| 44 | private array $fieldConfigs = [], |
||
| 45 | ) { |
||
| 46 | if ($labelClass !== null) { |
||
| 47 | $this->labelConfig['class()'] = is_array($labelClass) ? $labelClass : [$labelClass]; |
||
|
|
|||
| 48 | } |
||
| 49 | if ($hintClass !== null) { |
||
| 50 | $this->hintConfig['class()'] = is_array($hintClass) ? $hintClass : [$hintClass]; |
||
| 51 | } |
||
| 52 | if ($errorClass !== null) { |
||
| 53 | $this->errorConfig['class()'] = is_array($errorClass) ? $errorClass : [$errorClass]; |
||
| 54 | } |
||
| 55 | } |
||
| 56 | |||
| 57 | public function getLabelConfig(): array |
||
| 58 | { |
||
| 59 | return $this->labelConfig; |
||
| 60 | } |
||
| 61 | |||
| 62 | public function getHintConfig(): array |
||
| 65 | } |
||
| 66 | |||
| 67 | public function getErrorConfig(): array |
||
| 70 | } |
||
| 71 | |||
| 72 | /** |
||
| 73 | * @psalm-param class-string $class |
||
| 74 | */ |
||
| 75 | public function getFieldConfig(string $class): array |
||
| 177 | } |
||
| 178 | } |
||
| 179 |