Completed
Pull Request — develop (#209)
by Franck
07:06
created

PptMedia::render()   C

Complexity

Conditions 7
Paths 6

Size

Total Lines 35
Code Lines 27

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 25
CRAP Score 7.0027

Importance

Changes 3
Bugs 1 Features 0
Metric Value
c 3
b 1
f 0
dl 0
loc 35
ccs 25
cts 26
cp 0.9615
rs 6.7272
cc 7
eloc 27
nc 6
nop 0
crap 7.0027
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 \PhpOffice\Common\Adapter\Zip\ZipInterface
12
     */
13 92
    public function render()
14
    {
15 92
        for ($i = 0; $i < $this->getDrawingHashTable()->count(); ++$i) {
16 31
            $shape = $this->getDrawingHashTable()->getByIndex($i);
17 31
            if ($shape instanceof Drawing || $shape instanceof Media) {
0 ignored issues
show
Bug introduced by
The class PhpOffice\PhpPresentatio...er\PowerPoint2007\Media does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
18 6
                $imagePath     = $shape->getPath();
19 6
                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 5
                } elseif (strpos($imagePath, 'data:image/') === 0) {
29 1
                    list(, $imageContents) = explode(';', $imagePath);
30 1
                    list(, $imageContents) = explode(',', $imageContents);
31 1
                    $imageContents = base64_decode($imageContents);
32
                } else {
33 4
                    $imageContents = file_get_contents($imagePath);
34
                }
35 6
                $this->getZip()->addFromString('ppt/media/' . str_replace(' ', '_', $shape->getIndexedFilename()), $imageContents);
36
            } elseif ($shape instanceof MemoryDrawing) {
37 1
                ob_start();
38 1
                call_user_func($shape->getRenderingFunction(), $shape->getImageResource());
39 1
                $imageContents = ob_get_contents();
40 1
                ob_end_clean();
41
42 1
                $this->getZip()->addFromString('ppt/media/' . str_replace(' ', '_', $shape->getIndexedFilename()), $imageContents);
43
            }
44
        }
45
46 92
        return $this->getZip();
47
    }
48
}
49