Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
98.80% covered (success)
98.80%
165 / 167
93.33% covered (success)
93.33%
28 / 30
CRAP
0.00% covered (danger)
0.00%
0 / 1
DocumentProperties
98.80% covered (success)
98.80%
165 / 167
93.33% covered (success)
93.33%
28 / 30
115
0.00% covered (danger)
0.00%
0 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getCreator
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setCreator
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getLastModifiedBy
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setLastModifiedBy
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getCreated
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setCreated
90.00% covered (success)
90.00%
9 / 10
0.00% covered (danger)
0.00%
0 / 1
5.03
 getModified
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setModified
90.00% covered (success)
90.00%
9 / 10
0.00% covered (danger)
0.00%
0 / 1
5.03
 getTitle
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setTitle
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getDescription
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setDescription
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getSubject
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setSubject
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getKeywords
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setKeywords
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getCategory
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setCategory
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getCompany
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setCompany
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getManager
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setManager
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getCustomProperties
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 isCustomPropertySet
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getCustomPropertyValue
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
2
 getCustomPropertyType
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
2
 setCustomProperty
100.00% covered (success)
100.00%
10 / 10
100.00% covered (success)
100.00%
1 / 1
6
 convertProperty
100.00% covered (success)
100.00%
51 / 51
100.00% covered (success)
100.00%
1 / 1
36
 convertPropertyType
