Passed
Push — main ( 83c25f...829487 )
by Stefan
01:56
created
OPlathey/FPDF/FPDF.php 1 patch
Braces   +159 added lines, -120 removed lines patch added patch discarded remove patch
@@ -259,8 +259,9 @@  discard block
 block discarded – undo
259 259
         // Set left, top and right margins
260 260
         $this->lMargin = $left;
261 261
         $this->tMargin = $top;
262
-        if($right===null)
263
-            $right = $left;
262
+        if($right===null) {
263
+                    $right = $left;
264
+        }
264 265
         $this->rMargin = $right;
265 266
     }
266 267
 
@@ -274,8 +275,9 @@  discard block
 block discarded – undo
274 275
     {
275 276
         // Set left margin
276 277
         $this->lMargin = $margin;
277
-        if($this->page>0 && $this->x<$margin)
278
-            $this->x = $margin;
278
+        if($this->page>0 && $this->x<$margin) {
279
+                    $this->x = $margin;
280
+        }
279 281
     }
280 282
 
281 283
     /**
@@ -347,14 +349,16 @@  discard block
 block discarded – undo
347 349
     public function setDisplayMode($zoom, string $layout='default') : void
348 350
     {
349 351
         // Set display mode in viewer
350
-        if($zoom=='fullpage' || $zoom=='fullwidth' || $zoom=='real' || $zoom=='default' || !is_string($zoom))
351
-            $this->ZoomMode = $zoom;
352
-        else
353
-            $this->error('Incorrect zoom display mode: '.$zoom);
354
-        if($layout=='single' || $layout=='continuous' || $layout=='two' || $layout=='default')
355
-            $this->LayoutMode = $layout;
356
-        else
357
-            $this->error('Incorrect layout display mode: '.$layout);
352
+        if($zoom=='fullpage' || $zoom=='fullwidth' || $zoom=='real' || $zoom=='default' || !is_string($zoom)) {
353
+                    $this->ZoomMode = $zoom;
354
+        } else {
355
+                    $this->error('Incorrect zoom display mode: '.$zoom);
356
+        }
357
+        if($layout=='single' || $layout=='continuous' || $layout=='two' || $layout=='default') {
358
+                    $this->LayoutMode = $layout;
359
+        } else {
360
+                    $this->error('Incorrect layout display mode: '.$layout);
361
+        }
358 362
     }
359 363
 
360 364
     /**
@@ -369,10 +373,11 @@  discard block
 block discarded – undo
369 373
     public function setCompression(bool $compress) : void
370 374
     {
371 375
         // Set page compression
372
-        if(function_exists('gzcompress'))
373
-            $this->compress = $compress;
374
-        else
375
-            $this->compress = false;
376
+        if(function_exists('gzcompress')) {
377
+                    $this->compress = $compress;
378
+        } else {
379
+                    $this->compress = false;
380
+        }
376 381
     }
377 382
 
378 383
     /**
@@ -463,10 +468,12 @@  discard block
 block discarded – undo
463 468
     public function close() : void
464 469
     {
465 470
         // Terminate document
466
-        if($this->state==3)
467
-            return;
468
-        if($this->page==0)
469
-            $this->addPage();
471
+        if($this->state==3) {
472
+                    return;
473
+        }
474
+        if($this->page==0) {
475
+                    $this->addPage();
476
+        }
470 477
         // Page footer
471 478
         $this->InFooter = true;
472 479
         $this->footer();
@@ -682,8 +689,9 @@  discard block
 block discarded – undo
682 689
         $cw = &$this->CurrentFont['cw'];
683 690
         $w = 0;
684 691
         $l = strlen($s);
685
-        for($i=0;$i<$l;$i++)
686
-            $w += $cw[$s[$i]];
692
+        for($i=0;$i<$l;$i++) {
693
+                    $w += $cw[$s[$i]];
694
+        }
687 695
         return $w*$this->FontSize/1000;
688 696
     }
689 697
     
@@ -697,8 +705,9 @@  discard block
 block discarded – undo
697 705
     {
698 706
         // Set line width
699 707
         $this->LineWidth = $width;
700
-        if($this->page>0)
701
-            $this->out(sprintf('%.2F w',$width*$this->k));
708
+        if($this->page>0) {
709
+                    $this->out(sprintf('%.2F w',$width*$this->k));
710
+        }
702 711
     }
703 712
     
704 713
     /**
@@ -734,12 +743,13 @@  discard block
 block discarded – undo
734 743
     public function rect(float $x, float $y, float $w, float $h, string $style='') : void
735 744
     {
736 745
         // Draw a rectangle
737
-        if($style=='F')
738
-            $op = 'f';
739
-        elseif($style=='FD' || $style=='DF')
740
-            $op = 'B';
741
-        else
742
-            $op = 'S';
746
+        if($style=='F') {
747
+                    $op = 'f';
748
+        } elseif($style=='FD' || $style=='DF') {
749
+                    $op = 'B';
750
+        } else {
751
+                    $op = 'S';
752
+        }
743 753
         $this->out(sprintf('%.2F %.2F %.2F %.2F re %s',$x*$this->k,($this->h-$y)*$this->k,$w*$this->k,-$h*$this->k,$op));
744 754
     }
745 755
     
@@ -764,23 +774,27 @@  discard block
 block discarded – undo
764 774
     {
765 775
         // Add a TrueType, OpenType or Type1 font
766 776
         $family = strtolower($family);
767
-        if($file=='')
768
-            $file = str_replace(' ','',$family).strtolower($style).'.php';
777
+        if($file=='') {
778
+                    $file = str_replace(' ','',$family).strtolower($style).'.php';
779
+        }
769 780
         $style = strtoupper($style);
770
-        if($style=='IB')
771
-            $style = 'BI';
781
+        if($style=='IB') {
782
+                    $style = 'BI';
783
+        }
772 784
         $fontkey = $family.$style;
773
-        if(isset($this->fonts[$fontkey]))
774
-            return;
785
+        if(isset($this->fonts[$fontkey])) {
786
+                    return;
787
+        }
775 788
         $info = $this->loadFont($file);
776 789
         $info['i'] = count($this->fonts)+1;
777 790
         if(!empty($info['file']))
778 791
         {
779 792
             // Embedded font
780
-            if($info['type']=='TrueType')
781
-                $this->FontFiles[$info['file']] = array('length1'=>$info['originalsize']);
782
-            else
783
-                $this->FontFiles[$info['file']] = array('length1'=>$info['size1'], 'length2'=>$info['size2']);
793
+            if($info['type']=='TrueType') {
794
+                            $this->FontFiles[$info['file']] = array('length1'=>$info['originalsize']);
795
+            } else {
796
+                            $this->FontFiles[$info['file']] = array('length1'=>$info['size1'], 'length2'=>$info['size2']);
797
+            }
784 798
         }
785 799
         $this->fonts[$fontkey] = $info;
786 800
     }
@@ -823,42 +837,49 @@  discard block
 block discarded – undo
823 837
     public function setFont(string $family, string $style='', float $size=0) : void
824 838
     {
825 839
         // Select a font; size given in points
826
-        if($family=='')
827
-            $family = $this->FontFamily;
828
-        else
829
-            $family = strtolower($family);
840
+        if($family=='') {
841
+                    $family = $this->FontFamily;
842
+        } else {
843
+                    $family = strtolower($family);
844
+        }
830 845
         $style = strtoupper($style);
831 846
         if(strpos($style,'U')!==false)
832 847
         {
833 848
             $this->underline = true;
834 849
             $style = str_replace('U','',$style);
850
+        } else {
851
+                    $this->underline = false;
852
+        }
853
+        if($style=='IB') {
854
+                    $style = 'BI';
855
+        }
856
+        if($size==0) {
857
+                    $size = $this->FontSizePt;
835 858
         }
836
-        else
837
-            $this->underline = false;
838
-        if($style=='IB')
839
-            $style = 'BI';
840
-        if($size==0)
841
-            $size = $this->FontSizePt;
842 859
         // Test if font is already selected
843
-        if($this->FontFamily==$family && $this->FontStyle==$style && $this->FontSizePt==$size)
844
-            return;
860
+        if($this->FontFamily==$family && $this->FontStyle==$style && $this->FontSizePt==$size) {
861
+                    return;
862
+        }
845 863
         // Test if font is already loaded
846 864
         $fontkey = $family.$style;
847 865
         if(!isset($this->fonts[$fontkey]))
848 866
         {
849 867
             // Test if one of the core fonts
850
-            if($family=='arial')
851
-                $family = 'helvetica';
868
+            if($family=='arial') {
869
+                            $family = 'helvetica';
870
+            }
852 871
             if(in_array($family,$this->CoreFonts))
853 872
             {
854
-                if($family=='symbol' || $family=='zapfdingbats')
855
-                    $style = '';
873
+                if($family=='symbol' || $family=='zapfdingbats') {
874
+                                    $style = '';
875
+                }
856 876
                 $fontkey = $family.$style;
857
-                if(!isset($this->fonts[$fontkey]))
858
-                    $this->addFont($family,$style);
877
+                if(!isset($this->fonts[$fontkey])) {
878
+                                    $this->addFont($family,$style);
879
+                }
880
+            } else {
881
+                            $this->error('Undefined font: '.$family.' '.$style);
859 882
             }
860
-            else
861
-                $this->error('Undefined font: '.$family.' '.$style);
862 883
         }
863 884
         // Select it
864 885
         $this->FontFamily = $family;
@@ -866,8 +887,9 @@  discard block
 block discarded – undo
866 887
         $this->FontSizePt = $size;
867 888
         $this->FontSize = $size/$this->k;
868 889
         $this->CurrentFont = &$this->fonts[$fontkey];
869
-        if($this->page>0)
870
-            $this->out(sprintf('BT /F%d %.2F Tf ET',$this->CurrentFont['i'],$this->FontSizePt));
890
+        if($this->page>0) {
891
+                    $this->out(sprintf('BT /F%d %.2F Tf ET',$this->CurrentFont['i'],$this->FontSizePt));
892
+        }
871 893
     }
872 894
     
873 895
     /**
@@ -1135,16 +1157,19 @@  discard block
 block discarded – undo
1135 1157
     public function multiCell(float $w, float $h, string $txt, $border=0, string $align='J', bool $fill=false) : void
1136 1158
     {
1137 1159
         // Output text with automatic or explicit line breaks
1138
-        if(!isset($this->CurrentFont))
1139
-            $this->error('No font has been set');
1160
+        if(!isset($this->CurrentFont)) {
1161
+                    $this->error('No font has been set');
1162
+        }
1140 1163
         $cw = &$this->CurrentFont['cw'];
1141
-        if($w==0)
1142
-            $w = $this->w-$this->rMargin-$this->x;
1164
+        if($w==0) {
1165
+                    $w = $this->w-$this->rMargin-$this->x;
1166
+        }
1143 1167
         $wmax = ($w-2*$this->cMargin)*1000/$this->FontSize;
1144 1168
         $s = str_replace("\r",'',$txt);
1145 1169
         $nb = strlen($s);
1146
-        if($nb>0 && $s[$nb-1]=="\n")
1147
-            $nb--;
1170
+        if($nb>0 && $s[$nb-1]=="\n") {
1171
+                    $nb--;
1172
+        }
1148 1173
         $b = 0;
1149 1174
         $b2 = '';
1150 1175
         if($border)
@@ -1154,14 +1179,15 @@  discard block
 block discarded – undo
1154 1179
                 $border = 'LTRB';
1155 1180
                 $b = 'LRT';
1156 1181
                 $b2 = 'LR';
1157
-            }
1158
-            else
1182
+            } else
1159 1183
             {
1160 1184
                 $b2 = '';
1161
-                if(strpos($border,'L')!==false)
1162
-                    $b2 .= 'L';
1163
-                if(strpos($border,'R')!==false)
1164
-                    $b2 .= 'R';
1185
+                if(strpos($border,'L')!==false) {
1186
+                                    $b2 .= 'L';
1187
+                }
1188
+                if(strpos($border,'R')!==false) {
1189
+                                    $b2 .= 'R';
1190
+                }
1165 1191
                 $b = (strpos($border,'T')!==false) ? $b2.'T' : $b2;
1166 1192
             }
1167 1193
         }
@@ -1191,8 +1217,9 @@  discard block
 block discarded – undo
1191 1217
                 $l = 0;
1192 1218
                 $ns = 0;
1193 1219
                 $nl++;
1194
-                if($border && $nl==2)
1195
-                    $b = $b2;
1220
+                if($border && $nl==2) {
1221
+                                    $b = $b2;
1222
+                }
1196 1223
                 continue;
1197 1224
             }
1198 1225
             if($c==' ')
@@ -1207,16 +1234,16 @@  discard block
 block discarded – undo
1207 1234
                 // Automatic line break
1208 1235
                 if($sep==-1)
1209 1236
                 {
1210
-                    if($i==$j)
1211
-                        $i++;
1237
+                    if($i==$j) {
1238
+                                            $i++;
1239
+                    }
1212 1240
                     if($this->ws>0)
1213 1241
                     {
1214 1242
                         $this->ws = 0;
1215 1243
                         $this->out('0 Tw');
1216 1244
                     }
1217 1245
                     $this->cell($w,$h,substr($s,$j,$i-$j),$b,2,$align,$fill);
1218
-                }
1219
-                else
1246
+                } else
1220 1247
                 {
1221 1248
                     if($align=='J')
1222 1249
                     {
@@ -1231,11 +1258,12 @@  discard block
 block discarded – undo
1231 1258
                 $l = 0;
1232 1259
                 $ns = 0;
1233 1260
                 $nl++;
1234
-                if($border && $nl==2)
1235
-                    $b = $b2;
1261
+                if($border && $nl==2) {
1262
+                                    $b = $b2;
1263
+                }
1264
+            } else {
1265
+                            $i++;
1236 1266
             }
1237
-            else
1238
-                $i++;
1239 1267
         }
1240 1268
         // Last chunk
1241 1269
         if($this->ws>0)
@@ -1243,8 +1271,9 @@  discard block
 block discarded – undo
1243 1271
             $this->ws = 0;
1244 1272
             $this->out('0 Tw');
1245 1273
         }
1246
-        if($border && strpos($border,'B')!==false)
1247
-            $b .= 'B';
1274
+        if($border && strpos($border,'B')!==false) {
1275
+                    $b .= 'B';
1276
+        }
1248 1277
         $this->cell($w,$h,substr($s,$j,$i-$j),$b,2,$align,$fill);
1249 1278
         $this->x = $this->lMargin;
1250 1279
     }
@@ -1262,8 +1291,9 @@  discard block
 block discarded – undo
1262 1291
     public function write(float $h, string $txt, $link='') : void
1263 1292
     {
1264 1293
         // Output text in flowing mode
1265
-        if(!isset($this->CurrentFont))
1266
-            $this->error('No font has been set');
1294
+        if(!isset($this->CurrentFont)) {
1295
+                    $this->error('No font has been set');
1296
+        }
1267 1297
         $cw = &$this->CurrentFont['cw'];
1268 1298
         $w = $this->w-$this->rMargin-$this->x;
1269 1299
         $wmax = ($w-2*$this->cMargin)*1000/$this->FontSize;
@@ -1295,8 +1325,9 @@  discard block
 block discarded – undo
1295 1325
                 $nl++;
1296 1326
                 continue;
1297 1327
             }
1298
-            if($c==' ')
1299
-                $sep = $i;
1328
+            if($c==' ') {
1329
+                            $sep = $i;
1330
+            }
1300 1331
             $l += $cw[$c];
1301 1332
             if($l>$wmax)
1302 1333
             {
@@ -1314,11 +1345,11 @@  discard block
 block discarded – undo
1314 1345
                         $nl++;
1315 1346
                         continue;
1316 1347
                     }
1317
-                    if($i==$j)
1318
-                        $i++;
1348
+                    if($i==$j) {
1349
+                                            $i++;
1350
+                    }
1319 1351
                     $this->cell($w,$h,substr($s,$j,$i-$j),0,2,'',false,$link);
1320
-                }
1321
-                else
1352
+                } else
1322 1353
                 {
1323 1354
                     $this->cell($w,$h,substr($s,$j,$sep-$j),0,2,'',false,$link);
1324 1355
                     $i = $sep+1;
@@ -1333,13 +1364,14 @@  discard block
 block discarded – undo
1333 1364
                     $wmax = ($w-2*$this->cMargin)*1000/$this->FontSize;
1334 1365
                 }
1335 1366
                 $nl++;
1367
+            } else {
1368
+                            $i++;
1336 1369
             }
1337
-            else
1338
-                $i++;
1339 1370
         }
1340 1371
         // Last chunk
1341
-        if($i!=$j)
1342
-            $this->cell($l/1000*$this->FontSize,$h,substr($s,$j),0,0,'',false,$link);
1372
+        if($i!=$j) {
1373
+                    $this->cell($l/1000*$this->FontSize,$h,substr($s,$j),0,0,'',false,$link);
1374
+        }
1343 1375
     }
1344 1376
     
1345 1377
     /**
@@ -1353,10 +1385,11 @@  discard block
 block discarded – undo
1353 1385
     {
1354 1386
         // Line feed; default value is the last cell height
1355 1387
         $this->x = $this->lMargin;
1356
-        if($h===null)
1357
-            $this->y += $this->lasth;
1358
-        else
1359
-            $this->y += $h;
1388
+        if($h===null) {
1389
+                    $this->y += $this->lasth;
1390
+        } else {
1391
+                    $this->y += $h;
1392
+        }
1360 1393
     }
1361 1394
     
1362 1395
     /**
@@ -1534,10 +1567,11 @@  discard block
 block discarded – undo
1534 1567
     public function setX(float $x) : void
1535 1568
     {
1536 1569
         // Set x position
1537
-        if($x>=0)
1538
-            $this->x = $x;
1539
-        else
1540
-            $this->x = $this->w+$x;
1570
+        if($x>=0) {
1571
+                    $this->x = $x;
1572
+        } else {
1573
+                    $this->x = $this->w+$x;
1574
+        }
1541 1575
     }
1542 1576
 
1543 1577
     /**
@@ -1559,12 +1593,14 @@  discard block
 block discarded – undo
1559 1593
     public function setY(float $y, bool $resetX=true) : void
1560 1594
     {
1561 1595
         // Set y position and optionally reset x
1562
-        if($y>=0)
1563
-            $this->y = $y;
1564
-        else
1565
-            $this->y = $this->h+$y;
1566
-        if($resetX)
1567
-            $this->x = $this->lMargin;
1596
+        if($y>=0) {
1597
+                    $this->y = $y;
1598
+        } else {
1599
+                    $this->y = $this->h+$y;
1600
+        }
1601
+        if($resetX) {
1602
+                    $this->x = $this->lMargin;
1603
+        }
1568 1604
     }
1569 1605
     
1570 1606
     /**
@@ -1609,10 +1645,12 @@  discard block
 block discarded – undo
1609 1645
             $dest = $name;
1610 1646
             $name = $tmp;
1611 1647
         }
1612
-        if($dest=='')
1613
-            $dest = 'I';
1614
-        if($name=='')
1615
-            $name = 'doc.pdf';
1648
+        if($dest=='') {
1649
+                    $dest = 'I';
1650
+        }
1651
+        if($name=='') {
1652
+                    $name = 'doc.pdf';
1653
+        }
1616 1654
         switch(strtoupper($dest))
1617 1655
         {
1618 1656
             case 'I':
@@ -1639,8 +1677,9 @@  discard block
 block discarded – undo
1639 1677
                 break;
1640 1678
             case 'F':
1641 1679
                 // Save to local file
1642
-                if(!file_put_contents($name,$this->buffer))
1643
-                    $this->error('Unable to create output file: '.$name);
1680
+                if(!file_put_contents($name,$this->buffer)) {
1681
+                                    $this->error('Unable to create output file: '.$name);
1682
+                }
1644 1683
                 break;
1645 1684
             case 'S':
1646 1685
                 // Return as a string
@@ -2701,9 +2740,9 @@  discard block
 block discarded – undo
2701 2740
                     // Level increasing: set first pointer
2702 2741
                     $this->outlines[$parent]['first'] = $i;
2703 2742
                 }
2743
+            } else {
2744
+                            $this->outlines[$i]['parent'] = $nb;
2704 2745
             }
2705
-            else
2706
-                $this->outlines[$i]['parent'] = $nb;
2707 2746
                 if ($o['l'] <= $level && $i > 0) {
2708 2747
                     // Set prev and next pointers
2709 2748
                     $prev = $lru[$o['l']];
Please login to merge, or discard this patch.