Completed
Push — develop ( 069c66...25ff91 )
by Adrien
23:18
created

Dompdf   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 74.19%

Importance

Changes 0
Metric Value
dl 0
loc 63
ccs 23
cts 31
cp 0.7419
rs 10
c 0
b 0
f 0
wmc 9
lcom 1
cbo 5

1 Method

Rating   Name   Duplication   Size   Complexity  
C save() 0 53 9
1
<?php
2
3
namespace PhpOffice\PhpSpreadsheet\Writer\Pdf;
4
5
use PhpOffice\PhpSpreadsheet\Worksheet\PageSetup;
6
use PhpOffice\PhpSpreadsheet\Writer\IWriter;
7
use PhpOffice\PhpSpreadsheet\Writer\Pdf;
8
9
class Dompdf extends Pdf implements IWriter
10
{
11
    /**
12
     * Save Spreadsheet to file.
13
     *
14
     * @param string $pFilename Name of the file to save as
15
     *
16
     * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception
17
     */
18 2
    public function save($pFilename)
19
    {
20 2
        $fileHandle = parent::prepareForSave($pFilename);
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (prepareForSave() instead of save()). Are you sure this is correct? If so, you might want to change this to $this->prepareForSave().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
21
22
        //  Default PDF paper size
23 2
        $paperSize = 'LETTER'; //    Letter    (8.5 in. by 11 in.)
24
25
        //  Check for paper size and page orientation
26 2
        if ($this->getSheetIndex() === null) {
27
            $orientation = ($this->spreadsheet->getSheet(0)->getPageSetup()->getOrientation()
28
                == PageSetup::ORIENTATION_LANDSCAPE) ? 'L' : 'P';
29
            $printPaperSize = $this->spreadsheet->getSheet(0)->getPageSetup()->getPaperSize();
30
            $printMargins = $this->spreadsheet->getSheet(0)->getPageMargins();
0 ignored issues
show
Unused Code introduced by
$printMargins is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
31
        } else {
32 2
            $orientation = ($this->spreadsheet->getSheet($this->getSheetIndex())->getPageSetup()->getOrientation()
33 2
                == PageSetup::ORIENTATION_LANDSCAPE) ? 'L' : 'P';
34 2
            $printPaperSize = $this->spreadsheet->getSheet($this->getSheetIndex())->getPageSetup()->getPaperSize();
35 2
            $printMargins = $this->spreadsheet->getSheet($this->getSheetIndex())->getPageMargins();
0 ignored issues
show
Unused Code introduced by
$printMargins is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
36
        }
37
38 2
        $orientation = ($orientation == 'L') ? 'landscape' : 'portrait';
39
40
        //  Override Page Orientation
41 2
        if ($this->getOrientation() !== null) {
42
            $orientation = ($this->getOrientation() == PageSetup::ORIENTATION_DEFAULT)
43
                ? PageSetup::ORIENTATION_PORTRAIT
44
                : $this->getOrientation();
45
        }
46
        //  Override Paper Size
47 2
        if ($this->getPaperSize() !== null) {
48
            $printPaperSize = $this->getPaperSize();
49
        }
50
51 2
        if (isset(self::$paperSizes[$printPaperSize])) {
52 2
            $paperSize = self::$paperSizes[$printPaperSize];
53
        }
54
55
        //  Create PDF
56 2
        $pdf = new \Dompdf\Dompdf();
57 2
        $pdf->setPaper(strtolower($paperSize), $orientation);
58
59 2
        $pdf->loadHtml(
60 2
            $this->generateHTMLHeader(false) .
61 2
            $this->generateSheetData() .
62 2
            $this->generateHTMLFooter()
63
        );
64 2
        $pdf->render();
65
66
        //  Write to file
67 2
        fwrite($fileHandle, $pdf->output());
68
69 2
        parent::restoreStateAfterSave($fileHandle);
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (restoreStateAfterSave() instead of save()). Are you sure this is correct? If so, you might want to change this to $this->restoreStateAfterSave().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
70 2
    }
71
}
72