Completed
Pull Request — develop (#322)
by Thomas
08:13 queued 03:00
created

PowerPoint2007::loadMasterSlide()   F

Complexity

Conditions 33
Paths 449

Size

Total Lines 131
Code Lines 83

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 103
CRAP Score 33.1811

Importance

Changes 0
Metric Value
dl 0
loc 131
ccs 103
cts 109
cp 0.945
rs 3.1788
c 0
b 0
f 0
cc 33
eloc 83
nc 449
nop 2
crap 33.1811

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\DocumentLayout;
21
use PhpOffice\PhpPresentation\Shape\RichText\Paragraph;
22
use PhpOffice\PhpPresentation\Slide\AbstractSlide;
23
use PhpOffice\PhpPresentation\Shape\Placeholder;
24
use PhpOffice\PhpPresentation\Slide\Background\Image;
25
use PhpOffice\PhpPresentation\Slide\SlideLayout;
26
use PhpOffice\PhpPresentation\Slide\SlideMaster;
27
use PhpOffice\PhpPresentation\Shape\Drawing\Gd;
28
use PhpOffice\PhpPresentation\Style\SchemeColor;
29
use PhpOffice\PhpPresentation\Style\TextStyle;
30
use ZipArchive;
31
use PhpOffice\Common\XMLReader;
32
use PhpOffice\Common\Drawing as CommonDrawing;
33
use PhpOffice\PhpPresentation\PhpPresentation;
34
use PhpOffice\PhpPresentation\Style\Bullet;
35
use PhpOffice\PhpPresentation\Style\Color;
36
37
/**
38
 * Serialized format reader
39
 */
40
class PowerPoint2007 implements ReaderInterface
41
{
42
    /**
43
     * Output Object
44
     * @var PhpPresentation
45
     */
46
    protected $oPhpPresentation;
47
    /**
48
     * Output Object
49
     * @var \ZipArchive
50
     */
51
    protected $oZip;
52
    /**
53
     * @var array[]
54
     */
55
    protected $arrayRels = array();
56
    /**
57
     * @var SlideLayout[]
58
     */
59
    protected $arraySlideLayouts = array();
60
    /*
61
     * @var string
62
     */
63
    protected $filename;
64
65
    /**
66
     * Can the current \PhpOffice\PhpPresentation\Reader\ReaderInterface read the file?
67
     *
68
     * @param  string $pFilename
69
     * @throws \Exception
70
     * @return boolean
71
     */
72 2
    public function canRead($pFilename)
73
    {
74 2
        return $this->fileSupportsUnserializePhpPresentation($pFilename);
75
    }
76
77
    /**
78
     * Does a file support UnserializePhpPresentation ?
79
     *
80
     * @param  string $pFilename
81
     * @throws \Exception
82
     * @return boolean
83
     */
84 9
    public function fileSupportsUnserializePhpPresentation($pFilename = '')
85
    {
86
        // Check if file exists
87 9
        if (!file_exists($pFilename)) {
88 2
            throw new \Exception("Could not open " . $pFilename . " for reading! File does not exist.");
89
        }
90
91 7
        $oZip = new ZipArchive();
92
        // Is it a zip ?
93 7
        if ($oZip->open($pFilename) === true) {
94
            // Is it an OpenXML Document ?
95
            // Is it a Presentation ?
96 5
            if (is_array($oZip->statName('[Content_Types].xml')) && is_array($oZip->statName('ppt/presentation.xml'))) {
97 5
                return true;
98
            }
99 1
        }
100 3
        return false;
101
    }
102
103
    /**
104
     * Loads PhpPresentation Serialized file
105
     *
106
     * @param  string $pFilename
107
     * @return \PhpOffice\PhpPresentation\PhpPresentation
108
     * @throws \Exception
109
     */
110 6
    public function load($pFilename)
111
    {
112
        // Unserialize... First make sure the file supports it!
113 6
        if (!$this->fileSupportsUnserializePhpPresentation($pFilename)) {
114 1
            throw new \Exception("Invalid file format for PhpOffice\PhpPresentation\Reader\PowerPoint2007: " . $pFilename . ".");
115
        }
116
117 4
        return $this->loadFile($pFilename);
118
    }
119
120
    /**
121
     * Load PhpPresentation Serialized file
122
     *
123
     * @param  string $pFilename
124
     * @return \PhpOffice\PhpPresentation\PhpPresentation
125
     */
126 4
    protected function loadFile($pFilename)
127
    {
128 4
        $this->oPhpPresentation = new PhpPresentation();
129 4
        $this->oPhpPresentation->removeSlideByIndex();
130 4
        $this->oPhpPresentation->setAllMasterSlides(array());
131 4
        $this->filename = $pFilename;
132
133 4
        $this->oZip = new ZipArchive();
134 4
        $this->oZip->open($this->filename);
135 4
        $docPropsCore = $this->oZip->getFromName('docProps/core.xml');
136 4
        if ($docPropsCore !== false) {
137 4
            $this->loadDocumentProperties($docPropsCore);
138 4
        }
139
140 4
        $docPropsCustom = $this->oZip->getFromName('docProps/custom.xml');
141 4
        if ($docPropsCustom !== false) {
142 1
            $this->loadCustomProperties($docPropsCustom);
143 1
        }
144
145 4
        $pptViewProps = $this->oZip->getFromName('ppt/viewProps.xml');
146 4
        if ($pptViewProps !== false) {
147 4
            $this->loadViewProperties($pptViewProps);
148 4
        }
149
150 4
        $pptPresentation = $this->oZip->getFromName('ppt/presentation.xml');
151 4
        if ($pptPresentation !== false) {
152 4
            $this->loadDocumentLayout($pptPresentation);
153 4
            $this->loadSlides($pptPresentation);
154 4
        }
155
156 4
        return $this->oPhpPresentation;
157
    }
158
159
    /**
160
     * Read Document Layout
161
     * @param $sPart
162
     */
163 4
    protected function loadDocumentLayout($sPart)
164
    {
165 4
        $xmlReader = new XMLReader();
166 4
        if ($xmlReader->getDomFromString($sPart)) {
167 4
            foreach ($xmlReader->getElements('/p:presentation/p:sldSz') as $oElement) {
168 4
                $type = $oElement->getAttribute('type');
169 4
                $oLayout = $this->oPhpPresentation->getLayout();
170 4
                if ($type == DocumentLayout::LAYOUT_CUSTOM) {
171
                    $oLayout->setCX($oElement->getAttribute('cx'));
172
                    $oLayout->setCY($oElement->getAttribute('cy'));
173
                } else {
174 4
                    $oLayout->setDocumentLayout($type, true);
175 4
                    if ($oElement->getAttribute('cx') < $oElement->getAttribute('cy')) {
176
                        $oLayout->setDocumentLayout($type, false);
177
                    }
178
                }
179 4
            }
180 4
        }
181 4
    }
182
183
    /**
184
     * Read Document Properties
185
     * @param string $sPart
186
     */
187 4
    protected function loadDocumentProperties($sPart)
188
    {
189 4
        $xmlReader = new XMLReader();
190 4
        if ($xmlReader->getDomFromString($sPart)) {
191
            $arrayProperties = array(
192 4
                '/cp:coreProperties/dc:creator' => 'setCreator',
193 4
                '/cp:coreProperties/cp:lastModifiedBy' => 'setLastModifiedBy',
194 4
                '/cp:coreProperties/dc:title' => 'setTitle',
195 4
                '/cp:coreProperties/dc:description' => 'setDescription',
196 4
                '/cp:coreProperties/dc:subject' => 'setSubject',
197 4
                '/cp:coreProperties/cp:keywords' => 'setKeywords',
198 4
                '/cp:coreProperties/cp:category' => 'setCategory',
199 4
                '/cp:coreProperties/dcterms:created' => 'setCreated',
200 4
                '/cp:coreProperties/dcterms:modified' => 'setModified',
201 4
            );
202 4
            $oProperties = $this->oPhpPresentation->getDocumentProperties();
203 4
            foreach ($arrayProperties as $path => $property) {
204 4
                if (is_object($oElement = $xmlReader->getElement($path))) {
205 4
                    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...
206 4
                        $oDateTime = new \DateTime();
207 4
                        $oDateTime->createFromFormat(\DateTime::W3C, $oElement->nodeValue);
208 4
                        $oProperties->{$property}($oDateTime->getTimestamp());
209 4
                    } else {
210 4
                        $oProperties->{$property}($oElement->nodeValue);
211
                    }
212 4
                }
213 4
            }
214 4
        }
215 4
    }
216
217
    /**
218
     * Read Custom Properties
219
     * @param string $sPart
220
     */
221 1
    protected function loadCustomProperties($sPart)
222
    {
223 1
        $xmlReader = new XMLReader();
224 1
        $sPart = str_replace(' xmlns="http://schemas.openxmlformats.org/officeDocument/2006/custom-properties"', '', $sPart);
225 1
        if ($xmlReader->getDomFromString($sPart)) {
226 1
            $pathMarkAsFinal = '/Properties/property[@pid="2"][@fmtid="{D5CDD505-2E9C-101B-9397-08002B2CF9AE}"][@name="_MarkAsFinal"]/vt:bool';
227 1
            if (is_object($oElement = $xmlReader->getElement($pathMarkAsFinal))) {
228 1
                if ($oElement->nodeValue == 'true') {
229 1
                    $this->oPhpPresentation->getPresentationProperties()->markAsFinal(true);
230 1
                }
231 1
            }
232 1
        }
233 1
    }
234
235
    /**
236
     * Read View Properties
237
     * @param string $sPart
238
     */
239 4
    protected function loadViewProperties($sPart)
240
    {
241 4
        $xmlReader = new XMLReader();
242 4
        if ($xmlReader->getDomFromString($sPart)) {
243 4
            $pathZoom = '/p:viewPr/p:slideViewPr/p:cSldViewPr/p:cViewPr/p:scale/a:sx';
244 4
            if (is_object($oElement = $xmlReader->getElement($pathZoom))) {
245 3
                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...
246 3
                    $this->oPhpPresentation->getPresentationProperties()->setZoom($oElement->getAttribute('n') / $oElement->getAttribute('d'));
247 3
                }
248 3
            }
249 4
        }
250 4
    }
