Complex classes like Refiller 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 Refiller, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
19 | class Refiller extends RefillerPlugin |
||
|
|||
20 | { |
||
21 | /** |
||
22 | * Name. |
||
23 | * |
||
24 | * @var string |
||
25 | */ |
||
26 | const NAME = 'world-art'; |
||
27 | |||
28 | /** |
||
29 | * Title. |
||
30 | * |
||
31 | * @var string |
||
32 | */ |
||
33 | const TITLE = 'World-Art.ru'; |
||
34 | |||
35 | /** |
||
36 | * List of supported fields. |
||
37 | * |
||
38 | * @var array |
||
39 | */ |
||
40 | protected $supported_fields = [ |
||
41 | self::FIELD_DATE_END, |
||
42 | self::FIELD_DATE_PREMIERE, |
||
43 | self::FIELD_DURATION, |
||
44 | self::FIELD_EPISODES, |
||
45 | self::FIELD_EPISODES_NUMBER, |
||
46 | self::FIELD_GENRES, |
||
47 | self::FIELD_IMAGES, |
||
48 | self::FIELD_COUNTRY, |
||
49 | self::FIELD_NAMES, |
||
50 | self::FIELD_STUDIO, |
||
51 | self::FIELD_SOURCES, |
||
52 | self::FIELD_SUMMARY, |
||
53 | ]; |
||
54 | |||
55 | /** |
||
56 | * Filler. |
||
57 | * |
||
58 | * @var \AnimeDb\Bundle\WorldArtFillerBundle\Service\Filler |
||
59 | */ |
||
60 | protected $filler; |
||
61 | |||
62 | /** |
||
63 | * Search. |
||
64 | * |
||
65 | * @var \AnimeDb\Bundle\WorldArtFillerBundle\Service\Search |
||
66 | */ |
||
67 | protected $search; |
||
68 | |||
69 | /** |
||
70 | * Browser. |
||
71 | * |
||
72 | * @var \AnimeDb\Bundle\WorldArtFillerBundle\Service\Browser |
||
73 | */ |
||
74 | private $browser; |
||
75 | |||
76 | /** |
||
77 | * Construct. |
||
78 | * |
||
79 | * @param \AnimeDb\Bundle\WorldArtFillerBundle\Service\Filler $filler |
||
80 | * @param \AnimeDb\Bundle\WorldArtFillerBundle\Service\Search $search |
||
81 | * @param \AnimeDb\Bundle\WorldArtFillerBundle\Service\Browser $browser |
||
82 | */ |
||
83 | public function __construct(Filler $filler, Search $search, Browser $browser) |
||
89 | |||
90 | /** |
||
91 | * Get name. |
||
92 | * |
||
93 | * @return string |
||
94 | */ |
||
95 | public function getName() |
||
99 | |||
100 | /** |
||
101 | * Get title. |
||
102 | * |
||
103 | * @return string |
||
104 | */ |
||
105 | public function getTitle() |
||
109 | |||
110 | /** |
||
111 | * Is can refill item from source. |
||
112 | * |
||
113 | * @param \AnimeDb\Bundle\CatalogBundle\Entity\Item $item |
||
114 | * @param string $field |
||
115 | * |
||
116 | * @return bool |
||
117 | */ |
||
118 | public function isCanRefill(Item $item, $field) |
||
122 | |||
123 | /** |
||
124 | * Refill item field from source. |
||
125 | * |
||
126 | * @param \AnimeDb\Bundle\CatalogBundle\Entity\Item $item |
||
127 | * @param string $field |
||
128 | * |
||
129 | * @return \AnimeDb\Bundle\CatalogBundle\Entity\Item |
||
130 | */ |
||
131 | public function refill(Item $item, $field) |
||
156 | |||
157 | /** |
||
158 | * Is can search. |
||
159 | * |
||
160 | * @param \AnimeDb\Bundle\CatalogBundle\Entity\Item $item |
||
161 | * @param string $field |
||
162 | * |
||
163 | * @return bool |
||
164 | */ |
||
165 | public function isCanSearch(Item $item, $field) |
||
182 | |||
183 | /** |
||
184 | * Search items for refill. |
||
185 | * |
||
186 | * @param \AnimeDb\Bundle\CatalogBundle\Entity\Item $item |
||
187 | * @param string $field |
||
188 | * |
||
189 | * @return array [\AnimeDb\Bundle\CatalogBundle\Plugin\Fill\Refiller\Item] |
||
190 | */ |
||
191 | public function search(Item $item, $field) |
||
235 | |||
236 | /** |
||
237 | * Refill item field from search result. |
||
238 | * |
||
239 | * @param \AnimeDb\Bundle\CatalogBundle\Entity\Item $item |
||
240 | * @param string $field |
||
241 | * @param array $data |
||
242 | * |
||
243 | * @return \AnimeDb\Bundle\CatalogBundle\Entity\Item |
||
244 | */ |
||
245 | public function refillFromSearchResult(Item $item, $field, array $data) |
||
256 | |||
257 | /** |
||
258 | * Fill item. |
||
259 | * |
||
260 | * @param \AnimeDb\Bundle\CatalogBundle\Entity\Item $item |
||
261 | * @param \AnimeDb\Bundle\CatalogBundle\Entity\Item $new_item |
||
262 | * @param string $field |
||
263 | * |
||
264 | * @return \AnimeDb\Bundle\CatalogBundle\Entity\Item |
||
265 | */ |
||
266 | protected function fillItem(Item $item, Item $new_item, $field) |
||
319 | |||
320 | /** |
||
321 | * Get source for fill. |
||
322 | * |
||
323 | * @param \AnimeDb\Bundle\CatalogBundle\Entity\Item $item |
||
324 | * |
||
325 | * @return string |
||
326 | */ |
||
327 | public function getSourceForFill(Item $item) |
||
338 | } |
||
339 |
This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.