Complex classes like YmlCatalog 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 YmlCatalog, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
20 | class YmlCatalog |
||
21 | { |
||
22 | /** |
||
23 | * @var BaseFileStream |
||
24 | */ |
||
25 | protected $handle; |
||
26 | /** |
||
27 | * @var string |
||
28 | */ |
||
29 | protected $shopClass; |
||
30 | /** |
||
31 | * @var string |
||
32 | */ |
||
33 | protected $currencyClass; |
||
34 | /** |
||
35 | * @var string |
||
36 | */ |
||
37 | protected $categoryClass; |
||
38 | /** |
||
39 | * @var null|string |
||
40 | */ |
||
41 | protected $localDeliveryCostClass; |
||
42 | /** |
||
43 | * @var string |
||
44 | */ |
||
45 | protected $offerClass; |
||
46 | /** |
||
47 | * @var null|string |
||
48 | */ |
||
49 | protected $date; |
||
50 | |||
51 | /** |
||
52 | * @var null|callable |
||
53 | */ |
||
54 | protected $onValidationError; |
||
55 | |||
56 | /** |
||
57 | * @var null|string |
||
58 | */ |
||
59 | protected $customOfferClass; |
||
60 | |||
61 | /** |
||
62 | * @var null|string |
||
63 | */ |
||
64 | protected $deliveryOptionClass; |
||
65 | |||
66 | /** |
||
67 | * @var ActiveQuery |
||
68 | */ |
||
69 | private $query = null; |
||
70 | |||
71 | 9 | /** |
|
72 | * @var BatchQueryResult |
||
73 | */ |
||
74 | 2 | private $queryIterator = null; |
|
75 | |||
76 | /** |
||
77 | * @var ActiveDataProvider |
||
78 | */ |
||
79 | private $dataProvider = null; |
||
80 | |||
81 | /** |
||
82 | 9 | * @var Pagination |
|
83 | 9 | */ |
|
84 | 9 | private $pagination = null; |
|
85 | 9 | ||
86 | 9 | /** |
|
87 | 9 | * @param BaseFileStream $handle |
|
88 | 9 | * @param string $shopClass class name |
|
89 | 9 | * @param string $currencyClass class name |
|
90 | 9 | * @param string $categoryClass class name |
|
91 | 9 | * @param string $localDeliveryCostClass class name |
|
92 | * @param array $offerClasses |
||
93 | * @param null|string $date |
||
94 | * @param null|callable $onValidationError |
||
95 | * @param null|string $customOfferClass |
||
96 | 9 | */ |
|
97 | public function __construct( |
||
120 | 8 | ||
121 | /** |
||
122 | 6 | * @throws Exception |
|
123 | 6 | */ |
|
124 | public function generate() |
||
159 | |||
160 | /** |
||
161 | 9 | * @return null|string |
|
162 | */ |
||
163 | 9 | protected function getDate() |
|
173 | 6 | ||
174 | 4 | /** |
|
175 | 9 | * @param string $string |
|
176 | 6 | * @throws \Exception |
|
177 | 4 | */ |
|
178 | protected function write($string) |
||
182 | 6 | ||
183 | 3 | /** |
|
184 | * @param string $string tag name |
||
185 | 6 | */ |
|
186 | 9 | protected function writeTag($string) |
|
190 | 9 | ||
191 | /** |
||
192 | * @param BaseModel $model |
||
193 | * @param $valuesModel |
||
194 | * @throws Exception |
||
195 | 9 | */ |
|
196 | protected function writeModel(BaseModel $model, $valuesModel) |
||
213 | |||
214 | /** |
||
215 | * @param string|array $modelClass class name |
||
216 | */ |
||
217 | 9 | protected function writeEachModel($modelClass) |
|
279 | |||
280 | /** |
||
281 | * @return Model[]|false |
||
282 | */ |
||
283 | protected function getModels() |
||
311 | |||
312 | /** |
||
313 | * @param $modelClass |
||
314 | * @return Category|Currency|SimpleOffer |
||
315 | * @throws Exception |
||
316 | */ |
||
317 | protected function getNewModel($modelClass) |
||
335 | |||
336 | /** |
||
337 | * Performs PHP memory garbage collection. |
||
338 | */ |
||
339 | protected function gc() |
||
346 | } |
||
347 |
An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.
If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.