| Conditions | 24 | 
| Paths | 2698 | 
| Total Lines | 118 | 
| Lines | 0 | 
| Ratio | 0 % | 
| Changes | 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 | ||
| 306 | function MakeFont($fontfile,$afmfile,$enc='cp1252',$patch=array(),$type='TrueType') | ||
| 307 | { | ||
| 308 | //Generate a font definition file | ||
| 309 | set_magic_quotes_runtime(0); | ||
| 310 |   ini_set('auto_detect_line_endings','1'); | ||
| 311 | if($enc) | ||
| 312 |   { | ||
| 313 | $map=ReadMap($enc); | ||
| 314 | foreach($patch as $cc=>$gn) | ||
| 315 | $map[$cc]=$gn; | ||
| 316 | } | ||
| 317 | else | ||
| 318 | $map=array(); | ||
| 319 | if(!file_exists($afmfile)) | ||
| 320 |     die('<B>Error:</B> AFM file not found: '.$afmfile); | ||
| 321 | $fm=ReadAFM($afmfile,$map); | ||
| 322 | if($enc) | ||
| 323 | $diff=MakeFontEncoding($map); | ||
| 324 | else | ||
| 325 | $diff=''; | ||
| 326 | $fd=MakeFontDescriptor($fm,empty($map)); | ||
| 327 | //Find font type | ||
| 328 | if($fontfile) | ||
| 329 |   { | ||
| 330 | $ext=strtolower(substr($fontfile,-3)); | ||
| 331 | if($ext=='ttf') | ||
| 332 | $type='TrueType'; | ||
| 333 | elseif($ext=='pfb') | ||
| 334 | $type='Type1'; | ||
| 335 | else | ||
| 336 |       die('<B>Error:</B> unrecognized font file extension: '.$ext); | ||
| 337 | } | ||
| 338 | else | ||
| 339 |   { | ||
| 340 | if($type!='TrueType' and $type!='Type1') | ||
| 341 |       die('<B>Error:</B> incorrect font type: '.$type); | ||
| 342 | } | ||
| 343 | //Start generation | ||
| 344 | $s='<?php'."\n"; | ||
| 345 | $s.='$type=\''.$type."';\n"; | ||
| 346 | $s.='$name=\''.$fm['FontName']."';\n"; | ||
| 347 | $s.='$desc='.$fd.";\n"; | ||
| 348 | if(!isset($fm['UnderlinePosition'])) | ||
| 349 | $fm['UnderlinePosition']=-100; | ||
| 350 | if(!isset($fm['UnderlineThickness'])) | ||
| 351 | $fm['UnderlineThickness']=50; | ||
| 352 | $s.='$up='.$fm['UnderlinePosition'].";\n"; | ||
| 353 | $s.='$ut='.$fm['UnderlineThickness'].";\n"; | ||
| 354 | $w=MakeWidthArray($fm); | ||
| 355 | $s.='$cw='.$w.";\n"; | ||
| 356 | $s.='$enc=\''.$enc."';\n"; | ||
| 357 | $s.='$diff=\''.$diff."';\n"; | ||
| 358 | $basename=substr(basename($afmfile),0,-4); | ||
| 359 | if($fontfile) | ||
| 360 |   { | ||
| 361 | //Embedded font | ||
| 362 | if(!file_exists($fontfile)) | ||
| 363 |       die('<B>Error:</B> font file not found: '.$fontfile); | ||
| 364 | if($type=='TrueType') | ||
| 365 | CheckTTF($fontfile); | ||
| 366 | $f=fopen($fontfile,'rb'); | ||
| 367 | if(!$f) | ||
| 368 |       die('<B>Error:</B> Can\'t open '.$fontfile); | ||
| 369 | $file=fread($f,filesize($fontfile)); | ||
| 370 | fclose($f); | ||
| 371 | if($type=='Type1') | ||
| 372 |     { | ||
| 373 | //Find first two sections and discard third one | ||
| 374 |       $header=(ord($file{0})==128); | ||
| 375 | if($header) | ||
| 376 |       { | ||
| 377 | //Strip first binary header | ||
| 378 | $file=substr($file,6); | ||
| 379 | } | ||
| 380 | $pos=strpos($file,'eexec'); | ||
| 381 | if(!$pos) | ||
| 382 |         die('<B>Error:</B> font file does not seem to be valid Type1'); | ||
| 383 | $size1=$pos+6; | ||
| 384 |       if($header and ord($file{$size1})==128) | ||
| 385 |       { | ||
| 386 | //Strip second binary header | ||
| 387 | $file=substr($file,0,$size1).substr($file,$size1+6); | ||
| 388 | } | ||
| 389 | $pos=strpos($file,'00000000'); | ||
| 390 | if(!$pos) | ||
| 391 |         die('<B>Error:</B> font file does not seem to be valid Type1'); | ||
| 392 | $size2=$pos-$size1; | ||
| 393 | $file=substr($file,0,$size1+$size2); | ||
| 394 | } | ||
| 395 |     if(function_exists('gzcompress')) | ||
| 396 |     { | ||
| 397 | $cmp=$basename.'.z'; | ||
| 398 | SaveToFile($cmp,gzcompress($file),'b'); | ||
| 399 | $s.='$file=\''.$cmp."';\n"; | ||
| 400 |       echo 'Font file compressed ('.$cmp.')<BR>'; | ||
| 401 | } | ||
| 402 | else | ||
| 403 |     { | ||
| 404 | $s.='$file=\''.basename($fontfile)."';\n"; | ||
| 405 | echo '<B>Notice:</B> font file could not be compressed (zlib extension not available)<BR>'; | ||
| 406 | } | ||
| 407 | if($type=='Type1') | ||
| 408 |     { | ||
| 409 | $s.='$size1='.$size1.";\n"; | ||
| 410 | $s.='$size2='.$size2.";\n"; | ||
| 411 | } | ||
| 412 | else | ||
| 413 | $s.='$originalsize='.filesize($fontfile).";\n"; | ||
| 414 | } | ||
| 415 | else | ||
| 416 |   { | ||
| 417 | //Not embedded font | ||
| 418 | $s.='$file='."'';\n"; | ||
| 419 | } | ||
| 420 | $s.="?>\n"; | ||
| 421 | SaveToFile($basename.'.php',$s); | ||
| 422 |   echo 'Font definition file generated ('.$basename.'.php'.')<BR>'; | ||
| 423 | } | ||
| 424 | 
This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.