Completed
Pull Request — develop (#186)
by
unknown
07:55
created

PptMedia   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Test Coverage

Coverage 95.45%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 5
c 2
b 0
f 0
lcom 0
cbo 4
dl 0
loc 37
ccs 21
cts 22
cp 0.9545
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B render() 0 31 5
1
<?php
2
3
namespace PhpOffice\PhpPresentation\Writer\PowerPoint2007;
4
5
use PhpOffice\PhpPresentation\Shape\Drawing;
6
use PhpOffice\PhpPresentation\Shape\MemoryDrawing;
7
8
class PptMedia extends AbstractDecoratorWriter
9
{
10
    /**
11
     * @return \ZipArchive
12
     */
13 75
    public function render()
14
    {
15 75
        for ($i = 0; $i < $this->getDrawingHashTable()->count(); ++$i) {
16 26
            $shape = $this->getDrawingHashTable()->getByIndex($i);
17 26
            if ($shape instanceof Drawing) {
18 5
                $imagePath     = $shape->getPath();
19 5
                if (strpos($imagePath, 'zip://') !== false) {
20 1
                    $imagePath         = substr($imagePath, 6);
21 1
                    $imagePathSplitted = explode('#', $imagePath);
22
23 1
                    $imageZip = new \ZipArchive();
24 1
                    $imageZip->open($imagePathSplitted[0]);
25 1
                    $imageContents = $imageZip->getFromName($imagePathSplitted[1]);
26 1
                    $imageZip->close();
27 1
                    unset($imageZip);
28
                } else {
29 4
                    $imageContents = file_get_contents($imagePath);
30
                }
31 5
                $this->getZip()->addFromString('ppt/media/' . str_replace(' ', '_', $shape->getIndexedFilename()), $imageContents);
32
            } elseif ($shape instanceof MemoryDrawing) {
33 1
                ob_start();
34 1
                call_user_func($shape->getRenderingFunction(), $shape->getImageResource());
35 1
                $imageContents = ob_get_contents();
36 1
                ob_end_clean();
37
38 1
                $this->getZip()->addFromString('ppt/media/' . str_replace(' ', '_', $shape->getIndexedFilename()), $imageContents);
39
            }
40
        }
41
42 75
        return $this->getZip();
43
    }
44
}
45