Completed
Pull Request — develop (#230)
by Franck
08:45
created

PowerPoint2007::loadSlide()   D

Complexity

Conditions 15
Paths 113

Size

Total Lines 78
Code Lines 50

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 30
CRAP Score 45.9302

Importance

Changes 4
Bugs 0 Features 1
Metric Value
dl 0
loc 78
ccs 30
cts 62
cp 0.4839
rs 4.9094
c 4
b 0
f 1
cc 15
eloc 50
nc 113
nop 2
crap 45.9302

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
 * This file is part of PHPPresentation - A pure PHP library for reading and writing
4
 * presentations documents.
5
 *
6
 * PHPPresentation is free software distributed under the terms of the GNU Lesser
7
 * General Public License version 3 as published by the Free Software Foundation.
8
 *
9
 * For the full copyright and license information, please read the LICENSE
10
 * file that was distributed with this source code. For the full list of
11
 * contributors, visit https://github.com/PHPOffice/PHPPresentation/contributors.
12
 *
13
 * @link        https://github.com/PHPOffice/PHPPresentation
14
 * @copyright   2009-2015 PHPPresentation contributors
15
 * @license     http://www.gnu.org/licenses/lgpl.txt LGPL version 3
16
 */
17
18
namespace PhpOffice\PhpPresentation\Reader;
19
20
use PhpOffice\PhpPresentation\Shape\RichText\Paragraph;
21
use PhpOffice\PhpPresentation\Slide\AbstractSlide;
22
use PhpOffice\PhpPresentation\Shape\Placeholder;
23
use PhpOffice\PhpPresentation\Slide\Background\Image;
24
use PhpOffice\PhpPresentation\Slide\SlideLayout;
25
use PhpOffice\PhpPresentation\Slide\SlideMaster;
26
use PhpOffice\PhpPresentation\Shape\Drawing\Gd;
27
use PhpOffice\PhpPresentation\Style\SchemeColor;
28
use PhpOffice\PhpPresentation\Style\TextStyle;
29
use ZipArchive;
30
use PhpOffice\Common\XMLReader;
31
use PhpOffice\Common\Drawing as CommonDrawing;
32
use PhpOffice\PhpPresentation\PhpPresentation;
33
use PhpOffice\PhpPresentation\Style\Bullet;
34
use PhpOffice\PhpPresentation\Style\Color;
35
36
/**
37
 * Serialized format reader
38
 */
39
class PowerPoint2007 implements ReaderInterface
40
{
41
    /**
42
     * Output Object
43
     * @var PhpPresentation
44
     */
45
    protected $oPhpPresentation;
46
    /**
47
     * Output Object
48
     * @var \ZipArchive
49
     */
50
    protected $oZip;
51
    /**
52
     * @var array[]
53
     */
54
    protected $arrayRels = array();
55
    /**
56
     * @var SlideLayout[]
57
     */
58
    protected $arraySlideLayouts = array();
59
    /*
60
     * @var string
61
     */
62
    protected $filename;
63
64
    /**
65
     * Can the current \PhpOffice\PhpPresentation\Reader\ReaderInterface read the file?
66
     *
67
     * @param  string $pFilename
68
     * @throws \Exception
69
     * @return boolean
70
     */
71 2
    public function canRead($pFilename)
72
    {
73 2
        return $this->fileSupportsUnserializePhpPresentation($pFilename);
74
    }
75
76
    /**
77
     * Does a file support UnserializePhpPresentation ?
78
     *
79
     * @param  string $pFilename
80
     * @throws \Exception
81
     * @return boolean
82
     */
83 8
    public function fileSupportsUnserializePhpPresentation($pFilename = '')
84
    {
85
        // Check if file exists
86 8
        if (!file_exists($pFilename)) {
87 2
            throw new \Exception("Could not open " . $pFilename . " for reading! File does not exist.");
88
        }
89
90 6
        $oZip = new ZipArchive();
91
        // Is it a zip ?
92 6
        if ($oZip->open($pFilename) === true) {
93
            // Is it an OpenXML Document ?
94
            // Is it a Presentation ?
95 4
            if (is_array($oZip->statName('[Content_Types].xml')) && is_array($oZip->statName('ppt/presentation.xml'))) {
96 4
                return true;
97
            }
98 1
        }
99 3
        return false;
100
    }
101
102
    /**
103
     * Loads PhpPresentation Serialized file
104
     *
105
     * @param  string $pFilename
106
     * @return \PhpOffice\PhpPresentation\PhpPresentation
107
     * @throws \Exception
108
     */
109 5
    public function load($pFilename)
110
    {
111
        // Unserialize... First make sure the file supports it!
112 5
        if (!$this->fileSupportsUnserializePhpPresentation($pFilename)) {
113 1
            throw new \Exception("Invalid file format for PhpOffice\PhpPresentation\Reader\PowerPoint2007: " . $pFilename . ".");
114
        }
115
116 3
        return $this->loadFile($pFilename);
117
    }
118
119
    /**
120
     * Load PhpPresentation Serialized file
121
     *
122
     * @param  string $pFilename
123
     * @return \PhpOffice\PhpPresentation\PhpPresentation
124
     */
125 3
    protected function loadFile($pFilename)
126
    {
127 3
        $this->oPhpPresentation = new PhpPresentation();
128 3
        $this->oPhpPresentation->removeSlideByIndex();
129 3
        $this->oPhpPresentation->setAllMasterSlides(array());
130 3
        $this->filename = $pFilename;
131
132 3
        $this->oZip = new ZipArchive();
133 3
        $this->oZip->open($this->filename);
134 3
        $docPropsCore = $this->oZip->getFromName('docProps/core.xml');
135 3
        if ($docPropsCore !== false) {
136 3
            $this->loadDocumentProperties($docPropsCore);
137 3
        }
138
139 3
        $docPropsCustom = $this->oZip->getFromName('docProps/custom.xml');
140 3
        if ($docPropsCustom !== false) {
141 1
            $this->loadCustomProperties($docPropsCustom);
142 1
        }
143
144 3
        $pptViewProps = $this->oZip->getFromName('ppt/viewProps.xml');
145 3
        if ($pptViewProps !== false) {
146 3
            $this->loadViewProperties($pptViewProps);
147 3
        }
148
149 3
        $pptPresentation = $this->oZip->getFromName('ppt/presentation.xml');
150 3
        if ($pptPresentation !== false) {
151 3
            $this->loadSlides($pptPresentation);
152 3
        }
153
154 3
        return $this->oPhpPresentation;
155
    }
156
157
    /**
158
     * Read Document Properties
159
     * @param string $sPart
160
     */
161 3
    protected function loadDocumentProperties($sPart)
162
    {
163 3
        $xmlReader = new XMLReader();
164 3
        if ($xmlReader->getDomFromString($sPart)) {
165
            $arrayProperties = array(
166 3
                '/cp:coreProperties/dc:creator' => 'setCreator',
167 3
                '/cp:coreProperties/cp:lastModifiedBy' => 'setLastModifiedBy',
168 3
                '/cp:coreProperties/dc:title' => 'setTitle',
169 3
                '/cp:coreProperties/dc:description' => 'setDescription',
170 3
                '/cp:coreProperties/dc:subject' => 'setSubject',
171 3
                '/cp:coreProperties/cp:keywords' => 'setKeywords',
172 3
                '/cp:coreProperties/cp:category' => 'setCategory',
173 3
                '/cp:coreProperties/dcterms:created' => 'setCreated',
174 3
                '/cp:coreProperties/dcterms:modified' => 'setModified',
175 3
            );
176 3
            $oProperties = $this->oPhpPresentation->getDocumentProperties();
177 3
            foreach ($arrayProperties as $path => $property) {
178 3
                if (is_object($oElement = $xmlReader->getElement($path))) {
179 3
                    if ($oElement->hasAttribute('xsi:type') && $oElement->getAttribute('xsi:type') == 'dcterms:W3CDTF') {
0 ignored issues
show
Bug introduced by
The method hasAttribute() does not exist on DOMNode. Did you maybe mean hasAttributes()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
180 3
                        $oDateTime = new \DateTime();
181 3
                        $oDateTime->createFromFormat(\DateTime::W3C, $oElement->nodeValue);
182 3
                        $oProperties->{$property}($oDateTime->getTimestamp());
183 3
                    } else {
184 3
                        $oProperties->{$property}($oElement->nodeValue);
185
                    }
186 3
                }
187 3
            }
188 3
        }
189 3
    }
190
191
    /**
192
     * Read Custom Properties
193
     * @param string $sPart
194
     */
195 1
    protected function loadCustomProperties($sPart)
196
    {
197 1
        $xmlReader = new XMLReader();
198 1
        $sPart = str_replace(' xmlns="http://schemas.openxmlformats.org/officeDocument/2006/custom-properties"', '', $sPart);
199 1
        if ($xmlReader->getDomFromString($sPart)) {
200 1
            $pathMarkAsFinal = '/Properties/property[@pid="2"][@fmtid="{D5CDD505-2E9C-101B-9397-08002B2CF9AE}"][@name="_MarkAsFinal"]/vt:bool';
201 1
            if (is_object($oElement = $xmlReader->getElement($pathMarkAsFinal))) {
202 1
                if ($oElement->nodeValue == 'true') {
203 1
                    $this->oPhpPresentation->getPresentationProperties()->markAsFinal(true);
204 1
                }
205 1
            }
206 1
        }
207 1
    }
208
209
    /**
210
     * Read View Properties
211
     * @param string $sPart
212
     */
213 3
    protected function loadViewProperties($sPart)
214
    {
215 3
        $xmlReader = new XMLReader();
216 3
        if ($xmlReader->getDomFromString($sPart)) {
217 3
            $pathZoom = '/p:viewPr/p:slideViewPr/p:cSldViewPr/p:cViewPr/p:scale/a:sx';
218 3
            if (is_object($oElement = $xmlReader->getElement($pathZoom))) {
219 2
                if ($oElement->hasAttribute('d') && $oElement->hasAttribute('n')) {
0 ignored issues
show
Bug introduced by
The method hasAttribute() does not exist on DOMNode. Did you maybe mean hasAttributes()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
220 2
                    $this->oPhpPresentation->getPresentationProperties()->setZoom($oElement->getAttribute('n') / $oElement->getAttribute('d'));
221 2
                }
222 2
            }
223 3
        }
224 3
    }
225
226
    /**
227
     * Extract all slides
228
     */
229 3
    protected function loadSlides($sPart)
230
    {
231 3
        $xmlReader = new XMLReader();
232 3
        if ($xmlReader->getDomFromString($sPart)) {
233 3
            $fileRels = 'ppt/_rels/presentation.xml.rels';
234 3
            $this->loadRels($fileRels);
235
            // Load the Masterslides
236 3
            $this->loadMasterSlides($xmlReader, $fileRels);
237
            // Continue with loading the slides
238 3
            foreach ($xmlReader->getElements('/p:presentation/p:sldIdLst/p:sldId') as $oElement) {
239 3
                $rId = $oElement->getAttribute('r:id');
240 3
                $pathSlide = isset($this->arrayRels[$fileRels][$rId]) ? $this->arrayRels[$fileRels][$rId]['Target'] : '';
241 3
                if (!empty($pathSlide)) {
242 3
                    $pptSlide = $this->oZip->getFromName('ppt/' . $pathSlide);
243 3
                    if ($pptSlide !== false) {
244 3
                        $this->loadRels('ppt/slides/_rels/' . basename($pathSlide) . '.rels');
245 3
                        $this->loadSlide($pptSlide, basename($pathSlide));
246 3
                    }
247 3
                }
248 3
            }
249 3
        }
250 3
    }
251
252
    /**
253
     * Extract all MasterSlides
254
     * @param XMLReader $xmlReader
255
     * @param $fileRels
256
     */
257 3
    protected function loadMasterSlides(XMLReader $xmlReader, $fileRels)
258
    {
259
        // Get all the MasterSlide Id's from the presentation.xml file
260 3
        foreach ($xmlReader->getElements('/p:presentation/p:sldMasterIdLst/p:sldMasterId') as $oElement) {
261 3
            $rId = $oElement->getAttribute('r:id');
262
            // Get the path to the masterslide from the array with _rels files
263 3
            $pathMasterSlide = isset($this->arrayRels[$fileRels][$rId]) ?
264 3
                $this->arrayRels[$fileRels][$rId]['Target'] : '';
265 3
            if (!empty($pathMasterSlide)) {
266 3
                $pptMasterSlide = $this->oZip->getFromName('ppt/' . $pathMasterSlide);
267 3
                if ($pptMasterSlide !== false) {
268 3
                    $this->loadRels('ppt/slideMasters/_rels/' . basename($pathMasterSlide) . '.rels');
269 3
                    $this->loadMasterSlide($pptMasterSlide, basename($pathMasterSlide));
270 3
                }
271 3
            }
272 3
        }
273 3
    }
274
275
    /**
276
     * Extract data from slide
277
     * @param string $sPart
278
     * @param string $baseFile
279
     */
280 3
    protected function loadSlide($sPart, $baseFile)
281
    {
282 3
        $xmlReader = new XMLReader();
283 3
        if ($xmlReader->getDomFromString($sPart)) {
284
            // Core
285 3
            $oSlide = $this->oPhpPresentation->createSlide();
286 3
            $this->oPhpPresentation->setActiveSlideIndex($this->oPhpPresentation->getSlideCount() - 1);
287 3
            $oSlide->setRelsIndex('ppt/slides/_rels/' . $baseFile . '.rels');
288
289
            // Background
290 3
            $oElement = $xmlReader->getElement('/p:sld/p:cSld/p:bg/p:bgPr');
291 3
            if ($oElement) {
292
                $oElementColor = $xmlReader->getElement('a:solidFill/a:srgbClr', $oElement);
0 ignored issues
show
Documentation introduced by
$oElement is of type object<DOMNode>, but the function expects a null|object<DOMElement>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
293
                if ($oElementColor) {
294
                    // Color
295
                    $oColor = new Color();
296
                    $oColor->setRGB($oElementColor->hasAttribute('val') ? $oElementColor->getAttribute('val') : null);
0 ignored issues
show
Bug introduced by
The method hasAttribute() does not exist on DOMNode. Did you maybe mean hasAttributes()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
297
                    // Background
298
                    $oBackground = new \PhpOffice\PhpPresentation\Slide\Background\Color();
299
                    $oBackground->setColor($oColor);
300
                    // Slide Background
301
                    $oSlide = $this->oPhpPresentation->getActiveSlide();
302
                    $oSlide->setBackground($oBackground);
303
                }
304
                $oElementImage = $xmlReader->getElement('a:blipFill/a:blip', $oElement);
0 ignored issues
show
Documentation introduced by
$oElement is of type object<DOMNode>, but the function expects a null|object<DOMElement>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
305
                if ($oElementImage) {
306
                    $relImg = $this->arrayRels['ppt/slides/_rels/' . $baseFile . '.rels'][$oElementImage->getAttribute('r:embed')];
307
                    if (is_array($relImg)) {
308
                        // File
309
                        $pathImage = 'ppt/slides/' . $relImg['Target'];
310
                        $pathImage = explode('/', $pathImage);
311
                        foreach ($pathImage as $key => $partPath) {
312
                            if ($partPath == '..') {
313
                                unset($pathImage[$key - 1]);
314
                                unset($pathImage[$key]);
315
                            }
316
                        }
317
                        $pathImage = implode('/', $pathImage);
318
                        $contentImg = $this->oZip->getFromName($pathImage);
319
320
                        $tmpBkgImg = tempnam(sys_get_temp_dir(), 'PhpPresentationReaderPpt2007Bkg');
321
                        file_put_contents($tmpBkgImg, $contentImg);
322
                        // Background
323
                        $oBackground = new Image();
324
                        $oBackground->setPath($tmpBkgImg);
325
                        // Slide Background
326
                        $oSlide = $this->oPhpPresentation->getActiveSlide();
327
                        $oSlide->setBackground($oBackground);
328
                    }
329
                }
330
            }
331
332
            // Shapes
333 3
            foreach ($xmlReader->getElements('/p:sld/p:cSld/p:spTree/*') as $oNode) {
334 3
                switch ($oNode->tagName) {
335 3
                    case 'p:pic':
336 3
                        $this->loadShapeDrawing($xmlReader, $oNode, $oSlide);
337 3
                        break;
338 3
                    case 'p:sp':
339 3
                        $this->loadShapeRichText($xmlReader, $oNode, $oSlide);
340 3
                        break;
341 3
                    default:
342
                        //var_export($oNode->tagName);
343 3
                }
344 3
            }
345
            // Layout
346 3
            $oSlide = $this->oPhpPresentation->getActiveSlide();
347 3
            foreach ($this->arrayRels['ppt/slides/_rels/' . $baseFile . '.rels'] as $valueRel) {
348 3
                if ($valueRel['Type'] == 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/slideLayout') {
349 3
                    $layoutBasename = basename($valueRel['Target']);
350 3
                    if (array_key_exists($layoutBasename, $this->arraySlideLayouts)) {
351 3
                        $oSlide->setSlideLayout($this->arraySlideLayouts[$layoutBasename]);
352 3
                    }
353 3
                    break;
354
                }
355 3
            }
356 3
        }
357 3
    }
358
359 3
    private function loadMasterSlide($sPart, $baseFile)
360
    {
361 3
        $xmlReader = new XMLReader();
362 3
        if ($xmlReader->getDomFromString($sPart)) {
363
            // Core
364 3
            $oSlideMaster = $this->oPhpPresentation->createMasterSlide();
365 3
            $oSlideMaster->setTextStyles(new TextStyle(false));
366 3
            $oSlideMaster->setRelsIndex('ppt/slideMasters/_rels/' . $baseFile . '.rels');
367
368
            // Background
369 3
            $oElement = $xmlReader->getElement('/p:sldMaster/p:cSld/p:bg');
370 3
            if ($oElement) {
371 3
                $this->loadSlideBackground($xmlReader, $oElement, $oSlideMaster);
0 ignored issues
show
Compatibility introduced by
$oElement of type object<DOMNode> is not a sub-type of object<DOMElement>. It seems like you assume a child class of the class DOMNode to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
372 3
            }
373
374
            // Shapes
375 3
            $arrayElements = $xmlReader->getElements('/p:sldMaster/p:cSld/p:spTree/*');
376 3
            if ($arrayElements) {
377 3
                $this->loadSlideShapes($oSlideMaster, $arrayElements, $xmlReader);
378 3
            }
379
            // Header & Footer
380
381
            // ColorMapping
382 3
            $colorMap = array();
383 3
            $oElement = $xmlReader->getElement('/p:sldMaster/p:clrMap');
384 3
            if ($oElement->hasAttributes()) {
385 3
                foreach ($oElement->attributes as $attr) {
386 3
                    $colorMap[$attr->nodeName] = $attr->nodeValue;
387 3
                }
388 3
                $oSlideMaster->colorMap->setMapping($colorMap);
389 3
            }
390
391
            // TextStyles
392 3
            $arrayElementTxStyles = $xmlReader->getElements('/p:sldMaster/p:txStyles/*');
393 3
            if ($arrayElementTxStyles) {
394 3
                foreach ($arrayElementTxStyles as $oElementTxStyle) {
395 3
                    $arrayElementsLvl = $xmlReader->getElements('/p:sldMaster/p:txStyles/'.$oElementTxStyle->nodeName.'/*');
396 3
                    foreach ($arrayElementsLvl as $oElementLvl) {
397 3
                        if ($oElementLvl->nodeName == 'a:extLst') {
398
                            continue;
399
                        }
400 3
                        $oRTParagraph = new Paragraph();
401
402 3
                        if ($oElementLvl->nodeName == 'a:defPPr') {
403 3
                            $level = 0;
404 3
                        } else {
405 3
                            $level = str_replace('a:lvl', '', $oElementLvl->nodeName);
406 3
                            $level = str_replace('pPr', '', $level);
407
                        }
408
409 3
                        if ($oElementLvl->hasAttribute('algn')) {
410 3
                            $oRTParagraph->getAlignment()->setHorizontal($oElementLvl->getAttribute('algn'));
411 3
                        }
412 3
                        if ($oElementLvl->hasAttribute('marL')) {
413 3
                            $val = $oElementLvl->getAttribute('marL');
414 3
                            $val = CommonDrawing::emuToPixels($val);
415 3
                            $oRTParagraph->getAlignment()->setMarginLeft($val);
416 3
                        }
417 3
                        if ($oElementLvl->hasAttribute('marR')) {
418
                            $val = $oElementLvl->getAttribute('marR');
419
                            $val = CommonDrawing::emuToPixels($val);
420
                            $oRTParagraph->getAlignment()->setMarginRight($val);
421
                        }
422 3
                        if ($oElementLvl->hasAttribute('indent')) {
423 3
                            $val = $oElementLvl->getAttribute('indent');
424 3
                            $val = CommonDrawing::emuToPixels($val);
425 3
                            $oRTParagraph->getAlignment()->setIndent($val);
426 3
                        }
427 3
                        $oElementLvlDefRPR = $xmlReader->getElement('a:defRPr', $oElementLvl);
428 3
                        if ($oElementLvlDefRPR) {
429 3
                            if ($oElementLvlDefRPR->hasAttribute('sz')) {
0 ignored issues
show
Bug introduced by
The method hasAttribute() does not exist on DOMNode. Did you maybe mean hasAttributes()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
430 3
                                $oRTParagraph->getFont()->setSize($oElementLvlDefRPR->getAttribute('sz') / 100);
431 3
                            }
432 3
                            if ($oElementLvlDefRPR->hasAttribute('b') && $oElementLvlDefRPR->getAttribute('b') == 1) {
0 ignored issues
show
Bug introduced by
The method hasAttribute() does not exist on DOMNode. Did you maybe mean hasAttributes()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
433
                                $oRTParagraph->getFont()->setBold(true);
434
                            }
435 3
                            if ($oElementLvlDefRPR->hasAttribute('i') && $oElementLvlDefRPR->getAttribute('i') == 1) {
0 ignored issues
show
Bug introduced by
The method hasAttribute() does not exist on DOMNode. Did you maybe mean hasAttributes()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
436
                                $oRTParagraph->getFont()->setItalic(true);
437
                            }
438 3
                        }
439 3
                        $oElementSchemeColor = $xmlReader->getElement('a:defRPr/a:solidFill/a:schemeClr', $oElementLvl);
440 3
                        if ($oElementSchemeColor) {
441 3
                            if ($oElementSchemeColor->hasAttribute('val')) {
0 ignored issues
show
Bug introduced by
The method hasAttribute() does not exist on DOMNode. Did you maybe mean hasAttributes()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
442 3
                                $oRTParagraph->getFont()->setColor(new SchemeColor())->getColor()->setValue($oElementSchemeColor->getAttribute('val'));
0 ignored issues
show
Bug introduced by
It seems like you code against a specific sub-type and not the parent class PhpOffice\PhpPresentation\Style\Color as the method setValue() does only exist in the following sub-classes of PhpOffice\PhpPresentation\Style\Color: PhpOffice\PhpPresentation\Style\SchemeColor. Maybe you want to instanceof check for one of these explicitly?

Let’s take a look at an example:

abstract class User
{
    /** @return string */
    abstract public function getPassword();
}

class MyUser extends User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the parent class:

    abstract class User
    {
        /** @return string */
        abstract public function getPassword();
    
        /** @return string */
        abstract public function getDisplayName();
    }
    
Loading history...
443 3
                            }
444 3
                        }
445
446 3
                        switch ($oElementTxStyle->nodeName) {
447 3
                            case 'p:bodyStyle':
448 3
                                $oSlideMaster->getTextStyles()->setBodyStyleAtLvl($oRTParagraph, $level);
449 3
                                break;
450 3
                            case 'p:otherStyle':
451 3
                                $oSlideMaster->getTextStyles()->setOtherStyleAtLvl($oRTParagraph, $level);
452 3
                                break;
453 3
                            case 'p:titleStyle':
454 3
                                $oSlideMaster->getTextStyles()->setTitleStyleAtLvl($oRTParagraph, $level);
455 3
                                break;
456 3
                        }
457 3
                    }
458 3
                }
459 3
            }
460
461
            // Load the theme
462 3
            foreach ($this->arrayRels[$oSlideMaster->getRelsIndex()] as $arrayRel) {
463 3
                if ($arrayRel['Type'] == 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme') {
464 3
                    $pptTheme = $this->oZip->getFromName('ppt/' . substr($arrayRel['Target'], strrpos($arrayRel['Target'], '../') + 3));
465 3
                    if ($pptTheme !== false) {
466 3
                        $this->loadTheme($pptTheme, $oSlideMaster);
467 3
                    }
468 3
                    break;
469
                }
470 3
            }
471
472
            // Load the Layoutslide
473 3
            foreach ($xmlReader->getElements('/p:sldMaster/p:sldLayoutIdLst/p:sldLayoutId') as $oElement) {
474 3
                $rId = $oElement->getAttribute('r:id');
475
                // Get the path to the masterslide from the array with _rels files
476 3
                $pathLayoutSlide = isset($this->arrayRels[$oSlideMaster->getRelsIndex()][$rId]) ?
477 3
                    $this->arrayRels[$oSlideMaster->getRelsIndex()][$rId]['Target'] : '';
478 3
                if (!empty($pathLayoutSlide)) {
479 3
                    $pptLayoutSlide = $this->oZip->getFromName('ppt/' . substr($pathLayoutSlide, strrpos($pathLayoutSlide, '../') + 3));
480 3
                    if ($pptLayoutSlide !== false) {
481 3
                        $this->loadRels('ppt/slideLayouts/_rels/' . basename($pathLayoutSlide) . '.rels');
482 3
                        $oSlideMaster->addSlideLayout(
483 3
                            $this->loadLayoutSlide($pptLayoutSlide, basename($pathLayoutSlide), $oSlideMaster)
484 3
                        );
485 3
                    }
486 3
                }
487 3
            }
488 3
        }
489 3
    }
490
491 3
    private function loadLayoutSlide($sPart, $baseFile, SlideMaster $oSlideMaster)
492
    {
493 3
        $xmlReader = new XMLReader();
494 3
        if ($xmlReader->getDomFromString($sPart)) {
495
            // Core
496 3
            $oSlideLayout = new SlideLayout($oSlideMaster);
497 3
            $oSlideLayout->setRelsIndex('ppt/slideLayouts/_rels/' . $baseFile . '.rels');
498
499
            // Name
500 3
            $oElement = $xmlReader->getElement('/p:sldLayout/p:cSld');
501 3
            if ($oElement && $oElement->hasAttribute('name')) {
0 ignored issues
show
Bug introduced by
The method hasAttribute() does not exist on DOMNode. Did you maybe mean hasAttributes()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
502 3
                $oSlideLayout->setLayoutName($oElement->getAttribute('name'));
503 3
            }
504
505
            // Background
506 3
            $oElement = $xmlReader->getElement('/p:sldLayout/p:cSld/p:bg');
507 3
            if ($oElement) {
508
                $this->loadSlideBackground($xmlReader, $oElement, $oSlideLayout);
0 ignored issues
show
Compatibility introduced by
$oElement of type object<DOMNode> is not a sub-type of object<DOMElement>. It seems like you assume a child class of the class DOMNode to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
509
            }
510
511
            // ColorMapping
512 3
            $oElement = $xmlReader->getElement('/p:sldLayout/p:clrMapOvr/a:overrideClrMapping');
513 3
            if ($oElement && $oElement->hasAttributes()) {
514
                $colorMap = array();
515
                foreach ($oElement->attributes as $attr) {
516
                    $colorMap[$attr->nodeName] = $attr->nodeValue;
517
                }
518
                $oSlideLayout->colorMap->setMapping($colorMap);
519
            }
520
521
            // Shapes
522 3
            $oElements = $xmlReader->getElements('/p:sldLayout/p:cSld/p:spTree/*');
523 3
            if ($oElements) {
524 3
                $this->loadSlideShapes($oSlideLayout, $oElements, $xmlReader);
525 3
            }
526 3
            $this->arraySlideLayouts[$baseFile] = &$oSlideLayout;
527 3
            return $oSlideLayout;
528
        }
529
        return null;
530
    }
531
532
    /**
533
     * @param string $sPart
534
     * @param SlideMaster $oSlideMaster
535
     */
536 3
    private function loadTheme($sPart, SlideMaster $oSlideMaster)
537
    {
538 3
        $xmlReader = new XMLReader();
539 3
        if ($xmlReader->getDomFromString($sPart)) {
540 3
            $oElements = $xmlReader->getElements('/a:theme/a:themeElements/a:clrScheme/*');
541 3
            if ($oElements) {
542 3
                foreach ($oElements as $oElement) {
543 3
                    $oSchemeColor = new SchemeColor();
544 3
                    $oSchemeColor->setValue(str_replace('a:', '', $oElement->tagName));
545 3
                    $colorElement = $xmlReader->getElement('*', $oElement);
546 3
                    if ($colorElement) {
547 3
                        if ($colorElement->hasAttribute('lastClr')) {
0 ignored issues
show
Bug introduced by
The method hasAttribute() does not exist on DOMNode. Did you maybe mean hasAttributes()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
548 3
                            $oSchemeColor->setRGB($colorElement->getAttribute('lastClr'));
549 3
                        } elseif ($colorElement->hasAttribute('val')) {
0 ignored issues
show
Bug introduced by
The method hasAttribute() does not exist on DOMNode. Did you maybe mean hasAttributes()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
550 3
                            $oSchemeColor->setRGB($colorElement->getAttribute('val'));
551 3
                        }
552 3
                    }
553 3
                    $oSlideMaster->addSchemeColor($oSchemeColor);
554 3
                }
555 3
            }
556 3
        }
557 3
    }
558
559
    /**
560
     * @param XMLReader $xmlReader
561
     * @param \DOMElement $oElement
562
     * @param AbstractSlide $oSlide
563
     */
564 3
    private function loadSlideBackground(XMLReader $xmlReader, \DOMElement $oElement, AbstractSlide $oSlide)
565
    {
566
        // Background color
567 3
        $oElementColor = $xmlReader->getElement('p:bgPr/a:solidFill/a:srgbClr', $oElement);
568 3
        if ($oElementColor) {
569
            // Color
570
            $oColor = new Color();
571
            $oColor->setRGB($oElementColor->hasAttribute('val') ? $oElementColor->getAttribute('val') : null);
0 ignored issues
show
Bug introduced by
The method hasAttribute() does not exist on DOMNode. Did you maybe mean hasAttributes()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
572
            // Background
573
            $oBackground = new \PhpOffice\PhpPresentation\Slide\Background\Color();
574
            $oBackground->setColor($oColor);
575
            // Slide Background
576
            $oSlide->setBackground($oBackground);
577
        }
578
579
        // Background scheme color
580 3
        $oElementSchemeColor = $xmlReader->getElement('p:bgRef/a:schemeClr', $oElement);
581 3
        if ($oElementSchemeColor) {
582
            // Color
583 3
            $oColor = new SchemeColor();
584 3
            $oColor->setValue($oElementSchemeColor->hasAttribute('val') ? $oElementSchemeColor->getAttribute('val') : null);
0 ignored issues
show
Bug introduced by
The method hasAttribute() does not exist on DOMNode. Did you maybe mean hasAttributes()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
585
            // Background
586 3
            $oBackground = new \PhpOffice\PhpPresentation\Slide\Background\SchemeColor();
587 3
            $oBackground->setSchemeColor($oColor);
588
            // Slide Background
589 3
            $oSlide->setBackground($oBackground);
590 3
        }
591
592
        // Background image
593 3
        $oElementImage = $xmlReader->getElement('p:bgPr/a:blipFill/a:blip', $oElement);
594 3
        if ($oElementImage) {
595
            $relImg = $this->arrayRels[$oSlide->getRelsIndex()][$oElementImage->getAttribute('r:embed')];
596
            if (is_array($relImg)) {
597
                // File
598
                $pathImage = 'ppt/slides/' . $relImg['Target'];
599
                $pathImage = explode('/', $pathImage);
600
                foreach ($pathImage as $key => $partPath) {
601
                    if ($partPath == '..') {
602
                        unset($pathImage[$key - 1]);
603
                        unset($pathImage[$key]);
604
                    }
605
                }
606
                $pathImage = implode('/', $pathImage);
607
                $contentImg = $this->oZip->getFromName($pathImage);
608
609
                $tmpBkgImg = tempnam(sys_get_temp_dir(), 'PhpPresentationReaderPpt2007Bkg');
610
                file_put_contents($tmpBkgImg, $contentImg);
611
                // Background
612
                $oBackground = new Image();
613
                $oBackground->setPath($tmpBkgImg);
614
                // Slide Background
615
                $oSlide->setBackground($oBackground);
616
            }
617
        }
618 3
    }
619
620
    /**
621
     *
622
     * @param XMLReader $document
623
     * @param \DOMElement $node
624
     * @param AbstractSlide $oSlide
625
     */
626 3
    protected function loadShapeDrawing(XMLReader $document, \DOMElement $node, AbstractSlide $oSlide)
627
    {
628
        // Core
629 3
        $oShape = new Gd();
630 3
        $oShape->getShadow()->setVisible(false);
631
        // Variables
632 3
        $fileRels = $oSlide->getRelsIndex();
633
634 3
        $oElement = $document->getElement('p:nvPicPr/p:cNvPr', $node);
635 3
        if ($oElement) {
636 3
            $oShape->setName($oElement->hasAttribute('name') ? $oElement->getAttribute('name') : '');
0 ignored issues
show
Bug introduced by
The method hasAttribute() does not exist on DOMNode. Did you maybe mean hasAttributes()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
637 3
            $oShape->setDescription($oElement->hasAttribute('descr') ? $oElement->getAttribute('descr') : '');
0 ignored issues
show
Bug introduced by
The method hasAttribute() does not exist on DOMNode. Did you maybe mean hasAttributes()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
638 3
        }
639
640 3
        $oElement = $document->getElement('p:blipFill/a:blip', $node);
641 3
        if ($oElement) {
642 3
            if ($oElement->hasAttribute('r:embed') && isset($this->arrayRels[$fileRels][$oElement->getAttribute('r:embed')]['Target'])) {
0 ignored issues
show
Bug introduced by
The method hasAttribute() does not exist on DOMNode. Did you maybe mean hasAttributes()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
643 3
                $pathImage = 'ppt/slides/' . $this->arrayRels[$fileRels][$oElement->getAttribute('r:embed')]['Target'];
644 3
                $pathImage = explode('/', $pathImage);
645 3
                foreach ($pathImage as $key => $partPath) {
646 3
                    if ($partPath == '..') {
647 3
                        unset($pathImage[$key - 1]);
648 3
                        unset($pathImage[$key]);
649 3
                    }
650 3
                }
651 3
                $pathImage = implode('/', $pathImage);
652 3
                $imageFile = $this->oZip->getFromName($pathImage);
653 3
                if (!empty($imageFile)) {
654 3
                    $oShape->setImageResource(imagecreatefromstring($imageFile));
655 3
                }
656 3
            }
657 3
        }
658
659 3
        $oElement = $document->getElement('p:spPr/a:xfrm', $node);
660 3
        if ($oElement) {
661 3
            if ($oElement->hasAttribute('rot')) {
0 ignored issues
show
Bug introduced by
The method hasAttribute() does not exist on DOMNode. Did you maybe mean hasAttributes()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
662 3
                $oShape->setRotation(CommonDrawing::angleToDegrees($oElement->getAttribute('rot')));
663 3
            }
664 3
        }
665
666 3
        $oElement = $document->getElement('p:spPr/a:xfrm/a:off', $node);
667 3
        if ($oElement) {
668 3
            if ($oElement->hasAttribute('x')) {
0 ignored issues
show
Bug introduced by
The method hasAttribute() does not exist on DOMNode. Did you maybe mean hasAttributes()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
669 3
                $oShape->setOffsetX(CommonDrawing::emuToPixels($oElement->getAttribute('x')));
670 3
            }
671 3
            if ($oElement->hasAttribute('y')) {
0 ignored issues
show
Bug introduced by
The method hasAttribute() does not exist on DOMNode. Did you maybe mean hasAttributes()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
672 3
                $oShape->setOffsetY(CommonDrawing::emuToPixels($oElement->getAttribute('y')));
673 3
            }
674 3
        }
675
676 3
        $oElement = $document->getElement('p:spPr/a:xfrm/a:ext', $node);
677 3
        if ($oElement) {
678 3
            if ($oElement->hasAttribute('cx')) {
0 ignored issues
show
Bug introduced by
The method hasAttribute() does not exist on DOMNode. Did you maybe mean hasAttributes()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
679 3
                $oShape->setWidth(CommonDrawing::emuToPixels($oElement->getAttribute('cx')));
680 3
            }
681 3
            if ($oElement->hasAttribute('cy')) {
0 ignored issues
show
Bug introduced by
The method hasAttribute() does not exist on DOMNode. Did you maybe mean hasAttributes()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
682 3
                $oShape->setHeight(CommonDrawing::emuToPixels($oElement->getAttribute('cy')));
683 3
            }
684 3
        }
685
686 3
        $oElement = $document->getElement('p:spPr/a:effectLst', $node);
687 3
        if ($oElement) {
688 3
            $oShape->getShadow()->setVisible(true);
689
690 3
            $oSubElement = $document->getElement('a:outerShdw', $oElement);
0 ignored issues
show
Documentation introduced by
$oElement is of type object<DOMNode>, but the function expects a null|object<DOMElement>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
691 3
            if ($oSubElement) {
692 3
                if ($oSubElement->hasAttribute('blurRad')) {
0 ignored issues
show
Bug introduced by
The method hasAttribute() does not exist on DOMNode. Did you maybe mean hasAttributes()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
693 3
                    $oShape->getShadow()->setBlurRadius(CommonDrawing::emuToPixels($oSubElement->getAttribute('blurRad')));
694 3
                }
695 3
                if ($oSubElement->hasAttribute('dist')) {
0 ignored issues
show
Bug introduced by
The method hasAttribute() does not exist on DOMNode. Did you maybe mean hasAttributes()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
696 3
                    $oShape->getShadow()->setDistance(CommonDrawing::emuToPixels($oSubElement->getAttribute('dist')));
697 3
                }
698 3
                if ($oSubElement->hasAttribute('dir')) {
0 ignored issues
show
Bug introduced by
The method hasAttribute() does not exist on DOMNode. Did you maybe mean hasAttributes()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
699 3
                    $oShape->getShadow()->setDirection(CommonDrawing::angleToDegrees($oSubElement->getAttribute('dir')));
700 3
                }
701 3
                if ($oSubElement->hasAttribute('algn')) {
0 ignored issues
show
Bug introduced by
The method hasAttribute() does not exist on DOMNode. Did you maybe mean hasAttributes()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
702 3
                    $oShape->getShadow()->setAlignment($oSubElement->getAttribute('algn'));
703 3
                }
704 3
            }
705
706 3
            $oSubElement = $document->getElement('a:outerShdw/a:srgbClr', $oElement);
0 ignored issues
show
Documentation introduced by
$oElement is of type object<DOMNode>, but the function expects a null|object<DOMElement>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
707 3
            if ($oSubElement) {
708 3
                if ($oSubElement->hasAttribute('val')) {
0 ignored issues
show
Bug introduced by
The method hasAttribute() does not exist on DOMNode. Did you maybe mean hasAttributes()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
709 3
                    $oColor = new Color();
710 3
                    $oColor->setRGB($oSubElement->getAttribute('val'));
711 3
                    $oShape->getShadow()->setColor($oColor);
712 3
                }
713 3
            }
714
715 3
            $oSubElement = $document->getElement('a:outerShdw/a:srgbClr/a:alpha', $oElement);
0 ignored issues
show
Documentation introduced by
$oElement is of type object<DOMNode>, but the function expects a null|object<DOMElement>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
716 3
            if ($oSubElement) {
717 3
                if ($oSubElement->hasAttribute('val')) {
0 ignored issues
show
Bug introduced by
The method hasAttribute() does not exist on DOMNode. Did you maybe mean hasAttributes()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
718 3
                    $oShape->getShadow()->setAlpha((int)$oSubElement->getAttribute('val') / 1000);
719 3
                }
720 3
            }
721 3
        }
722
723 3
        $oSlide->addShape($oShape);
724 3
    }
725
726
    /**
727
     * @param XMLReader $document
728
     * @param \DOMElement $node
729
     * @param AbstractSlide $oSlide
730
     * @throws \Exception
731
     */
732 3
    protected function loadShapeRichText(XMLReader $document, \DOMElement $node, AbstractSlide $oSlide)
733
    {
734
        // Core
735 3
        $oShape = $oSlide->createRichTextShape();
736 3
        $oShape->setParagraphs(array());
737
        // Variables
738 3
        $fileRels = $oSlide->getRelsIndex();
739
740 3
        $oElement = $document->getElement('p:spPr/a:xfrm', $node);
741 3
        if ($oElement && $oElement->hasAttribute('rot')) {
0 ignored issues
show
Bug introduced by
The method hasAttribute() does not exist on DOMNode. Did you maybe mean hasAttributes()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
742 3
            $oShape->setRotation(CommonDrawing::angleToDegrees($oElement->getAttribute('rot')));
743 3
        }
744
745 3
        $oElement = $document->getElement('p:spPr/a:xfrm/a:off', $node);
746 3
        if ($oElement) {
747 3
            if ($oElement->hasAttribute('x')) {
0 ignored issues
show
Bug introduced by
The method hasAttribute() does not exist on DOMNode. Did you maybe mean hasAttributes()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
748 3
                $oShape->setOffsetX(CommonDrawing::emuToPixels($oElement->getAttribute('x')));
749 3
            }
750 3
            if ($oElement->hasAttribute('y')) {
0 ignored issues
show
Bug introduced by
The method hasAttribute() does not exist on DOMNode. Did you maybe mean hasAttributes()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
751 3
                $oShape->setOffsetY(CommonDrawing::emuToPixels($oElement->getAttribute('y')));
752 3
            }
753 3
        }
754
755 3
        $oElement = $document->getElement('p:spPr/a:xfrm/a:ext', $node);
756 3
        if ($oElement) {
757 3
            if ($oElement->hasAttribute('cx')) {
0 ignored issues
show
Bug introduced by
The method hasAttribute() does not exist on DOMNode. Did you maybe mean hasAttributes()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
758 3
                $oShape->setWidth(CommonDrawing::emuToPixels($oElement->getAttribute('cx')));
759 3
            }
760 3
            if ($oElement->hasAttribute('cy')) {
0 ignored issues
show
Bug introduced by
The method hasAttribute() does not exist on DOMNode. Did you maybe mean hasAttributes()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
761 3
                $oShape->setHeight(CommonDrawing::emuToPixels($oElement->getAttribute('cy')));
762 3
            }
763 3
        }
764
765 3
        $oElement = $document->getElement('p:nvSpPr/p:nvPr/p:ph', $node);
766 3
        if ($oElement) {
767 3
            if ($oElement->hasAttribute('type')) {
0 ignored issues
show
Bug introduced by
The method hasAttribute() does not exist on DOMNode. Did you maybe mean hasAttributes()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
768 3
                $placeholder = new Placeholder($oElement->getAttribute('type'));
769 3
                $oShape->setPlaceHolder($placeholder);
770 3
            }
771 3
        }
772
773 3
        $arrayElements = $document->getElements('p:txBody/a:p', $node);
774 3
        foreach ($arrayElements as $oElement) {
775
            // Core
776 3
            $oParagraph = $oShape->createParagraph();
777 3
            $oParagraph->setRichTextElements(array());
778
779 3
            $oSubElement = $document->getElement('a:pPr', $oElement);
780 3
            if ($oSubElement) {
781 3
                if ($oSubElement->hasAttribute('algn')) {
0 ignored issues
show
Bug introduced by
The method hasAttribute() does not exist on DOMNode. Did you maybe mean hasAttributes()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
782 3
                    $oParagraph->getAlignment()->setHorizontal($oSubElement->getAttribute('algn'));
783 3
                }
784 3
                if ($oSubElement->hasAttribute('fontAlgn')) {
0 ignored issues
show
Bug introduced by
The method hasAttribute() does not exist on DOMNode. Did you maybe mean hasAttributes()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
785 3
                    $oParagraph->getAlignment()->setVertical($oSubElement->getAttribute('fontAlgn'));
786 3
                }
787 3
                if ($oSubElement->hasAttribute('marL')) {
0 ignored issues
show
Bug introduced by
The method hasAttribute() does not exist on DOMNode. Did you maybe mean hasAttributes()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
788 3
                    $oParagraph->getAlignment()->setMarginLeft(CommonDrawing::emuToPixels($oSubElement->getAttribute('marL')));
789 3
                }
790 3
                if ($oSubElement->hasAttribute('marR')) {
0 ignored issues
show
Bug introduced by
The method hasAttribute() does not exist on DOMNode. Did you maybe mean hasAttributes()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
791 3
                    $oParagraph->getAlignment()->setMarginRight(CommonDrawing::emuToPixels($oSubElement->getAttribute('marR')));
792 3
                }
793 3
                if ($oSubElement->hasAttribute('indent')) {
0 ignored issues
show
Bug introduced by
The method hasAttribute() does not exist on DOMNode. Did you maybe mean hasAttributes()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
794 3
                    $oParagraph->getAlignment()->setIndent(CommonDrawing::emuToPixels($oSubElement->getAttribute('indent')));
795 3
                }
796 3
                if ($oSubElement->hasAttribute('lvl')) {
0 ignored issues
show
Bug introduced by
The method hasAttribute() does not exist on DOMNode. Did you maybe mean hasAttributes()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
797 3
                    $oParagraph->getAlignment()->setLevel($oSubElement->getAttribute('lvl'));
798 3
                }
799
800 3
                $oElementBuFont = $document->getElement('a:buFont', $oSubElement);
0 ignored issues
show
Documentation introduced by
$oSubElement is of type object<DOMNode>, but the function expects a null|object<DOMElement>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
801 3
                $oParagraph->getBulletStyle()->setBulletType(Bullet::TYPE_NONE);
802 3
                if ($oElementBuFont) {
803 3
                    if ($oElementBuFont->hasAttribute('typeface')) {
0 ignored issues
show
Bug introduced by
The method hasAttribute() does not exist on DOMNode. Did you maybe mean hasAttributes()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
804 3
                        $oParagraph->getBulletStyle()->setBulletFont($oElementBuFont->getAttribute('typeface'));
805 3
                    }
806 3
                }
807 3
                $oElementBuChar = $document->getElement('a:buChar', $oSubElement);
0 ignored issues
show
Documentation introduced by
$oSubElement is of type object<DOMNode>, but the function expects a null|object<DOMElement>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
808 3
                if ($oElementBuChar) {
809 3
                    $oParagraph->getBulletStyle()->setBulletType(Bullet::TYPE_BULLET);
810 3
                    if ($oElementBuChar->hasAttribute('char')) {
0 ignored issues
show
Bug introduced by
The method hasAttribute() does not exist on DOMNode. Did you maybe mean hasAttributes()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
811 3
                        $oParagraph->getBulletStyle()->setBulletChar($oElementBuChar->getAttribute('char'));
812 3
                    }
813 3
                }
814
                /*$oElementBuAutoNum = $document->getElement('a:buAutoNum', $oSubElement);
815
                if ($oElementBuAutoNum) {
816
                    $oParagraph->getBulletStyle()->setBulletType(Bullet::TYPE_NUMERIC);
817
                    if ($oElementBuAutoNum->hasAttribute('type')) {
818
                        $oParagraph->getBulletStyle()->setBulletNumericStyle($oElementBuAutoNum->getAttribute('type'));
819
                    }
820
                    if ($oElementBuAutoNum->hasAttribute('startAt') && $oElementBuAutoNum->getAttribute('startAt') != 1) {
821
                        $oParagraph->getBulletStyle()->setBulletNumericStartAt($oElementBuAutoNum->getAttribute('startAt'));
822
                    }
823
                }*/
824 3
            }
825 3
            $arraySubElements = $document->getElements('(a:r|a:br)', $oElement);
826 3
            foreach ($arraySubElements as $oSubElement) {
827 3
                if ($oSubElement->tagName == 'a:br') {
828 3
                    $oParagraph->createBreak();
829 3
                }
830 3
                if ($oSubElement->tagName == 'a:r') {
831 3
                    $oElementrPr = $document->getElement('a:rPr', $oSubElement);
832 3
                    if (is_object($oElementrPr)) {
833 3
                        $oText = $oParagraph->createTextRun();
834
835 3
                        if ($oElementrPr->hasAttribute('b')) {
0 ignored issues
show
Bug introduced by
The method hasAttribute() does not exist on DOMNode. Did you maybe mean hasAttributes()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
836 3
                            $oText->getFont()->setBold($oElementrPr->getAttribute('b') == 'true' ? true : false);
837 3
                        }
838 3
                        if ($oElementrPr->hasAttribute('i')) {
0 ignored issues
show
Bug introduced by
The method hasAttribute() does not exist on DOMNode. Did you maybe mean hasAttributes()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
839 3
                            $oText->getFont()->setItalic($oElementrPr->getAttribute('i') == 'true' ? true : false);
840 3
                        }
841 3
                        if ($oElementrPr->hasAttribute('strike')) {
0 ignored issues
show
Bug introduced by
The method hasAttribute() does not exist on DOMNode. Did you maybe mean hasAttributes()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
842 3
                            $oText->getFont()->setStrikethrough($oElementrPr->getAttribute('strike') == 'noStrike' ? false : true);
843 3
                        }
844 3
                        if ($oElementrPr->hasAttribute('sz')) {
0 ignored issues
show
Bug introduced by
The method hasAttribute() does not exist on DOMNode. Did you maybe mean hasAttributes()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
845 3
                            $oText->getFont()->setSize((int)($oElementrPr->getAttribute('sz') / 100));
846 3
                        }
847 3
                        if ($oElementrPr->hasAttribute('u')) {
0 ignored issues
show
Bug introduced by
The method hasAttribute() does not exist on DOMNode. Did you maybe mean hasAttributes()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
848 3
                            $oText->getFont()->setUnderline($oElementrPr->getAttribute('u'));
849 3
                        }
850
                        // Color
851 3
                        $oElementSrgbClr = $document->getElement('a:solidFill/a:srgbClr', $oElementrPr);
0 ignored issues
show
Documentation introduced by
$oElementrPr is of type object<DOMNode>, but the function expects a null|object<DOMElement>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
852 3
                        if (is_object($oElementSrgbClr) && $oElementSrgbClr->hasAttribute('val')) {
0 ignored issues
show
Bug introduced by
The method hasAttribute() does not exist on DOMNode. Did you maybe mean hasAttributes()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
853 3
                            $oColor = new Color();
854 3
                            $oColor->setRGB($oElementSrgbClr->getAttribute('val'));
855 3
                            $oText->getFont()->setColor($oColor);
856 3
                        }
857
                        // Hyperlink
858 3
                        $oElementHlinkClick = $document->getElement('a:hlinkClick', $oElementrPr);
0 ignored issues
show
Documentation introduced by
$oElementrPr is of type object<DOMNode>, but the function expects a null|object<DOMElement>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
859 3
                        if (is_object($oElementHlinkClick)) {
860 3
                            if ($oElementHlinkClick->hasAttribute('tooltip')) {
0 ignored issues
show
Bug introduced by
The method hasAttribute() does not exist on DOMNode. Did you maybe mean hasAttributes()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
861 3
                                $oText->getHyperlink()->setTooltip($oElementHlinkClick->getAttribute('tooltip'));
862 3
                            }
863 3
                            if ($oElementHlinkClick->hasAttribute('r:id') && isset($this->arrayRels[$fileRels][$oElementHlinkClick->getAttribute('r:id')]['Target'])) {
0 ignored issues
show
Bug introduced by
The method hasAttribute() does not exist on DOMNode. Did you maybe mean hasAttributes()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
864 3
                                $oText->getHyperlink()->setUrl($this->arrayRels[$fileRels][$oElementHlinkClick->getAttribute('r:id')]['Target']);
865 3
                            }
866 3
                        }
867
                        //} else {
868
                        // $oText = $oParagraph->createText();
869
870 3
                        $oSubSubElement = $document->getElement('a:t', $oSubElement);
871 3
                        $oText->setText($oSubSubElement->nodeValue);
872 3
                    }
873 3
                }
874 3
            }
875 3
        }
876
877 3
        if (count($oShape->getParagraphs()) > 0) {
878 3
            $oShape->setActiveParagraph(0);
879 3
        }
880 3
    }
881
882
    /**
883
     *
884
     * @param string $fileRels
885
     * @return string
886
     */
887 3
    protected function loadRels($fileRels)
888
    {
889 3
        $sPart = $this->oZip->getFromName($fileRels);
890 3
        if ($sPart !== false) {
891 3
            $xmlReader = new XMLReader();
892 3
            if ($xmlReader->getDomFromString($sPart)) {
893 3
                foreach ($xmlReader->getElements('*') as $oNode) {
894 3
                    $this->arrayRels[$fileRels][$oNode->getAttribute('Id')] = array(
895 3
                        'Target' => $oNode->getAttribute('Target'),
896 3
                        'Type' => $oNode->getAttribute('Type'),
897
                    );
898 3
                }
899 3
            }
900 3
        }
901 3
    }
902
903
    /**
904
     * @param $oSlide
905
     * @param $oElements
906
     * @param $xmlReader
907
     * @internal param $baseFile
908
     */
909 3
    private function loadSlideShapes($oSlide, $oElements, $xmlReader)
910
    {
911 3
        foreach ($oElements as $oNode) {
912 3
            switch ($oNode->tagName) {
913 3
                case 'p:pic':
914
                    $this->loadShapeDrawing($xmlReader, $oNode, $oSlide);
915
                    break;
916 3
                case 'p:sp':
917 3
                    $this->loadShapeRichText($xmlReader, $oNode, $oSlide);
918 3
                    break;
919 3
                default:
920
                    //var_export($oNode->tagName);
921 3
            }
922 3
        }
923 3
    }
924
}
925