Complex classes like Page 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 Page, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
14 | class Page { |
||
15 | use |
||
16 | Singleton, |
||
17 | Includes; |
||
18 | public $Content; |
||
19 | public $interface = true; |
||
20 | public $pre_Html = ''; |
||
21 | public $Html = ''; |
||
22 | public $Description = ''; |
||
23 | /** |
||
24 | * @var string|string[] |
||
25 | */ |
||
26 | public $Title = []; |
||
27 | public $Head = ''; |
||
28 | public $pre_Body = ''; |
||
29 | public $Left = ''; |
||
30 | public $Top = ''; |
||
31 | public $Right = ''; |
||
32 | public $Bottom = ''; |
||
33 | public $post_Body = ''; |
||
34 | public $post_Html = ''; |
||
35 | /** |
||
36 | * Number of tabs by default for indentation the substitution of values into template |
||
37 | * |
||
38 | * @var array |
||
39 | */ |
||
40 | public $level = [ |
||
41 | 'Head' => 0, |
||
42 | 'pre_Body' => 1, |
||
43 | 'Left' => 3, |
||
44 | 'Top' => 3, |
||
45 | 'Content' => 4, |
||
46 | 'Bottom' => 3, |
||
47 | 'Right' => 3, |
||
48 | 'post_Body' => 1 |
||
49 | ]; |
||
50 | /** |
||
51 | * @var array[] |
||
52 | */ |
||
53 | protected $link = []; |
||
54 | /** |
||
55 | * @var string[] |
||
56 | */ |
||
57 | protected $search_replace = []; |
||
58 | /** |
||
59 | * @var false|string |
||
60 | */ |
||
61 | protected $canonical_url = false; |
||
62 | protected $theme; |
||
63 | protected $error_showed = false; |
||
64 | protected $finish_called_once = false; |
||
65 | /** |
||
66 | * @param string $property |
||
67 | * |
||
68 | * @return false|null|string |
||
69 | */ |
||
70 | function __get ($property) { |
||
99 | /** |
||
100 | * Initialization: setting of title and theme according to system configuration |
||
101 | * |
||
102 | * @return Page |
||
103 | */ |
||
104 | protected function init () { |
||
110 | /** |
||
111 | * Theme changing |
||
112 | * |
||
113 | * @param string $theme |
||
114 | * |
||
115 | * @return Page |
||
116 | */ |
||
117 | function set_theme ($theme) { |
||
121 | /** |
||
122 | * Adding of content on the page |
||
123 | * |
||
124 | * @param string $add |
||
125 | * @param bool|int $level |
||
126 | * |
||
127 | * @return Page |
||
128 | */ |
||
129 | function content ($add, $level = false) { |
||
137 | /** |
||
138 | * Sets body with content, that is transformed into JSON format |
||
139 | * |
||
140 | * @param mixed $add |
||
141 | * |
||
142 | * @return Page |
||
143 | */ |
||
144 | function json ($add) { |
||
150 | /** |
||
151 | * Loading of theme template |
||
152 | * |
||
153 | * @return bool |
||
154 | */ |
||
155 | protected function get_template () { |
||
187 | /** |
||
188 | * Processing of template, substituting of content, preparing for the output |
||
189 | * |
||
190 | * @return Page |
||
191 | */ |
||
192 | protected function prepare () { |
||
284 | /** |
||
285 | * @return string |
||
286 | */ |
||
287 | protected function get_favicon_path () { |
||
294 | /** |
||
295 | * @param string $property |
||
296 | * |
||
297 | * @return string |
||
298 | */ |
||
299 | protected function get_property_with_indentation ($property) { |
||
302 | /** |
||
303 | * Replacing anything in source code of finally generated page |
||
304 | * |
||
305 | * Parameters may be both simply strings for str_replace() and regular expressions for preg_replace() |
||
306 | * |
||
307 | * @param string|string[] $search |
||
308 | * @param string|string[] $replace |
||
309 | * |
||
310 | * @return Page |
||
311 | */ |
||
312 | function replace ($search, $replace = '') { |
||
321 | /** |
||
322 | * Processing of replacing in content |
||
323 | * |
||
324 | * @param string $content |
||
325 | * |
||
326 | * @return string |
||
327 | */ |
||
328 | protected function process_replacing ($content) { |
||
335 | /** |
||
336 | * Adding links |
||
337 | * |
||
338 | * @param array $data According to h class syntax |
||
339 | * |
||
340 | * @return Page |
||
341 | */ |
||
342 | function link ($data) { |
||
348 | /** |
||
349 | * Simple wrapper of $Page->link() for inserting Atom feed on page |
||
350 | * |
||
351 | * @param string $href |
||
352 | * @param string $title |
||
353 | * |
||
354 | * @return Page |
||
355 | */ |
||
356 | function atom ($href, $title = 'Atom Feed') { |
||
366 | /** |
||
367 | * Simple wrapper of $Page->link() for inserting RSS feed on page |
||
368 | * |
||
369 | * @param string $href |
||
370 | * @param string $title |
||
371 | * |
||
372 | * @return Page |
||
373 | */ |
||
374 | function rss ($href, $title = 'RSS Feed') { |
||
384 | /** |
||
385 | * Specify canonical url of current page |
||
386 | * |
||
387 | * @param string $url |
||
388 | * |
||
389 | * @return Page |
||
390 | */ |
||
391 | function canonical_url ($url) { |
||
399 | /** |
||
400 | * Adding text to the title page |
||
401 | * |
||
402 | * @param string $title |
||
403 | * @param bool $replace Replace whole title by this |
||
404 | * |
||
405 | * @return Page |
||
406 | */ |
||
407 | function title ($title, $replace = false) { |
||
416 | /** |
||
417 | * Display success message |
||
418 | * |
||
419 | * @param string $success_text |
||
420 | * |
||
421 | * @return Page |
||
422 | */ |
||
423 | function success ($success_text) { |
||
426 | /** |
||
427 | * Display notice message |
||
428 | * |
||
429 | * @param string $notice_text |
||
430 | * |
||
431 | * @return Page |
||
432 | */ |
||
433 | function notice ($notice_text) { |
||
436 | /** |
||
437 | * Display warning message |
||
438 | * |
||
439 | * @param string $warning_text |
||
440 | * |
||
441 | * @return Page |
||
442 | */ |
||
443 | function warning ($warning_text) { |
||
446 | /** |
||
447 | * Generic method for 3 methods above |
||
448 | * |
||
449 | * @param string $message |
||
450 | * @param string $class_ending |
||
451 | * |
||
452 | * @return Page |
||
453 | */ |
||
454 | protected function top_message ($message, $class_ending) { |
||
463 | /** |
||
464 | * Error pages processing |
||
465 | * |
||
466 | * @param null|string|string[] $custom_text Custom error text instead of text like "404 Not Found" or array with two elements: [error, error_description] |
||
467 | * @param bool $json Force JSON return format |
||
468 | * @param int $error_code HTTP status code |
||
469 | * |
||
470 | * @throws ExitException |
||
471 | */ |
||
472 | function error ($custom_text = null, $json = false, $error_code = 500) { |
||
521 | /** |
||
522 | * Provides next events: |
||
523 | * System/Page/display/before |
||
524 | * |
||
525 | * System/Page/display/after |
||
526 | * |
||
527 | * Page generation |
||
528 | */ |
||
529 | function __finish () { |
||
565 | } |
||
566 |
This function 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 function will be removed from the class and what other function to use instead.