Conditions | 12 |
Paths | 432 |
Total Lines | 72 |
Code Lines | 61 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
69 | private function style_parcer($text, &$font_data){ |
||
70 | $str=trim(strtr($text, array("\r"=>'', "\t"=>''))); |
||
71 | $rep=array('[bB]{1}'=>'B', '[iI]{1}'=>'I', '[iI]{1}[ ]*[bB]{1}'=>'BI', '[bB]{1}[ ]*[iI]{1}'=>'BI' ); |
||
72 | foreach($rep as $a=>$v){ |
||
73 | $str=preg_replace('/<[ ]*'.$a.'[ ]*>/', "<$v>", $str); |
||
74 | $str=preg_replace('/<[ ]*\/+[ ]*'.$a.'[ ]*>/', "</$v>", $str); |
||
75 | } |
||
76 | $str=preg_replace('/<BI>/', '<s "font-weight:B;font-style:I">', $str); |
||
77 | $str=preg_replace('/<\/BI>/', "</s>", $str); |
||
78 | $str=preg_replace('/<B>/', '<s "font-weight:B;">', $str); |
||
79 | $str=preg_replace('/<\/B>/', "</s>", $str); |
||
80 | $str=preg_replace('/<I>/', '<s "font-style:I;">', $str); |
||
81 | $str=preg_replace('/<\/I>/', "</s>", $str); |
||
82 | $open=array(); |
||
83 | $total=array(); |
||
84 | $lt="<s"; |
||
85 | $rt="</s>"; |
||
86 | $j=strpos($str, $lt, 0); |
||
87 | while($j!==false){ |
||
88 | if($j>0 && ord($str[$j-1])==92){ |
||
89 | $j=strpos($str, $lt, $j+1); |
||
90 | continue; |
||
91 | } |
||
92 | $k=strpos($str, '>',$j+1); |
||
93 | $open[$j]=substr($str, $j+2, $k-($j+2)); |
||
94 | $total[]=$j; |
||
95 | $j=strpos($str, $lt, $j+1); |
||
96 | } |
||
97 | $j=strpos($str, $rt, 0); |
||
98 | while($j!==false){ |
||
99 | $total[]=$j; |
||
100 | $j=strpos($str, $rt, $j+1); |
||
101 | } |
||
102 | sort($total); |
||
103 | |||
104 | $cs=''; |
||
105 | foreach($font_data as $k=>$v){ |
||
106 | $cs.=$k . ':'. $v . '; '; |
||
107 | } |
||
108 | $cs=$this->get_style($cs); |
||
109 | $tmp=array($cs); |
||
110 | $blocks=array(); |
||
111 | $blockstyle=array(); |
||
112 | $n=count($total); |
||
113 | $k=0; |
||
114 | for($i=0; $i<$n; $i++){ |
||
115 | $blocks[]=substr($str, $k, $total[$i]-$k); |
||
116 | $blockstyle[]=$cs; |
||
117 | if(isset($open[$total[$i]])){ |
||
118 | $cs=$this->style_merge($cs, $this->get_style($open[$total[$i]])); |
||
119 | array_push($tmp, $cs); |
||
120 | $k=strpos($str, '>',$total[$i]+1)+1; |
||
121 | } |
||
122 | else{ |
||
123 | $k=$total[$i]+4; |
||
124 | array_pop($tmp); |
||
125 | $l=count($tmp)-1; |
||
126 | $cs=$tmp[$l]; |
||
127 | } |
||
128 | } |
||
129 | if($k<strlen($str)){ |
||
130 | $blocks[]=substr($str, $k); |
||
131 | $blockstyle[]=$cs; |
||
132 | } |
||
133 | $n=count($blocks); |
||
134 | for($i=0; $i<$n; $i++){ |
||
135 | $this->parced_str.=strtr($blocks[$i], array('\<s'=>'<s')); |
||
136 | if(strlen($blocks[$i])>0){ |
||
137 | $blockstyle[$i]['style']=$blockstyle[$i]['font-weight'] . $blockstyle[$i]['font-style']; |
||
138 | unset($blockstyle[$i]['font-weight']); |
||
139 | unset($blockstyle[$i]['font-style']); |
||
140 | $this->style_map[strlen($this->parced_str)-1]=$blockstyle[$i]; |
||
141 | } |
||
211 |
Using a closing tag in PHP files that only contain PHP code is not recommended as you might accidentally add whitespace after the closing tag which would then be output by PHP. This can cause severe problems, for example headers cannot be sent anymore.
A simple precaution is to leave off the closing tag as it is not required, and it also has no negative effects whatsoever.