DateTimeProperty   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
eloc 9
dl 0
loc 28
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A renderProperty() 0 11 2
A __construct() 0 3 1
1
<?php
2
declare(strict_types=1);
3
4
namespace MisterIcy\ExcelWriter\Properties;
5
6
use MisterIcy\ExcelWriter\Exceptions\PropertyException;
7
use MisterIcy\ExcelWriter\Properties\Traits\DateTimeTrait;
8
use PhpOffice\PhpSpreadsheet\Style\NumberFormat;
9
10
/**
11
 * Class DateTimeProperty
12
 * @package MisterIcy\ExcelWriter\Properties
13
 */
14
final class DateTimeProperty extends AbstractProperty
15
{
16
    use DateTimeTrait;
17
18
    /**
19
     * DateTimeProperty constructor.
20
     */
21
    public function __construct()
22
    {
23
        $this->formatCode = NumberFormat::FORMAT_DATE_DATETIME;
24
    }
25
26
    /**
27
     * @param object $object
28
     * @return float|mixed
29
     * @throws PropertyException
30
     */
31
    public function renderProperty(object $object)
32
    {
33
        $rendered = parent::renderProperty($object);
34
        if (!$this->isFormula) {
35
            return (
36
                $this->convertDateTimeToExcelDateTime(
37
                    $rendered
0 ignored issues
show
Bug introduced by
It seems like $rendered can also be of type string; however, parameter $object of MisterIcy\ExcelWriter\Pr...teTimeToExcelDateTime() does only seem to accept DateTimeInterface|null, maybe add an additional type check? ( Ignorable by Annotation )

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

37
                    /** @scrutinizer ignore-type */ $rendered
Loading history...
38
                )
39
            );
40
        }
41
        return $rendered;
42
    }
43
}
44