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

MetaInf   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 56
Duplicated Lines 8.93 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 5
loc 56
ccs 0
cts 36
cp 0
rs 10
c 0
b 0
f 0
wmc 2
lcom 0
cbo 3

1 Method

Rating   Name   Duplication   Size   Complexity  
B writeManifest() 5 46 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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