251
252
    /**
253
     * Extract all slides
254
     */
255 4
    protected function loadSlides($sPart)
256
    {
257 4
        $xmlReader = new XMLReader();
258 4
        if ($xmlReader->getDomFromString($sPart)) {
259 4
            $fileRels = 'ppt/_rels/presentation.xml.rels';
260 4
            $this->loadRels($fileRels);
261
            // Load the Masterslides
262 4
            $this->loadMasterSlides($xmlReader, $fileRels);
263
            // Continue with loading the slides
264 4
            foreach ($xmlReader->getElements('/p:presentation/p:sldIdLst/p:sldId') as $oElement) {
265 4
                $rId = $oElement->getAttribute('r:id');
266 4
                $pathSlide = isset($this->arrayRels[$fileRels][$rId]) ? $this->arrayRels[$fileRels][$rId]['Target'] : '';
267 4
                if (!empty($pathSlide)) {
268 4
                    $pptSlide = $this->oZip->getFromName('ppt/' . $pathSlide);
269 4
                    if ($pptSlide !== false) {
270 4
                        $this->loadRels('ppt/slides/_rels/' . basename($pathSlide) . '.rels');
271 4
                        $this->loadSlide($pptSlide, basename($pathSlide));
272 4
                    }
273 4
                }
274 4
            }
275 4
        }
276 4
    }
