Test Failed
Push — develop ( 90366f...812a46 )
by Adrien
28:16
created

Properties::setCompany()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 5
ccs 3
cts 3
cp 1
crap 1
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace PhpOffice\PhpSpreadsheet\Document;
4
5
class Properties
6
{
7
    /** constants */
8
    const PROPERTY_TYPE_BOOLEAN = 'b';
9
    const PROPERTY_TYPE_INTEGER = 'i';
10
    const PROPERTY_TYPE_FLOAT = 'f';
11
    const PROPERTY_TYPE_DATE = 'd';
12
    const PROPERTY_TYPE_STRING = 's';
13
    const PROPERTY_TYPE_UNKNOWN = 'u';
14
15
    /**
16
     * Creator.
17
     *
18
     * @var string
19
     */
20
    private $creator = 'Unknown Creator';
21
22
    /**
23
     * LastModifiedBy.
24
     *
25
     * @var string
26
     */
27
    private $lastModifiedBy;
28
29
    /**
30
     * Created.
31
     *
32
     * @var int
33
     */
34
    private $created;
35
36
    /**
37
     * Modified.
38
     *
39
     * @var int
40
     */
41
    private $modified;
42
43
    /**
44
     * Title.
45
     *
46
     * @var string
47
     */
48
    private $title = 'Untitled Spreadsheet';
49
50
    /**
51
     * Description.
52
     *
53
     * @var string
54
     */
55
    private $description = '';
56
57
    /**
58
     * Subject.
59
     *
60
     * @var string
61
     */
62
    private $subject = '';
63
64
    /**
65
     * Keywords.
66
     *
67
     * @var string
68
     */
69
    private $keywords = '';
70
71
    /**
72
     * Category.
73
     *
74
     * @var string
75
     */
76
    private $category = '';
77
78
    /**
79
     * Manager.
80
     *
81
     * @var string
82
     */
83
    private $manager = '';
84
85
    /**
86
     * Company.
87
     *
88
     * @var string
89
     */
90
    private $company = 'Microsoft Corporation';
91
92
    /**
93
     * Custom Properties.
94
     *
95
     * @var string
96
     */
97
    private $customProperties = [];
98
99
    /**
100
     * Create a new Document Properties instance.
101
     */
102 137
    public function __construct()
103
    {
104
        // Initialise values
105 137
        $this->lastModifiedBy = $this->creator;
106 137
        $this->created = time();
107 137
        $this->modified = time();
108 137
    }
109
110
    /**
111
     * Get Creator.
112
     *
113
     * @return string
114
     */
115 63
    public function getCreator()
116
    {
117 63
        return $this->creator;
118
    }
119
120
    /**
121
     * Set Creator.
122
     *
123
     * @param string $creator
124
     *
125
     * @return Properties
126
     */
127 65
    public function setCreator($creator)
128
    {
129 65
        $this->creator = $creator;
130
131 65
        return $this;
132
    }
133
134
    /**
135
     * Get Last Modified By.
136
     *
137
     * @return string
138
     */
139 59
    public function getLastModifiedBy()
140
    {
141 59
        return $this->lastModifiedBy;
142
    }
143
144
    /**
145
     * Set Last Modified By.
146
     *
147
     * @param string $pValue
148
     *
149
     * @return Properties
150
     */
151 61
    public function setLastModifiedBy($pValue)
152
    {
153 61
        $this->lastModifiedBy = $pValue;
154
155 61
        return $this;
156
    }
157
158
    /**
159
     * Get Created.
160
     *
161
     * @return int
162
     */
163 59
    public function getCreated()
164
    {
165 59
        return $this->created;
166
    }
167
168
    /**
169
     * Set Created.
170
     *
171
     * @param datetime $pValue
0 ignored issues
show
Bug introduced by
The type PhpOffice\PhpSpreadsheet\Document\datetime was not found. Did you mean datetime? If so, make sure to prefix the type with \.
Loading history...
172
     *
173
     * @return Properties
174
     */
175 37 View Code Duplication
    public function setCreated($pValue)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
176
    {
177 37
        if ($pValue === null) {
178
            $pValue = time();
179 37
        } elseif (is_string($pValue)) {
180
            if (is_numeric($pValue)) {
181
                $pValue = (int) $pValue;
182
            } else {
183
                $pValue = strtotime($pValue);
184
            }
185
        }
186
187 37
        $this->created = $pValue;
0 ignored issues
show
Documentation Bug introduced by
It seems like $pValue of type PhpOffice\PhpSpreadsheet\Document\datetime is incompatible with the declared type integer of property $created.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
188
189 37
        return $this;
190
    }
191
192
    /**
193
     * Get Modified.
194
     *
195
     * @return int
196
     */
197 59
    public function getModified()
198
    {
199 59
        return $this->modified;
200
    }
201
202
    /**
203
     * Set Modified.
204
     *
205
     * @param datetime $pValue
206
     *
207
     * @return Properties
208
     */
209 37 View Code Duplication
    public function setModified($pValue)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
210
    {
211 37
        if ($pValue === null) {
212
            $pValue = time();
213 37
        } elseif (is_string($pValue)) {
214
            if (is_numeric($pValue)) {
215
                $pValue = (int) $pValue;
216
            } else {
217
                $pValue = strtotime($pValue);
218
            }
219
        }
220
221 37
        $this->modified = $pValue;
0 ignored issues
show
Documentation Bug introduced by
It seems like $pValue of type PhpOffice\PhpSpreadsheet\Document\datetime is incompatible with the declared type integer of property $modified.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
222
223 37
        return $this;
224
    }
225
226
    /**
227
     * Get Title.
228
     *
229
     * @return string
230
     */
231 63
    public function getTitle()
232
    {
233 63
        return $this->title;
234
    }
235
236
    /**
237
     * Set Title.
238
     *
239
     * @param string $title
240
     *
241
     * @return Properties
242
     */
243 53
    public function setTitle($title)
244
    {
245 53
        $this->title = $title;
246
247 53
        return $this;
248
    }
249
250
    /**
251
     * Get Description.
252
     *
253
     * @return string
254
     */
255 63
    public function getDescription()
256
    {
257 63
        return $this->description;
258
    }
259
260
    /**
261
     * Set Description.
262
     *
263
     * @param string $description
264
     *
265
     * @return Properties
266
     */
267 53
    public function setDescription($description)
268
    {
269 53
        $this->description = $description;
270
271 53
        return $this;
272
    }
273
274
    /**
275
     * Get Subject.
276
     *
277
     * @return string
278
     */
279 63
    public function getSubject()
280
    {
281 63
        return $this->subject;
282
    }
283
284
    /**
285
     * Set Subject.
286
     *
287
     * @param string $subject
288
     *
289
     * @return Properties
290
     */
291 53
    public function setSubject($subject)
292
    {
293 53
        $this->subject = $subject;
294
295 53
        return $this;
296
    }
297
298
    /**
299
     * Get Keywords.
300
     *
301
     * @return string
302
     */
303 63
    public function getKeywords()
304
    {
305 63
        return $this->keywords;
306
    }
307
308
    /**
309
     * Set Keywords.
310
     *
311
     * @param string $keywords
312
     *
313
     * @return Properties
314
     */
315 53
    public function setKeywords($keywords)
316
    {
317 53
        $this->keywords = $keywords;
318
319 53
        return $this;
320
    }
321
322
    /**
323
     * Get Category.
324
     *
325
     * @return string
326
     */
327 63
    public function getCategory()
328
    {
329 63
        return $this->category;
330
    }
331
332
    /**
333
     * Set Category.
334
     *
335
     * @param string $category
336
     *
337
     * @return Properties
338
     */
339 48
    public function setCategory($category)
340
    {
341 48
        $this->category = $category;
342
343 48
        return $this;
344
    }
345
346
    /**
347
     * Get Company.
348
     *
349
     * @return string
350
     */
351 62
    public function getCompany()
352
    {
353 62
        return $this->company;
354
    }
355
356
    /**
357
     * Set Company.
358
     *
359
     * @param string $company
360
     *
361
     * @return Properties
362
     */
363 24
    public function setCompany($company)
364
    {
365 24
        $this->company = $company;
366
367 24
        return $this;
368
    }
369
370
    /**
371
     * Get Manager.
372
     *
373
     * @return string
374
     */
375 62
    public function getManager()
376
    {
377 62
        return $this->manager;
378
    }
379
380
    /**
381
     * Set Manager.
382
     *
383
     * @param string $manager
384
     *
385
     * @return Properties
386
     */
387 10
    public function setManager($manager)
388
    {
389 10
        $this->manager = $manager;
390
391 10
        return $this;
392
    }
393
394
    /**
395
     * Get a List of Custom Property Names.
396
     *
397
     * @return array of string
398
     */
399 59
    public function getCustomProperties()
400
    {
401 59
        return array_keys($this->customProperties);
0 ignored issues
show
Bug introduced by
$this->customProperties of type string is incompatible with the type array expected by parameter $input of array_keys(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

401
        return array_keys(/** @scrutinizer ignore-type */ $this->customProperties);
Loading history...
402
    }
403
404
    /**
405
     * Check if a Custom Property is defined.
406
     *
407
     * @param string $propertyName
408
     *
409
     * @return bool
410
     */
411
    public function isCustomPropertySet($propertyName)
412
    {
413
        return isset($this->customProperties[$propertyName]);
414
    }
415
416
    /**
417
     * Get a Custom Property Value.
418
     *
419
     * @param string $propertyName
420
     *
421
     * @return string
422
     */
423 3
    public function getCustomPropertyValue($propertyName)
424
    {
425 3
        if (isset($this->customProperties[$propertyName])) {
426 3
            return $this->customProperties[$propertyName]['value'];
427
        }
428
    }
429
430
    /**
431
     * Get a Custom Property Type.
432
     *
433
     * @param string $propertyName
434
     *
435
     * @return string
436
     */
437 3
    public function getCustomPropertyType($propertyName)
438
    {
439 3
        if (isset($this->customProperties[$propertyName])) {
440 3
            return $this->customProperties[$propertyName]['type'];
441
        }
442
    }
443
444
    /**
445
     * Set a Custom Property.
446
     *
447
     * @param string $propertyName
448
     * @param mixed $propertyValue
449
     * @param string $propertyType
450
     *      'i'    : Integer
451
     *   'f' : Floating Point
452
     *   's' : String
453
     *   'd' : Date/Time
454
     *   'b' : Boolean
455
     *
456
     * @return Properties
457
     */
458 8
    public function setCustomProperty($propertyName, $propertyValue = '', $propertyType = null)
459
    {
460 8
        if (($propertyType === null) || (!in_array($propertyType, [self::PROPERTY_TYPE_INTEGER,
461 8
                                                                        self::PROPERTY_TYPE_FLOAT,
462 8
                                                                        self::PROPERTY_TYPE_STRING,
463 8
                                                                        self::PROPERTY_TYPE_DATE,
464 8
                                                                        self::PROPERTY_TYPE_BOOLEAN, ]))) {
465
            if ($propertyValue === null) {
466
                $propertyType = self::PROPERTY_TYPE_STRING;
467
            } elseif (is_float($propertyValue)) {
468
                $propertyType = self::PROPERTY_TYPE_FLOAT;
469
            } elseif (is_int($propertyValue)) {
470
                $propertyType = self::PROPERTY_TYPE_INTEGER;
471
            } elseif (is_bool($propertyValue)) {
472
                $propertyType = self::PROPERTY_TYPE_BOOLEAN;
473
            } else {
474
                $propertyType = self::PROPERTY_TYPE_STRING;
475
            }
476
        }
477
478 8
        $this->customProperties[$propertyName] = [
479 8
            'value' => $propertyValue,
480 8
            'type' => $propertyType,
481
        ];
482
483 8
        return $this;
484
    }
485
486
    /**
487
     * Implement PHP __clone to create a deep clone, not just a shallow copy.
488
     */
489 View Code Duplication
    public function __clone()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
490
    {
491
        $vars = get_object_vars($this);
492
        foreach ($vars as $key => $value) {
493
            if (is_object($value)) {
494
                $this->$key = clone $value;
495
            } else {
496
                $this->$key = $value;
497
            }
498
        }
499
    }
500
501 3
    public static function convertProperty($propertyValue, $propertyType)
502
    {
503
        switch ($propertyType) {
504 3
            case 'empty':     //    Empty
505
                return '';
506
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
507 3
            case 'null':      //    Null
508
                return null;
509
                break;
510 3
            case 'i1':        //    1-Byte Signed Integer
511 3
            case 'i2':        //    2-Byte Signed Integer
512 3
            case 'i4':        //    4-Byte Signed Integer
513 3
            case 'i8':        //    8-Byte Signed Integer
514 3
            case 'int':       //    Integer
515 2
                return (int) $propertyValue;
516
                break;
517 3
            case 'ui1':       //    1-Byte Unsigned Integer
518 3
            case 'ui2':       //    2-Byte Unsigned Integer
519 3
            case 'ui4':       //    4-Byte Unsigned Integer
520 3
            case 'ui8':       //    8-Byte Unsigned Integer
521 3
            case 'uint':      //    Unsigned Integer
522
                return abs((int) $propertyValue);
523
                break;
524 3
            case 'r4':        //    4-Byte Real Number
525 3
            case 'r8':        //    8-Byte Real Number
526 3
            case 'decimal':   //    Decimal
527 3
                return (float) $propertyValue;
528
                break;
529 3
            case 'lpstr':     //    LPSTR
530 3
            case 'lpwstr':    //    LPWSTR
531 3
            case 'bstr':      //    Basic String
532 3
                return $propertyValue;
533
                break;
534 3
            case 'date':      //    Date and Time
535 3
            case 'filetime':  //    File Time
536 3
                return strtotime($propertyValue);
537
                break;
538 3
            case 'bool':     //    Boolean
539 3
                return ($propertyValue == 'true') ? true : false;
540
                break;
541
            case 'cy':       //    Currency
542
            case 'error':    //    Error Status Code
543
            case 'vector':   //    Vector
544
            case 'array':    //    Array
545
            case 'blob':     //    Binary Blob
546
            case 'oblob':    //    Binary Blob Object
547
            case 'stream':   //    Binary Stream
548
            case 'ostream':  //    Binary Stream Object
549
            case 'storage':  //    Binary Storage
550
            case 'ostorage': //    Binary Storage Object
551
            case 'vstream':  //    Binary Versioned Stream
552
            case 'clsid':    //    Class ID
553
            case 'cf':       //    Clipboard Data
554
                return $propertyValue;
555
                break;
556
        }
557
558
        return $propertyValue;
559
    }
560
561 3
    public static function convertPropertyType($propertyType)
562
    {
563
        switch ($propertyType) {
564 3
            case 'i1':       //    1-Byte Signed Integer
565 3
            case 'i2':       //    2-Byte Signed Integer
566 3
            case 'i4':       //    4-Byte Signed Integer
567 3
            case 'i8':       //    8-Byte Signed Integer
568 3
            case 'int':      //    Integer
569 3
            case 'ui1':      //    1-Byte Unsigned Integer
570 3
            case 'ui2':      //    2-Byte Unsigned Integer
571 3
            case 'ui4':      //    4-Byte Unsigned Integer
572 3
            case 'ui8':      //    8-Byte Unsigned Integer
573 3
            case 'uint':     //    Unsigned Integer
574 2
                return self::PROPERTY_TYPE_INTEGER;
575
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
576 3
            case 'r4':       //    4-Byte Real Number
577 3
            case 'r8':       //    8-Byte Real Number
578 3
            case 'decimal':  //    Decimal
579 3
                return self::PROPERTY_TYPE_FLOAT;
580
                break;
581 3
            case 'empty':    //    Empty
582 3
            case 'null':     //    Null
583 3
            case 'lpstr':    //    LPSTR
584 3
            case 'lpwstr':   //    LPWSTR
585 3
            case 'bstr':     //    Basic String
586 3
                return self::PROPERTY_TYPE_STRING;
587
                break;
588 3
            case 'date':     //    Date and Time
589 3
            case 'filetime': //    File Time
590 3
                return self::PROPERTY_TYPE_DATE;
591
                break;
592 3
            case 'bool':     //    Boolean
593 3
                return self::PROPERTY_TYPE_BOOLEAN;
594
                break;
595
            case 'cy':       //    Currency
596
            case 'error':    //    Error Status Code
597
            case 'vector':   //    Vector
598
            case 'array':    //    Array
599
            case 'blob':     //    Binary Blob
600
            case 'oblob':    //    Binary Blob Object
601
            case 'stream':   //    Binary Stream
602
            case 'ostream':  //    Binary Stream Object
603
            case 'storage':  //    Binary Storage
604
            case 'ostorage': //    Binary Storage Object
605
            case 'vstream':  //    Binary Versioned Stream
606
            case 'clsid':    //    Class ID
607
            case 'cf':       //    Clipboard Data
608
                return self::PROPERTY_TYPE_UNKNOWN;
609
                break;
610
        }
611
612
        return self::PROPERTY_TYPE_UNKNOWN;
613
    }
614
}
615