100.00% covered (success)
100.00%
48 / 48
100.00% covered (success)
100.00%
1 / 1
36
1<?php
2
3/**
4 * This file is part of PHPProject - A pure PHP library for reading and writing
5 * presentations documents.
6 *
7 * PHPProject is free software distributed under the terms of the GNU Lesser
8 * General Public License version 3 as published by the Free Software Foundation.
9 *
10 * For the full copyright and license information, please read the LICENSE
11 * file that was distributed with this source code. For the full list of
12 * contributors, visit https: // github.com/PHPOffice/PHPWord/contributors.
13 *
14 * @link        https: // github.com/PHPOffice/PHPProject
15 * @copyright   2009-2014 PHPProject contributors
16 * @license     http: // www.gnu.org/licenses/lgpl.txt LGPL version 3
17 */
18
19declare(strict_types=1);
20
21namespace PhpOffice\PhpProject;
22
23/**
24 * PHPProject_DocumentProperties
25 *
26 * @category    PHPProject
27 * @package        PHPProject
28 * @copyright    Copyright (c) 2012 - 2012 PHPProject (https: // github.com/PHPOffice/PHPProject)
29 */
30class DocumentProperties
31{
32    /** constants */
33    const PROPERTY_TYPE_BOOLEAN        = 'b';
34    const PROPERTY_TYPE_INTEGER        = 'i';
35    const PROPERTY_TYPE_FLOAT        = 'f';
36    const PROPERTY_TYPE_DATE        = 'd';
37    const PROPERTY_TYPE_STRING        = 's';
38    const PROPERTY_TYPE_UNKNOWN        = 'u';
39
40
41    /**
42     * Creator
43     *
44     * @var    string
45     */
46    private $creator    = '';
47
48    /**
49     * LastModifiedBy
50     *
51     * @var    string
52     */
53    private $lastModifiedBy;
54
55    /**
56     * Created
57     *
58     * @var int
59     */
60    private $created;
61
62    /**
63     * Modified
64     *
65     * @var    int
66     */
67    private $modified;
68
69    /**
70     * Title
71     *
72     * @var    string
73     */
74    private $title    = '';
75
76    /**
77     * Description
78     *
79     * @var    string
80     */
81    private $description    = '';
82
83    /**
84     * Subject
85     *
86     * @var    string
87     */
88    private $subject        = '';
89
90    /**
91     * Keywords
92     *
93     * @var    string
94     */
95    private $keywords        = '';
96
97    /**
98     * Category
99     *
100     * @var    string
101     */
102    private $category        = '';
103
104    /**
105     * Manager
106     *
107     * @var    string
108     */
109    private $manager        = '';
110
111    /**
112     * Company
113     *
114     * @var    string
115     */
116    private $company        = '';
117
118    /**
119     * Custom Properties
120     *
121     * @var array<string, array{value: mixed, type: string}>
122     */
123    private $customProperties    = array();
124
125
126    /**
127     * Create a new PHPProject_DocumentProperties
128     */
129    public function __construct()
130    {
131        // Initialise values
132        $this->lastModifiedBy    = $this->creator;
133    }
134
135    /**
136     * Get Creator
137     *
138     * @return    string
139     */
140    public function getCreator(): string
141    {
142        return $this->creator;
143    }
144
145    /**
146     * Set Creator
147     *
148     * @param    string    $pValue
149     * @return    self
150     */
151    public function setCreator(string $pValue = ''): self
152    {
153        $this->creator = $pValue;
154        return $this;
155    }
156
157    /**
158     * Get Last Modified By
159     *
160     * @return    string
161     */
162    public function getLastModifiedBy(): string
163    {
164        return $this->lastModifiedBy;
165    }
166
167    /**
168     * Set Last Modified By
169     *
170     * @param    string    $pValue
171     * @return    self
172     */
173    public function setLastModifiedBy(string $pValue = ''): self
174    {
175        $this->lastModifiedBy = $pValue;
176        return $this;
177    }
178
179    /**
180     * Get Created
181     *
182     * @return    int
183     */
184    public function getCreated(): ?int
185    {
186        return $this->created;
187    }
188
189    /**
190     * Set Created
191     *
192     * @param int|string|null $pValue
193     * @return    self
194     */
195    public function setCreated($pValue = null): self
196    {
197        if ($pValue === null) {
198            $pValue = time();
199        } elseif (is_string($pValue)) {
200            if (is_numeric($pValue)) {
201                $pValue = intval($pValue);
202            } else {
203                $pValue = strtotime($pValue);
204                if ($pValue === false) {
205                    $pValue = null;
206                }
207            }
208        }
209
210        $this->created = $pValue;
211        return $this;
212    }
213
214    /**
215     * Get Modified
216     *
217     * @return    int
218     */
219    public function getModified(): ?int
220    {
221        return $this->modified;
222    }
223
224    /**
225     * Set Modified
226     *
227     * @param int|string|null $pValue
228     * @return    self
229     */
230    public function setModified($pValue = null): self
231    {
232        if ($pValue === null) {
233            $pValue = time();
234        } elseif (is_string($pValue)) {
235            if (is_numeric($pValue)) {
236                $pValue = intval($pValue);
237            } else {
238                $pValue = strtotime($pValue);
239                if ($pValue === false) {
240                    $pValue = null;
241                }
242            }
243        }
244
245        $this->modified = $pValue;
246        return $this;
247    }
248
249    /**
250     * Get Title
251     *
252     * @return    string
253     */
254    public function getTitle(): string
255    {
256        return $this->title;
257    }
258
259    /**
260     * Set Title
261     *
262     * @param    string    $pValue
263     * @return    self
264     */
265    public function setTitle(string $pValue = ''): self
266    {
267        $this->title = $pValue;
268        return $this;
269    }
270
271    /**
272     * Get Description
273     *
274     * @return    string
275     */
276    public function getDescription(): string
277    {
278        return $this->description;
279    }
280
281    /**
282     * Set Description
283     *
284     * @param    string    $pValue
285     * @return    self
286     */
287    public function setDescription(string $pValue = ''): self
288    {
289        $this->description = $pValue;
290        return $this;
291    }
292
293    /**
294     * Get Subject
295     *
296     * @return    string
297     */
298    public function getSubject(): string
299    {
300        return $this->subject;
301    }
302
303    /**
304     * Set Subject
305     *
306     * @param    string    $pValue
307     * @return    self
308     */
309    public function setSubject(string $pValue = ''): self
310    {
311        $this->subject = $pValue;
312        return $this;
313    }
314
315    /**
316     * Get Keywords
317     *
318     * @return    string
319     */
320    public function getKeywords(): string
321    {
322        return $this->keywords;
323    }
324
325    /**
326     * Set Keywords
327     *
328     * @param    string    $pValue
329     * @return    self
330     */
331    public function setKeywords(string $pValue = ''): self
332    {
333        $this->keywords = $pValue;
334        return $this;
335    }
336
337    /**
338     * Get Category
339     *
340     * @return    string
341     */
342    public function getCategory(): string
343    {
344        return $this->category;
345    }
346
347    /**
348     * Set Category
349     *
350     * @param    string    $pValue
351     * @return    self
352     */
353    public function setCategory(string $pValue = ''): self
354    {
355        $this->category = $pValue;
356        return $this;
357    }
358
359    /**
360     * Get Company
361     *
362     * @return    string
363     */
364    public function getCompany(): string
365    {
366        return $this->company;
367    }
368
369    /**
370     * Set Company
371     *
372     * @param    string    $pValue
373     * @return    self
374     */
375    public function setCompany(string $pValue = ''): self
376    {
377        $this->company = $pValue;
378        return $this;
379    }
380
381    /**
382     * Get Manager
383     *
384     * @return    string
385     */
386    public function getManager(): string
387    {
388        return $this->manager;
389    }
390
391    /**
392     * Set Manager
393     *
394     * @param    string    $pValue
395     * @return    self
396     */
397    public function setManager(string $pValue = ''): self
398    {
399        $this->manager = $pValue;
400        return $this;
401    }
402
403    /**
404     * Get a List of Custom Property Names
405     *
406     * @return string[]
407     */
408    public function getCustomProperties(): array
409    {
410        return array_keys($this->customProperties);
411    }
412
413    /**
414     * Check if a Custom Property is defined
415     *
416     * @param    string    $propertyName
417     * @return    boolean
418     */
419    public function isCustomPropertySet(string $propertyName): bool
420    {
421        return isset($this->customProperties[$propertyName]);
422    }
423
424    /**
425     * Get a Custom Property Value
426     *
427     * @param    string    $propertyName
428     * @return    string|null
429     */
430    public function getCustomPropertyValue(string $propertyName)
431    {
432        if (isset($this->customProperties[$propertyName])) {
433            return $this->customProperties[$propertyName]['value'];
434        }
435        return null;
436    }
437
438    /**
439     * Get a Custom Property Type
440     *
441     * @param    string    $propertyName
442     * @return    string|null
443     */
444    public function getCustomPropertyType(string $propertyName): ?string
445    {
446        if (isset($this->customProperties[$propertyName])) {
447            return $this->customProperties[$propertyName]['type'];
448        }
449        return null;
450    }
451
452    /**
453     * Set a Custom Property
454     *
455     * @param    string    $propertyName
456     * @param    mixed    $propertyValue
457     * @param    string    $propertyType
458     *                        'i': Integer
459     *                        'f': Floating Point
460     *                        's': String
461     *                        'd': Date/Time
462     *                        'b': Boolean
463     * @return    self
464     */
465    public function setCustomProperty(string $propertyName, $propertyValue = '', ?string $propertyType = null): self
466    {
467        if (($propertyType === null) || (!in_array($propertyType, array(self::PROPERTY_TYPE_INTEGER, self::PROPERTY_TYPE_FLOAT, self::PROPERTY_TYPE_STRING, self::PROPERTY_TYPE_DATE, self::PROPERTY_TYPE_BOOLEAN)))) {
468            if (is_float($propertyValue)) {
469                $propertyType = self::PROPERTY_TYPE_FLOAT;
470            } elseif (is_int($propertyValue)) {
471                $propertyType = self::PROPERTY_TYPE_INTEGER;
472            } elseif (is_bool($propertyValue)) {
473                $propertyType = self::PROPERTY_TYPE_BOOLEAN;
474            } else {
475                $propertyType = self::PROPERTY_TYPE_STRING;
476            }
477        }
478
479        $this->customProperties[$propertyName] = array('value' => $propertyValue, 'type' => $propertyType);
480        return $this;
481    }
482
483    public static function convertProperty(string $propertyValue, string $propertyType)
484    {
485        switch ($propertyType) {
486            case 'empty': // Empty
487                $propertyValue = '';
488                break;
489            case 'null': // Null
490                $propertyValue = null;
491                break;
492            case 'i1': // 1-Byte Signed Integer
493            case 'i2': // 2-Byte Signed Integer
494            case 'i4': // 4-Byte Signed Integer
495            case 'i8': // 8-Byte Signed Integer
496            case 'int': // Integer
497                $propertyValue = (int) $propertyValue;
498                break;
499            case 'ui1': // 1-Byte Unsigned Integer
500            case 'ui2': // 2-Byte Unsigned Integer
501            case 'ui4': // 4-Byte Unsigned Integer
502            case 'ui8': // 8-Byte Unsigned Integer
503            case 'uint': // Unsigned Integer
504                $propertyValue = abs((int) $propertyValue);
505                break;
506            case 'r4': // 4-Byte Real Number
507            case 'r8': // 8-Byte Real Number
508            case 'decimal': // Decimal
509                $propertyValue = (float) $propertyValue;
510                break;
511            case 'lpstr': // LPSTR
512            case 'lpwstr': // LPWSTR
513            case 'bstr': // Basic String
514                break;
515            case 'date': // Date and Time
516            case 'filetime': // File Time
517                $propertyValue = strtotime($propertyValue);
518                break;
519            case 'bool': // Boolean
520                $propertyValue = ($propertyValue == 'true') ? true: false;
521                break;
522            case 'cy': // Currency
523            case 'error': // Error Status Code
524            case 'vector': // Vector
525            case 'array': // Array
526            case 'blob': // Binary Blob
527            case 'oblob': // Binary Blob Object
528            case 'stream': // Binary Stream
529            case 'ostream': // Binary Stream Object
530            case 'storage': // Binary Storage
531            case 'ostorage': // Binary Storage Object
532            case 'vstream': // Binary Versioned Stream
533            case 'clsid': // Class ID
534            case 'cf': // Clipboard Data
535                break;
536        }
537        return $propertyValue;
538    }
539
540    public static function convertPropertyType(string $propertyType): string
541    {
542        switch ($propertyType) {
543            case 'i1': // 1-Byte Signed Integer
544            case 'i2': // 2-Byte Signed Integer
545            case 'i4': // 4-Byte Signed Integer
546            case 'i8': // 8-Byte Signed Integer
547            case 'int': // Integer
548            case 'ui1': // 1-Byte Unsigned Integer
549            case 'ui2': // 2-Byte Unsigned Integer
550            case 'ui4': // 4-Byte Unsigned Integer
551            case 'ui8': // 8-Byte Unsigned Integer
552            case 'uint': // Unsigned Integer
553                $propertyType = self::PROPERTY_TYPE_INTEGER;
554                break;
555            case 'r4': // 4-Byte Real Number
556            case 'r8': // 8-Byte Real Number
557            case 'decimal': // Decimal
558                $propertyType = self::PROPERTY_TYPE_FLOAT;
559                break;
560            case 'empty': // Empty
561            case 'null': // Null
562            case 'lpstr': // LPSTR
563            case 'lpwstr': // LPWSTR
564            case 'bstr': // Basic String
565                $propertyType = self::PROPERTY_TYPE_STRING;
566                break;
567            case 'date': // Date and Time
568            case 'filetime': // File Time
569                $propertyType = self::PROPERTY_TYPE_DATE;
570                break;
571            case 'bool': // Boolean
572                $propertyType = self::PROPERTY_TYPE_BOOLEAN;
573                break;
574            case 'cy': // Currency
575            case 'error': // Error Status Code
576            case 'vector': // Vector
577            case 'array': // Array
578            case 'blob': // Binary Blob
579            case 'oblob': // Binary Blob Object
580            case 'stream': // Binary Stream
581            case 'ostream': // Binary Stream Object
582            case 'storage': // Binary Storage
583            case 'ostorage': // Binary Storage Object
584            case 'vstream': // Binary Versioned Stream
585            case 'clsid': // Class ID
586            case 'cf': // Clipboard Data
587                $propertyType = self::PROPERTY_TYPE_UNKNOWN;
588                break;
589            default:
590                $propertyType = self::PROPERTY_TYPE_UNKNOWN;
591        }
592        return $propertyType;
593    }
594}