277
278
    /**
279
     * Extract all MasterSlides
280
     * @param XMLReader $xmlReader
281
     * @param $fileRels
282
     */
283 4
    protected function loadMasterSlides(XMLReader $xmlReader, $fileRels)
284
    {
285
        // Get all the MasterSlide Id's from the presentation.xml file
286 4
        foreach ($xmlReader->getElements('/p:presentation/p:sldMasterIdLst/p:sldMasterId') as $oElement) {
287 4
            $rId = $oElement->getAttribute('r:id');
288
            // Get the path to the masterslide from the array with _rels files
289 4
            $pathMasterSlide = isset($this->arrayRels[$fileRels][$rId]) ?
290 4
                $this->arrayRels[$fileRels][$rId]['Target'] : '';
291 4
            if (!empty($pathMasterSlide)) {
292 4
                $pptMasterSlide = $this->oZip->getFromName('ppt/' . $pathMasterSlide);
293 4
                if ($pptMasterSlide !== false) {
294 4
                    $this->loadRels('ppt/slideMasters/_rels/' . basename($pathMasterSlide) . '.rels');
295 4
                    $this->loadMasterSlide($pptMasterSlide, basename($pathMasterSlide));
296 4
                }
297 4
            }
298 4
        }
299 4
    }
300
301
    /**
302
     * Extract data from slide
303
     * @param string $sPart
304
     * @param string $baseFile
305
     */
306 4
    protected function loadSlide($sPart, $baseFile)
307
    {
308 4
        $xmlReader = new XMLReader();
309 4
        if ($xmlReader->getDomFromString($sPart)) {
310
            // Core
311 4
            $oSlide = $this->oPhpPresentation->createSlide();
312 4
            $this->oPhpPresentation->setActiveSlideIndex($this->oPhpPresentation->getSlideCount() - 1);
313 4
            $oSlide->setRelsIndex('ppt/slides/_rels/' . $baseFile . '.rels');
314
315
            // Background
316 4
            $oElement = $xmlReader->getElement('/p:sld/p:cSld/p:bg/p:bgPr');
317 4
            if ($oElement) {
318
                $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...
319
                if ($oElementColor) {
320
                    // Color
321
                    $oColor = new Color();
322
                    $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...
323
                    // Background
324
                    $oBackground = new \PhpOffice\PhpPresentation\Slide\Background\Color();
325
                    $oBackground->setColor($oColor);
326
                    // Slide Background
327
                    $oSlide = $this->oPhpPresentation->getActiveSlide();
328
                    $oSlide->setBackground($oBackground);
329
                }
330
                $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...
331
                if ($oElementImage) {
332
                    $relImg = $this->arrayRels['ppt/slides/_rels/' . $baseFile . '.rels'][$oElementImage->getAttribute('r:embed')];
333
                    if (is_array($relImg)) {
334
                        // File
335
                        $pathImage = 'ppt/slides/' . $relImg['Target'];
336
                        $pathImage = explode('/', $pathImage);
337
                        foreach ($pathImage as $key => $partPath) {
338
                            if ($partPath == '..') {
339
                                unset($pathImage[$key - 1]);
340
                                unset($pathImage[$key]);
341
                            }
342
                        }
343
                        $pathImage = implode('/', $pathImage);
344
                        $contentImg = $this->oZip->getFromName($pathImage);
345
346
                        $tmpBkgImg = tempnam(sys_get_temp_dir(), 'PhpPresentationReaderPpt2007Bkg');
347
                        file_put_contents($tmpBkgImg, $contentImg);
348
                        // Background
349
                        $oBackground = new Image();
350
                        $oBackground->setPath($tmpBkgImg);
351
                        // Slide Background
352
                        $oSlide = $this->oPhpPresentation->getActiveSlide();
353
                        $oSlide->setBackground($oBackground);
354
                    }
355
                }
356
            }
357
358
            // Shapes
359 4
            foreach ($xmlReader->getElements('/p:sld/p:cSld/p:spTree/*') as $oNode) {
360 4
                switch ($oNode->tagName) {
361 4
                    case 'p:pic':
362 3
                        $this->loadShapeDrawing($xmlReader, $oNode, $oSlide);
363 3
                        break;
364 4
                    case 'p:sp':
365 4
                        $this->loadShapeRichText($xmlReader, $oNode, $oSlide);
366 4
                        break;
367 4
                    default:
368
                        //var_export($oNode->tagName);
369 4
                }
370 4
            }
371
            // Layout
372 4
            $oSlide = $this->oPhpPresentation->getActiveSlide();
373 4
            foreach ($this->arrayRels['ppt/slides/_rels/' . $baseFile . '.rels'] as $valueRel) {
374 4
                if ($valueRel['Type'] == 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/slideLayout') {
375 4
                    $layoutBasename = basename($valueRel['Target']);
376 4
                    if (array_key_exists($layoutBasename, $this->arraySlideLayouts)) {
377 4
                        $oSlide->setSlideLayout($this->arraySlideLayouts[$layoutBasename]);
378 4
                    }
379 4
                    break;
380
                }
381 4
            }
382 4
        }
383 4
    }
