Code Coverage
 
Classes and Traits
Functions and Methods
Lines
Total
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
26 / 26
CRAP
100.00% covered (success)
100.00%
70 / 70
DocumentProperties
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
26 / 26
34
100.00% covered (success)
100.00%
70 / 70
 __construct
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
11 / 11
 getCreator
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 setCreator
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
2 / 2
 getLastModifiedBy
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 setLastModifiedBy
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
2 / 2
 getCreated
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 setCreated
100.00% covered (success)
100.00%
1 / 1
2
100.00% covered (success)
100.00%
4 / 4
 getModified
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 setModified
100.00% covered (success)
100.00%
1 / 1
2
100.00% covered (success)
100.00%
4 / 4
 getTitle
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 setTitle
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
2 / 2
 getDescription
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 setDescription
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
2 / 2
 getSubject
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 setSubject
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
2 / 2
 getKeywords
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 setKeywords
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
2 / 2
 getCategory
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 setCategory
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
2 / 2
 getCompany
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 setCompany
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
2 / 2
 getCustomProperties
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 isCustomPropertySet
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 getCustomPropertyValue
100.00% covered (success)
100.00%
1 / 1
2
100.00% covered (success)
100.00%
3 / 3
 getCustomPropertyType
100.00% covered (success)
100.00%
1 / 1
2
100.00% covered (success)
100.00%
3 / 3
 setCustomProperty
