Complex classes like pinp_FPDF 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 pinp_FPDF, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
13 | class pinp_FPDF extends FPDF |
||
14 | { |
||
15 | |||
16 | public function __construct ($orientation='P',$unit='mm',$format='A4') |
||
29 | |||
30 | public function _SetMargins($left,$top,$right=-1) |
||
34 | |||
35 | public function _SetLeftMargin($margin) |
||
39 | |||
40 | public function _SetTopMargin($margin) |
||
44 | |||
45 | public function _SetRightMargin($margin) |
||
49 | |||
50 | public function _SetAutoPageBreak($auto,$margin=0) |
||
54 | |||
55 | public function _SetDisplayMode($zoom,$layout='continuous') |
||
59 | |||
60 | public function _SetCompression($compress) |
||
64 | |||
65 | public function _SetTitle($title) |
||
69 | |||
70 | public function _SetSubject($subject) |
||
74 | |||
75 | public function _SetAuthor($author) |
||
79 | |||
80 | public function _SetKeywords($keywords) |
||
84 | |||
85 | public function _SetCreator($creator) |
||
89 | |||
90 | public function _AliasNbPages($alias='{nb}') |
||
94 | |||
95 | public function _Error($msg) |
||
99 | |||
100 | public function _Open() |
||
104 | |||
105 | public function _Close() |
||
109 | |||
110 | public function _AddPage($orientation='') |
||
114 | |||
115 | public function _Header() |
||
119 | |||
120 | public function _Footer() |
||
124 | |||
125 | public function _PageNo() |
||
129 | |||
130 | public function _SetDrawColor($r,$g=-1,$b=-1) |
||
134 | |||
135 | public function _SetFillColor($r,$g=-1,$b=-1) |
||
139 | |||
140 | public function _SetTextColor($r,$g=-1,$b=-1) |
||
144 | |||
145 | public function _GetStringWidth($s) |
||
149 | |||
150 | public function _SetLineWidth($width) |
||
154 | |||
155 | public function _Line($x1,$y1,$x2,$y2) |
||
159 | |||
160 | public function _Rect($x,$y,$w,$h,$style='') |
||
164 | |||
165 | public function _AddFont($family,$style='',$file='') |
||
171 | |||
172 | public function _SetFont($family,$style='',$size=0) |
||
176 | |||
177 | public function _SetFontSize($size) |
||
181 | |||
182 | public function _AddLink() |
||
186 | |||
187 | public function _SetLink($link,$y=0,$page=-1) |
||
191 | |||
192 | public function _Link($x,$y,$w,$h,$link) |
||
196 | |||
197 | public function _Text($x,$y,$txt) |
||
201 | |||
202 | public function _AcceptPageBreak() |
||
206 | |||
207 | public function _Cell($w,$h=0,$txt='',$border=0,$ln=0,$align='',$fill=0,$link='') |
||
211 | |||
212 | public function _MultiCell($w,$h,$txt,$border=0,$align='J',$fill=0) |
||
216 | |||
217 | public function _Write($h,$txt,$link='') |
||
221 | |||
222 | public function _Image($file,$x,$y,$w,$h=0,$type='',$link='') |
||
226 | |||
227 | public function _Ln($h='') |
||
231 | |||
232 | public function _GetX() |
||
236 | |||
237 | public function _SetX($x) |
||
241 | |||
242 | public function _GetY() |
||
246 | |||
247 | public function _SetY($y) |
||
251 | |||
252 | public function _SetXY($x,$y) |
||
256 | |||
257 | public function _Output($file='',$download=false) |
||
261 | |||
262 | public function _WriteHTML($html) |
||
266 | |||
267 | public function _OpenTag($tag,$attr) |
||
271 | |||
272 | public function _CloseTag($tag) |
||
276 | |||
277 | public function _SetStyle($tag,$enable) |
||
281 | |||
282 | public function _PutLink($URL,$txt) |
||
286 | |||
287 | // code originally from HTML2PDF by Cl�ment Lavoillotte |
||
288 | // [email protected] |
||
289 | // [email protected] |
||
290 | // http://www.streetpc.tk |
||
291 | |||
292 | // function hex2dec |
||
293 | // returns an associative array (keys: R,G,B) from |
||
294 | // a hex html code (e.g. #3FE5AA) |
||
295 | public function hex2dec($color = "#000000"){ |
||
308 | |||
309 | // conversion pixel -> millimeter in 72 dpi |
||
310 | public function px2mm($px){ |
||
313 | |||
314 | public function txtentities($html){ |
||
319 | |||
320 | //variables of html parser |
||
321 | protected $B; |
||
322 | protected $I; |
||
323 | protected $U; |
||
324 | protected $HREF; |
||
325 | protected $fontList; |
||
326 | protected $issetfont; |
||
327 | protected $issetcolor; |
||
328 | |||
329 | public function WriteHTML($html) |
||
365 | |||
366 | public function OpenTag($tag,$attr) |
||
419 | |||
420 | public function CloseTag($tag) |
||
441 | |||
442 | public function SetStyle($tag,$enable) |
||
452 | |||
453 | public function PutLink($URL,$txt) |
||
462 | |||
463 | //End of class |
||
464 | } |
||
465 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.