384
385 4
    private function loadMasterSlide($sPart, $baseFile)
386
    {
387 4
        $xmlReader = new XMLReader();
388 4
        if ($xmlReader->getDomFromString($sPart)) {
389
            // Core
390 4
            $oSlideMaster = $this->oPhpPresentation->createMasterSlide();
391 4
            $oSlideMaster->setTextStyles(new TextStyle(false));
392 4
            $oSlideMaster->setRelsIndex('ppt/slideMasters/_rels/' . $baseFile . '.rels');
393
394
            // Background
395 4
            $oElement = $xmlReader->getElement('/p:sldMaster/p:cSld/p:bg');
396 4
            if ($oElement) {
397 4
                $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...
398 4
            }
399
400
            // Shapes
401 4
            $arrayElements = $xmlReader->getElements('/p:sldMaster/p:cSld/p:spTree/*');
402 4
            if ($arrayElements) {
403 4
                $this->loadSlideShapes($oSlideMaster, $arrayElements, $xmlReader);
404 4
            }
405
            // Header & Footer
406
407
            // ColorMapping
408 4
            $colorMap = array();
409 4
            $oElement = $xmlReader->getElement('/p:sldMaster/p:clrMap');
410 4
            if ($oElement->hasAttributes()) {
411 4
                foreach ($oElement->attributes as $attr) {
412 4
                    $colorMap[$attr->nodeName] = $attr->nodeValue;
413 4
                }
414 4
                $oSlideMaster->colorMap->setMapping($colorMap);
415 4
            }
416
417
            // TextStyles
418 4
            $arrayElementTxStyles = $xmlReader->getElements('/p:sldMaster/p:txStyles/*');
419 4
            if ($arrayElementTxStyles) {
420 4
                foreach ($arrayElementTxStyles as $oElementTxStyle) {
421 4
                    $arrayElementsLvl = $xmlReader->getElements('/p:sldMaster/p:txStyles/'.$oElementTxStyle->nodeName.'/*');
422 4
                    foreach ($arrayElementsLvl as $oElementLvl) {
423 4
                        if ($oElementLvl->nodeName == 'a:extLst') {
424 1
                            continue;
425
                        }
426 4
                        $oRTParagraph = new Paragraph();
427
428 4
                        if ($oElementLvl->nodeName == 'a:defPPr') {
429 3
                            $level = 0;
430 3
                        } else {
431 4
                            $level = str_replace('a:lvl', '', $oElementLvl->nodeName);
432 4
                            $level = str_replace('pPr', '', $level);
433
                        }
434
435 4
                        if ($oElementLvl->hasAttribute('algn')) {
436 4
                            $oRTParagraph->getAlignment()->setHorizontal($oElementLvl->getAttribute('algn'));
437 4
                        }
438 4
                        if ($oElementLvl->hasAttribute('marL')) {
439 4
                            $val = $oElementLvl->getAttribute('marL');
440 4
                            $val = CommonDrawing::emuToPixels($val);
441 4
                            $oRTParagraph->getAlignment()->setMarginLeft($val);
442 4
                        }
443 4
                        if ($oElementLvl->hasAttribute('marR')) {
444
                            $val = $oElementLvl->getAttribute('marR');
445
                            $val = CommonDrawing::emuToPixels($val);
446
                            $oRTParagraph->getAlignment()->setMarginRight($val);
447
                        }
448 4
                        if ($oElementLvl->hasAttribute('indent')) {
449 4
                            $val = $oElementLvl->getAttribute('indent');
450 4
                            $val = CommonDrawing::emuToPixels($val);
451 4
                            $oRTParagraph->getAlignment()->setIndent($val);
452 4
                        }
453 4
                        $oElementLvlDefRPR = $xmlReader->getElement('a:defRPr', $oElementLvl);
454 4
                        if ($oElementLvlDefRPR) {
455 4
                            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...
456 4
                                $oRTParagraph->getFont()->setSize($oElementLvlDefRPR->getAttribute('sz') / 100);
457 4
                            }
458 4
                            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...
459 1
                                $oRTParagraph->getFont()->setBold(true);
460 1
                            }
461 4
                            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...
462
                                $oRTParagraph->getFont()->setItalic(true);
463
                            }
464 4
                        }
465 4
                        $oElementSchemeColor = $xmlReader->getElement('a:defRPr/a:solidFill/a:schemeClr', $oElementLvl);
466 4
                        if ($oElementSchemeColor) {
467 4
                            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...
468 4
                                $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...
469 4
                            }
470 4
                        }
471
472 4
                        switch ($oElementTxStyle->nodeName) {
473 4
                            case 'p:bodyStyle':
474 4
                                $oSlideMaster->getTextStyles()->setBodyStyleAtLvl($oRTParagraph, $level);
475 4
                                break;
476 4
                            case 'p:otherStyle':
477 4
                                $oSlideMaster->getTextStyles()->setOtherStyleAtLvl($oRTParagraph, $level);
478 4
                                break;
479 4
                            case 'p:titleStyle':
480 4
                                $oSlideMaster->getTextStyles()->setTitleStyleAtLvl($oRTParagraph, $level);
481 4
                                break;
482 4
                        }
483 4
                    }
