Completed
Pull Request — develop (#207)
by Franck
24:36 queued 20:39
created

Pictures::render()   C

Complexity

Conditions 10
Paths 24

Size

Total Lines 53
Code Lines 36

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 42
CRAP Score 10

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 53
ccs 42
cts 42
cp 1
rs 6.5333
cc 10
eloc 36
nc 24
nop 0
crap 10

How to fix   Long Method    Complexity   

Long Method

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:

1
<?php
2
3
namespace PhpOffice\PhpPresentation\Writer\ODPresentation;
4
5
use PhpOffice\Common\Adapter\Zip\ZipInterface;
6
use PhpOffice\PhpPresentation\Shape\Drawing;
7
use PhpOffice\PhpPresentation\Slide\Background\Image;
8
9
class Pictures extends AbstractDecoratorWriter
10
{
11
    /**
12
     * @return ZipInterface
13
     */
14
15
    public function render()
16 57
    {
17
        $arrMedia = array();
18 57
        for ($i = 0; $i < $this->getDrawingHashTable()->count(); ++$i) {
19 57
            $shape = $this->getDrawingHashTable()->getByIndex($i);gi
20 28
            if (!($shape instanceof Drawing\AbstractDrawingAdapter)) {
0 ignored issues
show
Bug introduced by
This code did not parse for me. Apparently, there is an error somewhere around this line:

Syntax error, unexpected T_IF
Loading history...
21 28
                continue;
22 7
            }
23 7
            if (in_array($shape->getIndexedFilename(), $arrMedia)) {
24
                continue;
25 7
            }
26
            $arrMedia[] = $shape->getIndexedFilename();
27 7
            $this->getZip()->addFromString('Pictures/' . $shape->getIndexedFilename(), $shape->getContents());
28 1
        }
29 1
30
        foreach ($this->getPresentation()->getAllSlides() as $keySlide => $oSlide) {
31 1
            // Add background image slide
32 1
            $oBkgImage = $oSlide->getBackground();
33 1
            if ($oBkgImage instanceof Image) {
34 1
                $this->getZip()->addFromString('Pictures/'.$oBkgImage->getIndexedFilename($keySlide), file_get_contents($oBkgImage->getPath()));
35 1
            }
36 7
        }
37 1
        
38 1
        return $this->getZip();
39 1
    }
40
}
41