Completed
Push — develop ( 782b4e...557e80 )
by Adrien
43:38
created

MetaInf::writeManifest()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 46
Code Lines 37

Duplication

Lines 5
Ratio 10.87 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
cc 2
eloc 37
nc 2
nop 0
dl 5
loc 46
ccs 0
cts 36
cp 0
crap 6
rs 8.9411
c 0
b 0
f 0
1
<?php
2
3
namespace PhpOffice\PhpSpreadsheet\Writer\Ods;
4
5
use PhpOffice\PhpSpreadsheet\Shared\XMLWriter;
6
use PhpOffice\PhpSpreadsheet\Spreadsheet;
7
8
class MetaInf extends WriterPart
9
{
10
    /**
11
     * Write META-INF/manifest.xml to XML format.
12
     *
13
     * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception
14
     *
15
     * @return string XML Output
16
     */
17
    public function writeManifest()
18
    {
19
        $objWriter = null;
0 ignored issues
show
Unused Code introduced by
$objWriter 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...
20 View Code Duplication
        if ($this->getParentWriter()->getUseDiskCaching()) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
21
            $objWriter = new XMLWriter(XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory());
22
        } else {
23
            $objWriter = new XMLWriter(XMLWriter::STORAGE_MEMORY);
24
        }
25
26
        // XML header
27
        $objWriter->startDocument('1.0', 'UTF-8');
28
29
        // Manifest
30
        $objWriter->startElement('manifest:manifest');
31
        $objWriter->writeAttribute('xmlns:manifest', 'urn:oasis:names:tc:opendocument:xmlns:manifest:1.0');
32
        $objWriter->writeAttribute('manifest:version', '1.2');
33
34
        $objWriter->startElement('manifest:file-entry');
35
        $objWriter->writeAttribute('manifest:full-path', '/');
36
        $objWriter->writeAttribute('manifest:version', '1.2');
37
        $objWriter->writeAttribute('manifest:media-type', 'application/vnd.oasis.opendocument.spreadsheet');
38
        $objWriter->endElement();
39
        $objWriter->startElement('manifest:file-entry');
40
        $objWriter->writeAttribute('manifest:full-path', 'meta.xml');
41
        $objWriter->writeAttribute('manifest:media-type', 'text/xml');
42
        $objWriter->endElement();
43
        $objWriter->startElement('manifest:file-entry');
44
        $objWriter->writeAttribute('manifest:full-path', 'settings.xml');
45
        $objWriter->writeAttribute('manifest:media-type', 'text/xml');
46
        $objWriter->endElement();
47
        $objWriter->startElement('manifest:file-entry');
48
        $objWriter->writeAttribute('manifest:full-path', 'content.xml');
49
        $objWriter->writeAttribute('manifest:media-type', 'text/xml');
50
        $objWriter->endElement();
51
        $objWriter->startElement('manifest:file-entry');
52
        $objWriter->writeAttribute('manifest:full-path', 'Thumbnails/thumbnail.png');
53
        $objWriter->writeAttribute('manifest:media-type', 'image/png');
54
        $objWriter->endElement();
55
        $objWriter->startElement('manifest:file-entry');
56
        $objWriter->writeAttribute('manifest:full-path', 'styles.xml');
57
        $objWriter->writeAttribute('manifest:media-type', 'text/xml');
58
        $objWriter->endElement();
59
        $objWriter->endElement();
60
61
        return $objWriter->getData();
62
    }
63
}
64