484 4
                }
485 4
            }
486
487
            // Load the theme
488 4
            foreach ($this->arrayRels[$oSlideMaster->getRelsIndex()] as $arrayRel) {
489 4
                if ($arrayRel['Type'] == 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme') {
490 4
                    $pptTheme = $this->oZip->getFromName('ppt/' . substr($arrayRel['Target'], strrpos($arrayRel['Target'], '../') + 3));
491 4
                    if ($pptTheme !== false) {
492 4
                        $this->loadTheme($pptTheme, $oSlideMaster);
493 4
                    }
494 4
                    break;
495
                }
496 4
            }
497
498
            // Load the Layoutslide
499 4
            foreach ($xmlReader->getElements('/p:sldMaster/p:sldLayoutIdLst/p:sldLayoutId') as $oElement) {
500 4
                $rId = $oElement->getAttribute('r:id');
501
                // Get the path to the masterslide from the array with _rels files
502 4
                $pathLayoutSlide = isset($this->arrayRels[$oSlideMaster->getRelsIndex()][$rId]) ?
503 4
                    $this->arrayRels[$oSlideMaster->getRelsIndex()][$rId]['Target'] : '';
504 4
                if (!empty($pathLayoutSlide)) {
505 4
                    $pptLayoutSlide = $this->oZip->getFromName('ppt/' . substr($pathLayoutSlide, strrpos($pathLayoutSlide, '../') + 3));
506 4
                    if ($pptLayoutSlide !== false) {
507 4
                        $this->loadRels('ppt/slideLayouts/_rels/' . basename($pathLayoutSlide) . '.rels');
508 4
                        $oSlideMaster->addSlideLayout(
509 4
                            $this->loadLayoutSlide($pptLayoutSlide, basename($pathLayoutSlide), $oSlideMaster)
510 4
                        );
511 4
                    }
512 4
                }
513 4
            }
514 4
        }
515 4
    }
516
517 4
    private function loadLayoutSlide($sPart, $baseFile, SlideMaster $oSlideMaster)
518
    {
519 4
        $xmlReader = new XMLReader();
520 4
        if ($xmlReader->getDomFromString($sPart)) {
521
            // Core
522 4
            $oSlideLayout = new SlideLayout($oSlideMaster);
523 4
            $oSlideLayout->setRelsIndex('ppt/slideLayouts/_rels/' . $baseFile . '.rels');
524
525
            // Name
526 4
            $oElement = $xmlReader->getElement('/p:sldLayout/p:cSld');
527 4
            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...
528 4
                $oSlideLayout->setLayoutName($oElement->getAttribute('name'));
529 4
            }
530
531
            // Background
532 4
            $oElement = $xmlReader->getElement('/p:sldLayout/p:cSld/p:bg');
533 4
            if ($oElement) {
534 1
                $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...
535 1
            }
536
537
            // ColorMapping
538 4
            $oElement = $xmlReader->getElement('/p:sldLayout/p:clrMapOvr/a:overrideClrMapping');
539 4
            if ($oElement && $oElement->hasAttributes()) {
540 1
                $colorMap = array();
541 1
                foreach ($oElement->attributes as $attr) {
542 1
                    $colorMap[$attr->nodeName] = $attr->nodeValue;
543 1
                }
544 1
                $oSlideLayout->colorMap->setMapping($colorMap);
545 1
            }
546
547
            // Shapes
548 4
            $oElements = $xmlReader->getElements('/p:sldLayout/p:cSld/p:spTree/*');
549 4
            if ($oElements) {
550 4
                $this->loadSlideShapes($oSlideLayout, $oElements, $xmlReader);
551 4
            }
552 4
            $this->arraySlideLayouts[$baseFile] = &$oSlideLayout;
553 4
            return $oSlideLayout;
554
        }
555
        return null;
556
    }
557
558
    /**
559
     * @param string $sPart
560
     * @param SlideMaster $oSlideMaster
561
     */
562 4
    private function loadTheme($sPart, SlideMaster $oSlideMaster)
563
    {
564 4
        $xmlReader = new XMLReader();
565 4
        if ($xmlReader->getDomFromString($sPart)) {
566 4
            $oElements = $xmlReader->getElements('/a:theme/a:themeElements/a:clrScheme/*');
567 4
            if ($oElements) {
568 4
                foreach ($oElements as $oElement) {
569 4
                    $oSchemeColor = new SchemeColor();
570 4
                    $oSchemeColor->setValue(str_replace('a:', '', $oElement->tagName));
571 4
                    $colorElement = $xmlReader->getElement('*', $oElement);
572 4
                    if ($colorElement) {
573 4
                        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...
574 4
                            $oSchemeColor->setRGB($colorElement->getAttribute('lastClr'));
575 4
                        } 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...
576 4
                            $oSchemeColor->setRGB($colorElement->getAttribute('val'));
577 4
                        }
578 4
                    }
579 4
                    $oSlideMaster->addSchemeColor($oSchemeColor);
580 4
                }
581 4
            }
582 4
        }
583 4
    }
584
585
    /**
586
     * @param XMLReader $xmlReader
587
     * @param \DOMElement $oElement
588
     * @param AbstractSlide $oSlide
589
     */
