Code Coverage
 
Classes and Traits
Functions and Methods
Lines
Total
0.00% covered (danger)
0.00%
0 / 1
95.83% covered (success)
95.83%
23 / 24
CRAP
96.72% covered (success)
96.72%
59 / 61
PhpPresentation
0.00% covered (danger)
0.00%
0 / 1
95.83% covered (success)
95.83%
23 / 24
33
96.72% covered (success)
96.72%
59 / 61
 __construct
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
7 / 7
 getDocumentProperties
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 setDocumentProperties
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
2 / 2
 getPresentationProperties
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 setPresentationProperties
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
2 / 2
 getLayout
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 setLayout
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
2 / 2
 getActiveSlide
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 createSlide
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
3 / 3
 addSlide
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
2 / 2
 removeSlideByIndex
100.00% covered (success)
100.00%
1 / 1
2
100.00% covered (success)
100.00%
4 / 4
 getSlide
100.00% covered (success)
100.00%
1 / 1
2
100.00% covered (success)
100.00%
3 / 3
 getAllSlides
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 getIndex
0.00% covered (danger)
0.00%
0 / 1
4.59
66.67% covered (warning)
66.67%
4 / 6
 getSlideCount
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 getActiveSlideIndex
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 setActiveSlideIndex
100.00% covered (success)
100.00%
1 / 1
2
100.00% covered (success)
100.00%
4 / 4
 addExternalSlide
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
3 / 3
 getSlideIterator
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 createMasterSlide
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
3 / 3
 addMasterSlide
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
2 / 2
 copy
100.00% covered (success)
100.00%
1 / 1
2
100.00% covered (success)
100.00%
6 / 6
 getAllMasterSlides
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 setAllMasterSlides
100.00% covered (success)
100.00%
1 / 1
3
100.00% covered (success)
100.00%
3 / 3
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 * @see        https://github.com/PHPOffice/PHPPresentation
14 *
15 * @copyright   2009-2015 PHPPresentation contributors
16 * @license     http://www.gnu.org/licenses/lgpl.txt LGPL version 3
17 */
18
19declare(strict_types=1);
20
21namespace PhpOffice\PhpPresentation;
22
23use ArrayObject;
24use PhpOffice\PhpPresentation\Exception\OutOfBoundsException;
25use PhpOffice\PhpPresentation\Slide\Iterator;
26use PhpOffice\PhpPresentation\Slide\SlideMaster;
27
28/**
29 * PhpPresentation.
30 */
31class PhpPresentation
32{
33    /**
34     * Document properties.
35     *
36     * @var DocumentProperties
37     */
38    protected $documentProperties;
39
40    /**
41     * Presentation properties.
42     *
43     * @var PresentationProperties
44     */
45    protected $presentationProps;
46
47    /**
48     * Document layout.
49     *
50     * @var DocumentLayout
51     */
52    protected $layout;
53
54    /**
55     * Collection of Slide objects.
56     *
57     * @var array<int, Slide>
58     */
59    protected $slideCollection = [];
60
61    /**
62     * Active slide index.
63     *
64     * @var int
65     */
66    protected $activeSlideIndex = 0;
67
68    /**
69     * Collection of Master Slides.
70     *
71     * @var array<int, SlideMaster>|ArrayObject<int, SlideMaster>
72     */
73    protected $slideMasters;
74
75    /**
76     * Create a new PhpPresentation with one Slide.
77     */
78    public function __construct()
79    {
80        // Set empty Master & SlideLayout
81        $this->createMasterSlide()->createSlideLayout();
82
83        // Initialise slide collection and add one slide
84        $this->createSlide();
85        $this->setActiveSlideIndex();
86
87        // Set initial document properties & layout
88        $this->setDocumentProperties(new DocumentProperties());
89        $this->setPresentationProperties(new PresentationProperties());
90        $this->setLayout(new DocumentLayout());
91    }
92
93    /**
94     * Get properties.
95     */
96    public function getDocumentProperties(): DocumentProperties
97    {
98        return $this->documentProperties;
99    }
100
101    /**
102     * Set properties.
103     */
104    public function setDocumentProperties(DocumentProperties $value): self
105    {
106        $this->documentProperties = $value;
107
108        return $this;
109    }
110
111    /**
112     * Get presentation properties.
113     */
114    public function getPresentationProperties(): PresentationProperties
115    {
116        return $this->presentationProps;
117    }
118
119    /**
120     * Set presentation properties.
121     *
122     * @return PhpPresentation
123     */
124    public function setPresentationProperties(PresentationProperties $value): self
125    {
126        $this->presentationProps = $value;
127
128        return $this;
129    }
130
131    /**
132     * Get layout.
133     */
134    public function getLayout(): DocumentLayout
135    {
136        return $this->layout;
137    }
138
139    /**
140     * Set layout.
141     */
142    public function setLayout(DocumentLayout $value): self
143    {
144        $this->layout = $value;
145
146        return $this;
147    }
148
149    /**
150     * Get active slide.
151     */
152    public function getActiveSlide(): Slide
153    {
154        return $this->slideCollection[$this->activeSlideIndex];
155    }
156
157    /**
158     * Create slide and add it to this presentation.
159     */
160    public function createSlide(): Slide
161    {
162        $newSlide = new Slide($this);
163        $this->addSlide($newSlide);
164
165        return $newSlide;
166    }
167
168    /**
169     * Add slide.
170     */
171    public function addSlide(Slide $slide): Slide
172    {
173        $this->slideCollection[] = $slide;
174
175        return $slide;
176    }
177
178    /**
179     * Remove slide by index.
180     *
181     * @param int $index Slide index
182     *
183     * @throws OutOfBoundsException
184     */
185    public function removeSlideByIndex(int $index = 0): self
186    {
187        if ($index > count($this->slideCollection) - 1) {
188            throw new OutOfBoundsException(0, count($this->slideCollection) - 1, $index);
189        }
190        array_splice($this->slideCollection, $index, 1);
191
192        return $this;
193    }
194
195    /**
196     * Get slide by index.
197     *
198     * @param int $index Slide index
199     *
200     * @throws OutOfBoundsException
201     */
202    public function getSlide(int $index = 0): Slide
203    {