Passed
Pull Request — master (#14)
by Carlos C
02:25
created

ScalarValues::__construct()   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 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace PhpCfdi\SatCatalogos\Helpers;
6
7
/** @internal */
8
final class ScalarValues
9
{
10
    /** @var array<string, scalar> */
11
    private $data;
12
13
    /** @param array<string, scalar> $data */
14 139
    public function __construct(array $data)
15
    {
16 139
        $this->data = $data;
17
    }
18
19
    /** @return scalar|null */
20 139
    public function get(string $key)
21
    {
22 139
        return $this->data[$key] ?? null;
23
    }
24
25 139
    public function string(string $key): string
26
    {
27 139
        return (string) $this->get($key);
28
    }
29
30 112
    public function timestamp(string $key): int
31
    {
32 112
        $value = $this->string($key);
33 112
        if ('' === $value) {
34 95
            return 0;
35
        }
36 112
        return strtotime($value) ?: 0;
37
    }
38
39 24
    public function bool(string $key): bool
40
    {
41 24
        return (bool) $this->get($key);
42
    }
43
44 12
    public function int(string $key): int
45
    {
46 12
        return (int) $this->get($key);
47
    }
48
}
49