Complex classes like FunctionsPrint 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 FunctionsPrint, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
26 | class FunctionsPrint { |
||
27 | |||
28 | /** |
||
29 | * Get an array converted to a list. For example |
||
30 | * array("red", "green", "yellow", "blue") => "red, green, yellow and blue" |
||
31 | * |
||
32 | * @param array $array Array to convert |
||
33 | * @return string List of elements |
||
34 | */ |
||
35 | static public function getListFromArray(array $array) { |
||
51 | |||
52 | /** |
||
53 | * Return HTML code to include a flag icon in facts description |
||
54 | * |
||
55 | * @param \Fisharebest\Webtrees\Fact $fact Fact record |
||
56 | * @param \MyArtJaub\Webtrees\Map\MapProviderInterface $mapProvider Map Provider |
||
57 | * @return string HTML code of the inserted flag |
||
58 | */ |
||
59 | public static function htmlFactPlaceIcon( |
||
72 | |||
73 | /** |
||
74 | * Return HTML code to include a flag icon |
||
75 | * |
||
76 | * @param \Fisharebest\Webtrees\Place $place |
||
77 | * @param string $icon_path |
||
78 | * @param number $size |
||
79 | * @return string HTML code of the inserted flag |
||
80 | */ |
||
81 | public static function htmlPlaceIcon(\Fisharebest\Webtrees\Place $place, $icon_path , $size = 50) { |
||
84 | |||
85 | /** |
||
86 | * Returns HTML code to display a tag cloud from a list. |
||
87 | * List must be a list of arrays (one for each item to display) containing the following parameters: |
||
88 | * - "text" : text to display |
||
89 | * - "count" : count of items |
||
90 | * - "url" : url to the item |
||
91 | * |
||
92 | * @param array $list Array of items to display in the cloud |
||
93 | * @param bool $totals Display totals for an items |
||
94 | * @return string Tag Cloud HTML Code |
||
95 | */ |
||
96 | public static function htmlListCloud($list, $totals) { |
||
128 | |||
129 | |||
130 | /** |
||
131 | * Returns HTML code to include a place cloud |
||
132 | * |
||
133 | * @param array $places Array of places to display in the cloud |
||
134 | * @param bool $totals Display totals for a place |
||
135 | * @param \Fisharebest\Webtrees\Tree $tree Tree |
||
136 | * @return string Place Cloud HTML Code |
||
137 | */ |
||
138 | public static function htmlPlacesCloud($places, $totals, Tree $tree) { |
||
153 | |||
154 | /** |
||
155 | * Return HTML Code to display individual in non structured list (e.g. Patronymic Lineages) |
||
156 | * |
||
157 | * @param \Fisharebest\Webtrees\Individual $individual Individual to print |
||
158 | * @param bool $isStrong Bolden the name ? |
||
159 | * @return string HTML Code for individual item |
||
160 | */ |
||
161 | public static function htmlIndividualForList(\Fisharebest\Webtrees\Individual $individual, $isStrong = true){ |
||
184 | |||
185 | /** |
||
186 | * Format date to display short (just years) |
||
187 | * |
||
188 | * @param \Fisharebest\Webtrees\Fact $eventObj Fact to display date |
||
189 | * @param boolean $anchor option to print a link to calendar |
||
190 | * @return string HTML code for short date |
||
191 | */ |
||
192 | public static function formatFactDateShort(\Fisharebest\Webtrees\Fact $fact, $anchor=false) { |
||
212 | |||
213 | /** |
||
214 | * Format fact place to display short |
||
215 | * |
||
216 | * @param \Fisharebest\Webtrees\Fact $eventObj Fact to display date |
||
217 | * @param string $format Format of the place |
||
218 | * @param boolean $anchor option to print a link to placelist |
||
219 | * @return string HTML code for short place |
||
220 | */ |
||
221 | public static function formatFactPlaceShort(\Fisharebest\Webtrees\Fact $fact, $format, $anchor=false){ |
||
232 | |||
233 | /** |
||
234 | * Format Sosa number to display next to individual details |
||
235 | * Possible format are: |
||
236 | * - 1 (default) : display an image if the individual is a Sosa, independently of the number of times he is |
||
237 | * - 2 : display a list of Sosa numbers, with an image, separated by an hyphen. |
||
238 | * |
||
239 | * @param array $sosatab List of Sosa numbers |
||
240 | * @param int $format Format to apply to the Sosa numbers |
||
241 | * @param string $size CSS size for the icon. A CSS style css_$size is required |
||
242 | * @return string HTML code for the formatted Sosa numbers |
||
243 | */ |
||
244 | public static function formatSosaNumbers(array $sosatab, $format = 1, $size = 'small'){ |
||
271 | |||
272 | /** |
||
273 | * Format IsSourced icons for display |
||
274 | * Possible format are: |
||
275 | * - 1 (default) : display an icon depending on the level of sources |
||
276 | * |
||
277 | * @param string $sourceType Type of the record : 'E', 'R' |
||
278 | * @param int $isSourced Level to display |
||
279 | * @param string $tag Fact to display status |
||
280 | * @param int $format Format to apply to the IsSourced parameter |
||
281 | * @param string $size CSS size for the icon. A CSS style css_$size is required |
||
282 | * @return string HTML code for IsSourced icon |
||
283 | */ |
||
284 | public static function formatIsSourcedIcon($sourceType, $isSourced, $tag='EVEN', $format = 1, $size='normal'){ |
||
350 | |||
351 | /** |
||
352 | * Check whether the date is compatible with the Google Chart range (between 1550 and 2030). |
||
353 | * |
||
354 | * @param Date $date |
||
355 | * @return boolean |
||
356 | */ |
||
357 | public static function isDateWithinChartsRange(Date $date) { |
||
360 | |||
361 | } |
||
362 |
In PHP, under loose comparison (like
==
, or!=
, orswitch
conditions), values of different types might be equal.For
string
values, the empty string''
is a special case, in particular the following results might be unexpected: