Failed Conditions
Pull Request — master (#1694)
by Adrien
08:05
created

Size::__toString()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
ccs 2
cts 2
cp 1
crap 1
1
<?php
2
3
namespace PhpOffice\PhpSpreadsheet\Helper;
4
5
class Size
6
{
7
    const REGEXP_SIZE_VALIDATION = '/^(?P<size>\d*\.?\d+)(?P<unit>pt|px|em)?$/i';
8
9
    /**
10
     * @var bool
11
     */
12
    protected $valid;
13
14
    /**
15
     * @var string
16
     */
17
    protected $size = '';
18
19
    /**
20
     * @var string
21
     */
22
    protected $unit = '';
23
24 29
    public function __construct(string $size)
25
    {
26 29
        $this->valid = (bool) preg_match(self::REGEXP_SIZE_VALIDATION, $size, $matches);
27 29
        if ($this->valid) {
28 28
            $this->size = $matches['size'];
29 28
            $this->unit = $matches['unit'] ?? 'pt';
30
        }
31 29
    }
32
33 29
    public function valid(): bool
34
    {
35 29
        return $this->valid;
36
    }
37
38
    public function size(): string
39
    {
40
        return $this->size;
41
    }
42
43
    public function unit(): string
44
    {
45
        return $this->unit;
46
    }
47
48 28
    public function __toString()
49
    {
50 28
        return $this->size . $this->unit;
51
    }
52
}
53