590 4
    private function loadSlideBackground(XMLReader $xmlReader, \DOMElement $oElement, AbstractSlide $oSlide)
591
    {
592
        // Background color
593 4
        $oElementColor = $xmlReader->getElement('p:bgPr/a:solidFill/a:srgbClr', $oElement);
594 4
        if ($oElementColor) {
595
            // Color
596
            $oColor = new Color();
597
            $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...
598
            // Background
599
            $oBackground = new \PhpOffice\PhpPresentation\Slide\Background\Color();
600
            $oBackground->setColor($oColor);
601
            // Slide Background
602
            $oSlide->setBackground($oBackground);
603
        }
604
605
        // Background scheme color
606 4
        $oElementSchemeColor = $xmlReader->getElement('p:bgRef/a:schemeClr', $oElement);
607 4
        if ($oElementSchemeColor) {
608
            // Color
609 4
            $oColor = new SchemeColor();
610 4
            $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...
611
            // Background
612 4
            $oBackground = new \PhpOffice\PhpPresentation\Slide\Background\SchemeColor();
613 4
            $oBackground->setSchemeColor($oColor);
614
            // Slide Background
615 4
            $oSlide->setBackground($oBackground);
616 4
        }
617
618
        // Background image
619 4
        $oElementImage = $xmlReader->getElement('p:bgPr/a:blipFill/a:blip', $oElement);
620 4
        if ($oElementImage) {
621
            $relImg = $this->arrayRels[$oSlide->getRelsIndex()][$oElementImage->getAttribute('r:embed')];
622
            if (is_array($relImg)) {
623
                // File
624
                $pathImage = 'ppt/slides/' . $relImg['Target'];
625
                $pathImage = explode('/', $pathImage);
626
                foreach ($pathImage as $key => $partPath) {
627
                    if ($partPath == '..') {
628
                        unset($pathImage[$key - 1]);
629
                        unset($pathImage[$key]);
630
                    }
631
                }
632
                $pathImage = implode('/', $pathImage);
633
                $contentImg = $this->oZip->getFromName($pathImage);
634
635
                $tmpBkgImg = tempnam(sys_get_temp_dir(), 'PhpPresentationReaderPpt2007Bkg');
636
                file_put_contents($tmpBkgImg, $contentImg);
637
                // Background
638
                $oBackground = new Image();
639
                $oBackground->setPath($tmpBkgImg);
640
                // Slide Background
641
                $oSlide->setBackground($oBackground);
642
            }
643
        }
644 4
    }
645
646
    /**
647
     *
648
     * @param XMLReader $document
649
     * @param \DOMElement $node
650
     * @param AbstractSlide $oSlide
651
     */
652 3
    protected function loadShapeDrawing(XMLReader $document, \DOMElement $node, AbstractSlide $oSlide)
653
    {
654
        // Core
655 3
        $oShape = new Gd();
656 3
        $oShape->getShadow()->setVisible(false);
657
        // Variables
658 3
        $fileRels = $oSlide->getRelsIndex();
659
660 3
        $oElement = $document->getElement('p:nvPicPr/p:cNvPr', $node);
661 3
        if ($oElement) {
662 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...
663 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...
664 3
        }
665
666 3
        $oElement = $document->getElement('p:blipFill/a:blip', $node);
667 3
        if ($oElement) {
668 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...
669 3
                $pathImage = 'ppt/slides/' . $this->arrayRels[$fileRels][$oElement->getAttribute('r:embed')]['Target'];
670 3
                $pathImage = explode('/', $pathImage);
671 3
                foreach ($pathImage as $key => $partPath) {
672 3
                    if ($partPath == '..') {
673 3
                        unset($pathImage[$key - 1]);
674 3
                        unset($pathImage[$key]);
675 3
                    }
676 3
                }
677 3
                $pathImage = implode('/', $pathImage);
678 3
                $imageFile = $this->oZip->getFromName($pathImage);
679 3
                if (!empty($imageFile)) {
680 3
                    $oShape->setImageResource(imagecreatefromstring($imageFile));
681 3
                }
682 3
            }
683 3
        }
684
685 3
        $oElement = $document->getElement('p:spPr/a:xfrm', $node);
686 3
        if ($oElement) {
687 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...
688 3
                $oShape->setRotation(CommonDrawing::angleToDegrees($oElement->getAttribute('rot')));
689 3
            }
690 3
        }
691
692 3
        $oElement = $document->getElement('p:spPr/a:xfrm/a:off', $node);
693 3
        if ($oElement) {
694 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...
695 3
                $oShape->setOffsetX(CommonDrawing::emuToPixels($oElement->getAttribute('x')));
696 3
            }
697 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...
698 3
                $oShape->setOffsetY(CommonDrawing::emuToPixels($oElement->getAttribute('y')));
699 3
            }
700 3
        }
701
702 3
        $oElement = $document->getElement('p:spPr/a:xfrm/a:ext', $node);
703 3
        if ($oElement) {
704 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...
705 3
                $oShape->setWidth(CommonDrawing::emuToPixels($oElement->getAttribute('cx')));
706 3
            }
707 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...
708 3
                $oShape->setHeight(CommonDrawing::emuToPixels($oElement->getAttribute('cy')));
709 3
            }
710 3
        }
711
712 3
        $oElement = $document->getElement('p:spPr/a:effectLst', $node);
