Completed
Pull Request — develop (#207)
by Franck
12:42 queued 05:23
created

Pictures::render()   B

Complexity

Conditions 6
Paths 12

Size

Total Lines 25
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 20
CRAP Score 6

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 25
ccs 20
cts 20
cp 1
rs 8.439
cc 6
eloc 15
nc 12
nop 0
crap 6
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);
20 28
            if (!($shape instanceof Drawing\AbstractDrawingAdapter)) {
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 7
        }
29 1
30 1
        foreach ($this->getPresentation()->getAllSlides() as $keySlide => $oSlide) {
31
            // 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 1
        }
37 6
        
38 1
        return $this->getZip();
39 1
    }
40
}
41