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