713 3
        if ($oElement) {
714 3
            $oShape->getShadow()->setVisible(true);
715
716 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...
717 3
            if ($oSubElement) {
718 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...
719 3
                    $oShape->getShadow()->setBlurRadius(CommonDrawing::emuToPixels($oSubElement->getAttribute('blurRad')));
720 3
                }
721 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...
722 3
                    $oShape->getShadow()->setDistance(CommonDrawing::emuToPixels($oSubElement->getAttribute('dist')));
723 3
                }
724 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...
725 3
                    $oShape->getShadow()->setDirection(CommonDrawing::angleToDegrees($oSubElement->getAttribute('dir')));
726 3
                }
727 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...
728 3
                    $oShape->getShadow()->setAlignment($oSubElement->getAttribute('algn'));
729 3
                }
730 3
            }
731
732 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...
733 3
            if ($oSubElement) {
734 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...
735 3
                    $oColor = new Color();
736 3
                    $oColor->setRGB($oSubElement->getAttribute('val'));
737 3
                    $oShape->getShadow()->setColor($oColor);
738 3
                }
739 3
            }
740
741 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...
742 3
            if ($oSubElement) {
743 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...
744 3
                    $oShape->getShadow()->setAlpha((int)$oSubElement->getAttribute('val') / 1000);
745 3
                }
746 3
            }
747 3
        }
748
749 3
        $oSlide->addShape($oShape);
750 3
    }
751
752
    /**
753
     * @param XMLReader $document
754
     * @param \DOMElement $node
755
     * @param AbstractSlide $oSlide
756
     * @throws \Exception
757
     */
758 4
    protected function loadShapeRichText(XMLReader $document, \DOMElement $node, AbstractSlide $oSlide)
759
    {
760
        // Core
761 4
        $oShape = $oSlide->createRichTextShape();
762 4
        $oShape->setParagraphs(array());
763
        // Variables
764 4
        $fileRels = $oSlide->getRelsIndex();
765
766 4
        $oElement = $document->getElement('p:spPr/a:xfrm', $node);
767 4
        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...
768 4
            $oShape->setRotation(CommonDrawing::angleToDegrees($oElement->getAttribute('rot')));
769 4
        }
770
771 4
        $oElement = $document->getElement('p:spPr/a:xfrm/a:off', $node);
772 4
        if ($oElement) {
773 4
            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...
774 4
                $oShape->setOffsetX(CommonDrawing::emuToPixels($oElement->getAttribute('x')));
775 4
            }
776 4
            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...
777 4
                $oShape->setOffsetY(CommonDrawing::emuToPixels($oElement->getAttribute('y')));
778 4
            }
779 4
        }
780
781 4
        $oElement = $document->getElement('p:spPr/a:xfrm/a:ext', $node);
782 4
        if ($oElement) {
783 4
            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...
784 4
                $oShape->setWidth(CommonDrawing::emuToPixels($oElement->getAttribute('cx')));
785 4
            }
786 4
            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...
787 4
                $oShape->setHeight(CommonDrawing::emuToPixels($oElement->getAttribute('cy')));
788 4
            }
789 4
        }
790
791 4
        $oElement = $document->getElement('p:nvSpPr/p:nvPr/p:ph', $node);
792 4
        if ($oElement) {
793 4
            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...
794 4
                $placeholder = new Placeholder($oElement->getAttribute('type'));
795 4
                $oShape->setPlaceHolder($placeholder);
796 4
            }
797 4
        }
798
799 4
        $arrayElements = $document->getElements('p:txBody/a:p', $node);
800 4
        foreach ($arrayElements as $oElement) {
801
            // Core
802 4
            $oParagraph = $oShape->createParagraph();
803 4
            $oParagraph->setRichTextElements(array());
804
805 4
            $oSubElement = $document->getElement('a:pPr', $oElement);
806 4
            if ($oSubElement) {
807 4
                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...
808 4
                    $oParagraph->getAlignment()->setHorizontal($oSubElement->getAttribute('algn'));
809 4
                }
810 4
                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...
811 3
                    $oParagraph->getAlignment()->setVertical($oSubElement->getAttribute('fontAlgn'));
812 3
                }
813 4
                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...
814 4
                    $oParagraph->getAlignment()->setMarginLeft(CommonDrawing::emuToPixels($oSubElement->getAttribute('marL')));
815 4
                }
816 4
                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...
817 3
                    $oParagraph->getAlignment()->setMarginRight(CommonDrawing::emuToPixels($oSubElement->getAttribute('marR')));
818 3
                }
819 4
                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...
820 3
                    $oParagraph->getAlignment()->setIndent(CommonDrawing::emuToPixels($oSubElement->getAttribute('indent')));
821 3
                }
822 4
                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...
823 4
                    $oParagraph->getAlignment()->setLevel($oSubElement->getAttribute('lvl'));
824 4
                }
825
826 4
                $oParagraph->getBulletStyle()->setBulletType(Bullet::TYPE_NONE);
827
828 4
                $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...
829 4
                if ($oElementBuFont) {
830 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...
831 3
                        $oParagraph->getBulletStyle()->setBulletFont($oElementBuFont->getAttribute('typeface'));
832 3
                    }
833 3
                }
834 4
                $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...
835 4
                if ($oElementBuChar) {
836 3
                    $oParagraph->getBulletStyle()->setBulletType(Bullet::TYPE_BULLET);
837 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...
838 3
                        $oParagraph->getBulletStyle()->setBulletChar($oElementBuChar->getAttribute('char'));
839 3
                    }
840 3
                }
