Complex classes like Helper 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 Helper, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
30 | class Helper |
||
31 | { |
||
32 | /** |
||
33 | * @var ServiceManager |
||
34 | */ |
||
35 | protected $serviceManager; |
||
36 | |||
37 | /** |
||
38 | * @var \HaaseIT\HCSF\HelperConfig |
||
39 | */ |
||
40 | protected $config; |
||
41 | |||
42 | /** |
||
43 | * @var array |
||
44 | */ |
||
45 | protected $core = []; |
||
46 | |||
47 | /** |
||
48 | * @var array |
||
49 | */ |
||
50 | protected $secrets = []; |
||
51 | |||
52 | /** |
||
53 | * @var array |
||
54 | */ |
||
55 | protected $shop = []; |
||
56 | |||
57 | /** |
||
58 | * Helper constructor. |
||
59 | * @param ServiceManager $serviceManager |
||
60 | */ |
||
61 | public function __construct(ServiceManager $serviceManager) |
||
69 | |||
70 | public function getCleanRequestTarget() { |
||
82 | |||
83 | /** |
||
84 | * @param string $target |
||
85 | * @param bool $replace |
||
86 | * @param int $http_response_header |
||
87 | * @return void|false |
||
88 | */ |
||
89 | public function redirectToPage($target = '', $replace = false, $http_response_header = 302) |
||
98 | |||
99 | /** |
||
100 | * @param string $message |
||
101 | */ |
||
102 | public function terminateScript($message = '') |
||
106 | |||
107 | /** |
||
108 | * @param $number |
||
109 | * @return string |
||
110 | */ |
||
111 | public function formatNumber($number) |
||
120 | |||
121 | /** |
||
122 | * @param $file |
||
123 | * @param int $width |
||
124 | * @param int $height |
||
125 | * @return bool|string |
||
126 | */ |
||
127 | public function getSignedGlideURL($file, $width = 0, $height = 0) |
||
147 | |||
148 | /** |
||
149 | * @param $to |
||
150 | * @param string $subject |
||
151 | * @param string $message |
||
152 | * @param array $aImagesToEmbed |
||
153 | * @param array $aFilesToAttach |
||
154 | * @return bool |
||
155 | */ |
||
156 | public function mailWrapper($to, $subject = '(No subject)', $message = '', $aImagesToEmbed = [], $aFilesToAttach = []) { |
||
204 | |||
205 | // don't remove this, this is the fallback for unavailable twig functions |
||
206 | /** |
||
207 | * @param $string |
||
208 | * @return mixed |
||
209 | */ |
||
210 | public function reachThrough($string) { |
||
213 | // don't remove this, this is the fallback for unavailable twig functions |
||
214 | /** |
||
215 | * @return string |
||
216 | */ |
||
217 | public function returnEmptyString() { |
||
220 | |||
221 | /** |
||
222 | * @param array $aP |
||
223 | * @param Page $P |
||
224 | */ |
||
225 | public function getDebug($aP, $P) |
||
238 | |||
239 | /** |
||
240 | * @param string $purpose |
||
241 | * @return bool|\HTMLPurifier |
||
242 | */ |
||
243 | public function getPurifier($purpose) |
||
277 | |||
278 | /** |
||
279 | * @param $callback |
||
280 | * @param $parameters |
||
281 | * @return bool|mixed |
||
282 | */ |
||
283 | public function twigCallback($callback, $parameters) |
||
298 | |||
299 | /** |
||
300 | * @param \Doctrine\DBAL\Connection $dbal |
||
301 | * @param string $table |
||
302 | * @param array $data |
||
303 | * @return string |
||
304 | */ |
||
305 | public function autoInsert(\Doctrine\DBAL\Connection $dbal, $table, array $data) |
||
321 | } |
||
322 |