Conditions | 2 |
Paths | 2 |
Total Lines | 56 |
Code Lines | 22 |
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 |
||
9 | public function pdfFile($dir = null, $pages=5, $title = '', $author = '', $subject = '', $keywords = '') |
||
10 | { |
||
11 | $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false); |
||
12 | |||
13 | // set document information |
||
14 | $pdf->SetCreator(PDF_CREATOR); |
||
15 | $pdf->SetAuthor($this->getAuthor($author)); |
||
16 | $pdf->SetTitle($this->getTitle($title)); |
||
17 | $pdf->SetSubject($this->getSubject($subject)); |
||
18 | $pdf->SetKeywords($this->getKeywords($keywords)); |
||
19 | |||
20 | // remove default header/footer |
||
21 | $pdf->setPrintHeader(false); |
||
22 | $pdf->setPrintFooter(false); |
||
23 | |||
24 | // set default monospaced font |
||
25 | $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED); |
||
26 | |||
27 | // set margins |
||
28 | $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT); |
||
29 | |||
30 | // set auto page breaks |
||
31 | $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM); |
||
32 | |||
33 | // set image scale factor |
||
34 | $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO); |
||
35 | |||
36 | // set some language-dependent strings (optional) |
||
37 | /*if (@file_exists(dirname(__FILE__).'/lang/eng.php')) { |
||
38 | require_once(dirname(__FILE__).'/lang/eng.php'); |
||
39 | $pdf->setLanguageArray($l); |
||
40 | }*/ |
||
41 | |||
42 | // set default font subsetting mode |
||
43 | $pdf->setFontSubsetting(true); |
||
44 | |||
45 | // Set font |
||
46 | // dejavusans is a UTF-8 Unicode font, if you only need to |
||
47 | // print standard ASCII chars, you can use core fonts like |
||
48 | // helvetica or times to reduce file size. |
||
49 | $pdf->SetFont('dejavusans', '', 14, '', true); |
||
50 | |||
51 | $pages = mt_rand(1, $pages); |
||
52 | |||
53 | for ($i = 0; $i < $pages; $i++) { |
||
54 | $pdf->AddPage(); |
||
55 | $html = $this->getPageHtml($i); |
||
56 | $pdf->writeHTMLCell(0, 0, '', '', $html, 0, 1, 0, true, '', true); |
||
57 | } |
||
58 | |||
59 | // Close and save PDF document |
||
60 | $fileName = $this->getFilename($dir); |
||
61 | |||
62 | $pdf->Output($fileName, 'F'); |
||
63 | |||
64 | return $fileName; |
||
65 | } |
||
125 |