100.00% covered (success)
100.00%
1 / 1
5
100.00% covered (success)
100.00%
17 / 17
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
23/**
24 * \PhpOffice\PhpPresentation\DocumentProperties.
25 */
26class DocumentProperties
27{
28    public const PROPERTY_TYPE_BOOLEAN = 'b';
29    public const PROPERTY_TYPE_INTEGER = 'i';
30    public const PROPERTY_TYPE_FLOAT = 'f';
31    public const PROPERTY_TYPE_DATE = 'd';
32    public const PROPERTY_TYPE_STRING = 's';
33    public const PROPERTY_TYPE_UNKNOWN = 'u';
34
35    /**
36     * Creator.
37     *
38     * @var string
39     */
40    private $creator;
41
42    /**
43     * LastModifiedBy.
44     *
45     * @var string
46     */
47    private $lastModifiedBy;
48
49    /**
50     * Created.
51     *
52     * @var int
53     */
54    private $created;
55
56    /**
57     * Modified.
58     *
59     * @var int
60     */
61    private $modified;
62
63    /**
64     * Title.
65     *
66     * @var string
67     */
68    private $title;
69
70    /**
71     * Description.
72     *
73     * @var string
74     */
75    private $description;
76
77    /**
78     * Subject.
79     *
80     * @var string
81     */
82    private $subject;
83
84    /**
85     * Keywords.
86     *
87     * @var string
88     */
89    private $keywords;
90
91    /**
92     * Category.
93     *
94     * @var string
95     */
96    private $category;
97
98    /**
99     * Company.
100     *
101     * @var string
102     */
103    private $company;
104
105    /**
106     * Custom Properties.
107     *
108     * @var array<string, array<string, mixed>>
109     */
110    private $customProperties = [];
111
112    /**
113     * Create a new \PhpOffice\PhpPresentation\DocumentProperties
114     */
115    public function __construct()
116    {
117        // Initialise values
118        $this->creator = 'Unknown Creator';
119        $this->lastModifiedBy = $this->creator;
120        $this->created = time();
121        $this->modified = time();
122        $this->title = 'Untitled Presentation';
123        $this->subject = '';
124        $this->description = '';
125        $this->keywords = '';
126        $this->category = '';
127        $this->company = 'Microsoft Corporation';
128    }
129
130    /**
131     * Get Creator.
132     *
133     * @return string
134     */
135    public function getCreator()
136    {
137        return $this->creator;
138    }
139
140    /**
141     * Set Creator.
142     *
143     * @param string $pValue
144     *
145     * @return \PhpOffice\PhpPresentation\DocumentProperties
146     */
147    public function setCreator($pValue = '')
148    {
149        $this->creator = $pValue;
150
151        return $this;
152    }
153
154    /**
155     * Get Last Modified By.
156     *
157     * @return string
158     */
159    public function getLastModifiedBy()
160    {
161        return $this->lastModifiedBy;
162    }
163
164    /**
165     * Set Last Modified By.
166     *
167     * @param string $pValue
168     *
169     * @return \PhpOffice\PhpPresentation\DocumentProperties
170     */
171    public function setLastModifiedBy($pValue = '')
172    {
173        $this->lastModifiedBy = $pValue;
174
175        return $this;
176    }
177
178    /**
179     * Get Created.
180     *
181     * @return int
182     */
183    public function getCreated()
184    {
185        return $this->created;
186    }
187
188    /**
189     * Set Created.
190     *
191     * @param int $pValue
192     *
193     * @return \PhpOffice\PhpPresentation\DocumentProperties
194     */
195    public function setCreated($pValue = null)
196    {
197        if (is_null($pValue)) {
198            $pValue = time();
199        }
200        $this->created = $pValue;
201
202        return $this;
203    }
204
205    /**
206     * Get Modified.
207     *
208     * @return int
209     */
210    public function getModified()
211    {
212        return $this->modified;
213    }
214
215    /**
216     * Set Modified.
217     *
218     * @param int $pValue
219     *
220     * @return \PhpOffice\PhpPresentation\DocumentProperties
221     */
222    public function setModified($pValue = null)
223    {
224        if (is_null($pValue)) {
225            $pValue = time();
226        }
227        $this->modified = $pValue;
228
229        return $this;
230    }
231
232    /**
233     * Get Title.
234     *
235     * @return string
236     */
237    public function getTitle()
238    {
239        return $this->title;
240    }
241
242    /**
243     * Set Title.
244     *
245     * @param string $pValue
246     *
247     * @return \PhpOffice\PhpPresentation\DocumentProperties
248     */
249    public function setTitle($pValue = '')
250    {
251        $this->title = $pValue;
252
253        return $this;
254    }
255
256    /**
257     * Get Description.
258     *
259     * @return string
260     */
261    public function getDescription()
262    {
263        return $this->description;
264    }
265
266    /**
267     * Set Description.
268     *
269     * @param string $pValue
270     *
271     * @return \PhpOffice\PhpPresentation\DocumentProperties
272     */
273    public function setDescription($pValue = '')
274    {
275        $this->description = $pValue;
276
277        return $this;
278    }
279
280    /**
281     * Get Subject.
282     *
283     * @return string
284     */
285    public function getSubject()
286    {
287        return $this->subject;
288    }
289
290    /**
291     * Set Subject.
292     *
293     * @param string $pValue
294     *
295     * @return \PhpOffice\PhpPresentation\DocumentProperties
296     */
297    public function setSubject($pValue = '')
298    {
299        $this->subject = $pValue;
300
301        return $this;
302    }
303
304    /**
305     * Get Keywords.
306     *
307     * @return string
308     */
309    public function getKeywords()
310    {
311        return $this->keywords;
312    }
313
314    /**
315     * Set Keywords.
316     *
317     * @param string $pValue
318     *
319     * @return \PhpOffice\PhpPresentation\DocumentProperties
320     */
321    public function setKeywords($pValue = '')
322    {
323        $this->keywords = $pValue;
324
325        return $this;
326    }
327
328    /**
329     * Get Category.
330     *
331     * @return string
332     */
333    public function getCategory()
334    {
335        return $this->category;
336    }
337
338    /**
339     * Set Category.
340     *
341     * @param string $pValue
342     *
343     * @return \PhpOffice\PhpPresentation\DocumentProperties
344     */
345    public function setCategory($pValue = '')
346    {
347        $this->category = $pValue;
348
349        return $this;
350    }
351
352    /**
353     * Get Company.
354     *
355     * @return string
356     */
357    public function getCompany()
358    {
359        return $this->company;
360    }
361
362    /**
363     * Set Company.
364     *
365     * @param string $pValue
366     *
367     * @return \PhpOffice\PhpPresentation\DocumentProperties
368     */
369    public function setCompany($pValue = '')
370    {
371        $this->company = $pValue;
372
373        return $this;
374    }
375
376    /**
377     * Get a List of Custom Property Names.
378     *
379     * @return array<int, string>
380     */
381    public function getCustomProperties(): array
382    {
383        return array_keys($this->customProperties);
384    }
385
386    /**
387     * Check if a Custom Property is defined.
388     *
389     * @param string $propertyName
390     *
391     * @return bool
392     */
393    public function isCustomPropertySet(string $propertyName): bool
394    {
395        return isset($this->customProperties[$propertyName]);
396    }
397
398    /**
399     * Get a Custom Property Value.
400     *
401     * @param string $propertyName
402     *
403     * @return mixed|null
404     */
405    public function getCustomPropertyValue(string $propertyName)
406    {
407        if ($this->isCustomPropertySet($propertyName)) {
408            return $this->customProperties[$propertyName]['value'];
409        }
410
411        return null;
412    }
413
414    /**
415     * Get a Custom Property Type.
416     *
417     * @param string $propertyName
418     *
419     * @return string|null
420     */
421    public function getCustomPropertyType(string $propertyName): ?string
422    {
423        if ($this->isCustomPropertySet($propertyName)) {
424            return $this->customProperties[$propertyName]['type'];
425        }
426
427        return null;
428    }
429
430    /**
431     * Set a Custom Property.
432     *
433     * @param string $propertyName
434     * @param mixed $propertyValue
435     * @param string|null $propertyType
436     *                                  'i' : Integer
437     *                                  'f' : Floating Point
438     *                                  's' : String
439     *                                  'd' : Date/Time
440     *                                  'b' : Boolean
441     *
442     * @return self
443     */
444    public function setCustomProperty(string $propertyName, $propertyValue = '', ?string $propertyType = null): self
445    {
446        if (!in_array($propertyType, [