841 4
                $oElementBuAutoNum = $document->getElement('a:buAutoNum', $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...
842 4
                if ($oElementBuAutoNum) {
843
                    $oParagraph->getBulletStyle()->setBulletType(Bullet::TYPE_NUMERIC);
844
                    if ($oElementBuAutoNum->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...
845
                        $oParagraph->getBulletStyle()->setBulletNumericStyle($oElementBuAutoNum->getAttribute('type'));
846
                    }
847
                    if ($oElementBuAutoNum->hasAttribute('startAt') && $oElementBuAutoNum->getAttribute('startAt') != 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...
848
                        $oParagraph->getBulletStyle()->setBulletNumericStartAt($oElementBuAutoNum->getAttribute('startAt'));
849
                    }
850
                }
851 4
                $oElementBuClr = $document->getElement('a:buClr', $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...
852 4
                if ($oElementBuClr) {
853
                    $oColor = new Color();
854
                    /**
855
                     * @todo Create protected for reading Color
856
                     */
857
                    $oElementColor = $document->getElement('a:srgbClr', $oElementBuClr);
0 ignored issues
show
Documentation introduced by
$oElementBuClr 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...
858
                    if ($oElementColor) {
859
                        $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...
860
                    }
861
                    $oParagraph->getBulletStyle()->setBulletColor($oColor);
862
                }
863 4
            }
864 4
            $arraySubElements = $document->getElements('(a:r|a:br)', $oElement);
865 4
            foreach ($arraySubElements as $oSubElement) {
866 4
                if ($oSubElement->tagName == 'a:br') {
867 3
                    $oParagraph->createBreak();
868 3
                }
869 4
                if ($oSubElement->tagName == 'a:r') {
870 4
                    $oElementrPr = $document->getElement('a:rPr', $oSubElement);
871 4
                    if (is_object($oElementrPr)) {
872 4
                        $oText = $oParagraph->createTextRun();
873
874 4
                        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...
875 3
                            $oText->getFont()->setBold($oElementrPr->getAttribute('b') == 'true' ? true : false);
876 3
                        }
877 4
                        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...
878 3
                            $oText->getFont()->setItalic($oElementrPr->getAttribute('i') == 'true' ? true : false);
879 3
                        }
880 4
                        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...
881 3
                            $oText->getFont()->setStrikethrough($oElementrPr->getAttribute('strike') == 'noStrike' ? false : true);
882 3
                        }
883 4
                        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...
884 3
                            $oText->getFont()->setSize((int)($oElementrPr->getAttribute('sz') / 100));
885 3
                        }
886 4
                        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...
887 3
                            $oText->getFont()->setUnderline($oElementrPr->getAttribute('u'));
888 3
                        }
889
                        // Color
890 4
                        $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...
891 4
                        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...
892 3
                            $oColor = new Color();
893 3
                            $oColor->setRGB($oElementSrgbClr->getAttribute('val'));
894 3
                            $oText->getFont()->setColor($oColor);
895 3
                        }
896
                        // Hyperlink
897 4
                        $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...
898 4
                        if (is_object($oElementHlinkClick)) {
899 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...
900 3
                                $oText->getHyperlink()->setTooltip($oElementHlinkClick->getAttribute('tooltip'));
901 3
                            }
902 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...
903 3
                                $oText->getHyperlink()->setUrl($this->arrayRels[$fileRels][$oElementHlinkClick->getAttribute('r:id')]['Target']);
904 3
                            }
905 3
                        }
906
                        //} else {
907
                        // $oText = $oParagraph->createText();
908
909 4
                        $oSubSubElement = $document->getElement('a:t', $oSubElement);
910 4
                        $oText->setText($oSubSubElement->nodeValue);
911 4
                    }
912 4
                }
913 4
            }
914 4
        }
915
916 4
        if (count($oShape->getParagraphs()) > 0) {
917 4
            $oShape->setActiveParagraph(0);
918 4
        }
919 4
    }
920
921
    /**
922
     *
923
     * @param string $fileRels
924
     * @return string
925
     */
926 4
    protected function loadRels($fileRels)
927
    {
928 4
        $sPart = $this->oZip->getFromName($fileRels);
929 4
        if ($sPart !== false) {
930 4
            $xmlReader = new XMLReader();
931 4
            if ($xmlReader->getDomFromString($sPart)) {
932 4
                foreach ($xmlReader->getElements('*') as $oNode) {
933 4
                    $this->arrayRels[$fileRels][$oNode->getAttribute('Id')] = array(
934 4
                        'Target' => $oNode->getAttribute('Target'),
935 4
                        'Type' => $oNode->getAttribute('Type'),
936
                    );
937 4
                }
938 4
            }
939 4
        }
940 4
    }
941
942
    /**
943
     * @param $oSlide
944
     * @param $oElements
945
     * @param $xmlReader
946
     * @internal param $baseFile
947
     */
948 4
    private function loadSlideShapes($oSlide, $oElements, $xmlReader)
949
    {
950 4
        foreach ($oElements as $oNode) {
951 4
            switch ($oNode->tagName) {
952 4
                case 'p:pic':
953
                    $this->loadShapeDrawing($xmlReader, $oNode, $oSlide);
954
                    break;
955 4
                case 'p:sp':
956 4
                    $this->loadShapeRichText($xmlReader, $oNode, $oSlide);
957 4
                    break;
958 4
                default:
959
                    //var_export($oNode->tagName);
960 4
            }
961 4
        }
962 4
    }
963
}
964