Total Complexity | 92 |
Total Lines | 369 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
Complex classes like exFPDF 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.
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 exFPDF, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
11 | class exFPDF extends FPDF |
||
12 | { |
||
13 | public function PageBreak(){ |
||
14 | return $this->PageBreakTrigger; |
||
15 | } |
||
16 | |||
17 | public function current_font($c){ |
||
18 | if($c=='family'){ |
||
19 | return $this->FontFamily; |
||
20 | } |
||
21 | elseif($c=='style'){ |
||
22 | return $this->FontStyle; |
||
23 | } |
||
24 | elseif($c=='size'){ |
||
25 | return $this->FontSizePt; |
||
26 | } |
||
27 | } |
||
28 | |||
29 | public function get_color($c){ |
||
30 | if($c=='fill'){ |
||
31 | return $this->FillColor; |
||
32 | } |
||
33 | elseif($c=='text'){ |
||
34 | return $this->TextColor; |
||
35 | } |
||
36 | } |
||
37 | |||
38 | public function get_page_width(){ |
||
39 | return $this->w; |
||
40 | } |
||
41 | |||
42 | public function get_margin($c){ |
||
43 | if($c=='l'){ |
||
44 | return $this->lMargin; |
||
45 | } |
||
46 | elseif($c=='r'){ |
||
47 | return $this->rMargin; |
||
48 | } |
||
49 | elseif($c=='t'){ |
||
50 | return $this->tMargin; |
||
51 | } |
||
52 | } |
||
53 | |||
54 | public function get_linewidth(){ |
||
55 | return $this->LineWidth; |
||
56 | } |
||
57 | |||
58 | public function get_orientation(){ |
||
59 | return $this->CurOrientation; |
||
60 | } |
||
61 | static private $hex=array('0'=>0,'1'=>1,'2'=>2,'3'=>3,'4'=>4,'5'=>5,'6'=>6,'7'=>7,'8'=>8,'9'=>9, |
||
62 | 'A'=>10,'B'=>11,'C'=>12,'D'=>13,'E'=>14,'F'=>15); |
||
63 | |||
64 | public function is_rgb($str){ |
||
65 | $a=true; |
||
66 | $tmp=explode(',', trim($str, ',')); |
||
67 | foreach($tmp as $color){ |
||
68 | if(!is_numeric($color) || $color<0 || $color>255){ |
||
69 | $a=false; |
||
70 | break; |
||
71 | } |
||
72 | } |
||
73 | return $a; |
||
74 | } |
||
75 | |||
76 | public function is_hex($str){ |
||
92 | } |
||
93 | |||
94 | public function hextodec($str){ |
||
95 | $result=array(); |
||
96 | $str=strtoupper(substr($str,1)); |
||
97 | $n=strlen($str); |
||
98 | for($i=0; $i<3; $i++){ |
||
99 | if($n==6){ |
||
100 | $result[$i]=self::$hex[$str[2*$i]]*16+self::$hex[$str[2*$i+1]]; |
||
101 | } |
||
102 | else{ |
||
103 | $result[$i]=self::$hex[$str[$i]]*16+self::$hex[$str[$i]]; |
||
104 | } |
||
105 | } |
||
106 | return $result; |
||
107 | } |
||
108 | static private $options=array('F'=>'', 'T'=>'', 'D'=>''); |
||
109 | |||
110 | public function resetColor($str, $p='F'){ |
||
111 | if(isset(self::$options[$p]) && self::$options[$p]!=$str){ |
||
112 | self::$options[$p]=$str; |
||
113 | $array=array(); |
||
114 | if($this->is_hex($str)){ |
||
115 | $array=$this->hextodec($str); |
||
116 | } |
||
117 | elseif($this->is_rgb($str)){ |
||
118 | $array=explode(',', trim($str, ',')); |
||
119 | for($i=0; $i<3; $i++){ |
||
120 | if(!isset($array[$i])){ |
||
121 | $array[$i]=0; |
||
122 | } |
||
123 | } |
||
124 | } |
||
125 | else{ |
||
126 | $array=array(null, null, null); |
||
127 | $i=0; |
||
128 | $tmp=explode(' ', $str); |
||
129 | foreach($tmp as $c){ |
||
130 | if(is_numeric($c)){ |
||
131 | $array[$i]=$c*256; |
||
132 | $i++; |
||
133 | } |
||
134 | } |
||
135 | } |
||
136 | if($p=='T'){ |
||
137 | $this->SetTextColor($array[0],$array[1],$array[2]); |
||
138 | } |
||
139 | elseif($p=='D'){ |
||
140 | $this->SetDrawColor($array[0],$array[1], $array[2]); |
||
141 | } |
||
142 | elseif($p=='F'){ |
||
143 | $this->SetFillColor($array[0],$array[1],$array[2]); |
||
144 | } |
||
145 | } |
||
146 | } |
||
147 | static private $font_def=''; |
||
148 | |||
149 | public function resetFont($font_family, $font_style, $font_size){ |
||
150 | if(self::$font_def!=$font_family .'-' . $font_style . '-' .$font_size){ |
||
151 | self::$font_def=$font_family .'-' . $font_style . '-' .$font_size; |
||
152 | $this->SetFont($font_family, $font_style, $font_size); |
||
153 | } |
||
154 | } |
||
155 | |||
156 | public function resetStaticData(){ |
||
157 | self::$font_def=''; |
||
158 | self::$options=array('F'=>'', 'T'=>'', 'D'=>''); |
||
159 | } |
||
160 | /*********************************************************************** |
||
161 | * |
||
162 | * Based on FPDF method SetFont |
||
163 | * |
||
164 | ************************************************************************/ |
||
165 | |||
166 | private function &FontData($family, $style, $size){ |
||
167 | if($family=='') |
||
168 | $family = $this->FontFamily; |
||
169 | else |
||
170 | $family = strtolower($family); |
||
171 | $style = strtoupper($style); |
||
172 | if(strpos($style,'U')!==false){ |
||
173 | $this->underline = true; |
||
174 | $style = str_replace('U','',$style); |
||
175 | } |
||
176 | if($style=='IB') |
||
177 | $style = 'BI'; |
||
178 | $fontkey = $family.$style; |
||
179 | if(!isset($this->fonts[$fontkey])){ |
||
180 | if($family=='arial') |
||
181 | $family = 'helvetica'; |
||
182 | if(in_array($family,$this->CoreFonts)){ |
||
183 | if($family=='symbol' || $family=='zapfdingbats') |
||
184 | $style = ''; |
||
185 | $fontkey = $family.$style; |
||
186 | if(!isset($this->fonts[$fontkey])) |
||
187 | $this->AddFont($family,$style); |
||
188 | } |
||
189 | else |
||
190 | $this->Error('Undefined font: '.$family.' '.$style); |
||
191 | } |
||
192 | $result['FontSize'] = $size/$this->k; |
||
|
|||
193 | $result['CurrentFont']=&$this->fonts[$fontkey]; |
||
194 | return $result; |
||
195 | } |
||
196 | |||
197 | |||
198 | private function setLines(&$fstring, $p, $q){ |
||
262 | } |
||
263 | |||
264 | public function &extMultiCell($font_family, $font_style, $font_size, $font_color, $w, $txt){ |
||
265 | $result=array(); |
||
266 | if($w==0){ |
||
267 | return $result; |
||
268 | } |
||
269 | $this->current_font=array('font-family'=>$font_family, 'style'=>$font_style, 'font-size'=>$font_size, 'font-color'=>$font_color); |
||
270 | $fstring=new formatedString($txt, $w, $this->current_font); |
||
271 | $word=''; |
||
272 | $p=0; |
||
273 | $i=0; |
||
274 | $n=strlen($fstring->parced_str); |
||
275 | while($i<$n){ |
||
276 | $word.=$fstring->parced_str[$i]; |
||
277 | if($fstring->parced_str[$i]=="\n" || $fstring->parced_str[$i]==' ' || $i==$n-1){ |
||
278 | $word=trim($word); |
||
279 | $this->setLines($fstring, $p, strlen($word)); |
||
280 | $p=$i+1; |
||
281 | $word=''; |
||
282 | if($fstring->parced_str[$i]=="\n" && $i<$n-1){ |
||
283 | $z=0; |
||
284 | $j=count($fstring->lines); |
||
285 | $fstring->lines[$j]=''; |
||
286 | $fstring->linesmap[$j]=array(); |
||
287 | } |
||
288 | } |
||
289 | $i++; |
||
290 | } |
||
291 | if($n==0){ |
||
292 | return $result; |
||
293 | } |
||
294 | $n=count($fstring->lines); |
||
295 | for($i=0; $i<$n; $i++){ |
||
296 | $result[$i]=$fstring->break_by_style($i); |
||
297 | } |
||
298 | return $result; |
||
299 | } |
||
300 | |||
301 | private function GetMixStringWidth($line){ |
||
315 | } |
||
316 | |||
317 | public function CellBlock($w, $lh, &$lines, $align='J'){ |
||
380 | } |
||
381 | } |
||
382 | |||
383 | } |
||
384 | ?> |
||
385 |