Passed
Push — master ( e8a696...8de9f1 )
by Artem
12:01
created

TimeValue::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 1
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 0
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 1
ccs 0
cts 0
cp 0
crap 2
rs 10
1
<?php
2
3
// ---------------------------------------------------------------------
4
//
5
//  Copyright (C) 2018-2024 Artem Rodygin
6
//
7
//  You should have received a copy of the MIT License along with
8
//  this file. If not, see <http://opensource.org/licenses/MIT>.
9
//
10
// ---------------------------------------------------------------------
11
12
namespace Linode\Entity;
13
14
/**
15
 * A key/value pair representing unix timestamp as a key.
16
 *
17
 * @property int   $time  Unix timestamp.
18
 * @property float $value Custom value.
19
 */
20
class TimeValue
21
{
22
    /**
23
     * TimeValue constructor.
24
     */
25
    public function __construct(protected int $time, protected float $value) {}
26
27
    /**
28
     * Checks whether the specified property exists.
29
     *
30
     * @param string $name property name
31
     */
32 1
    public function __isset(string $name): bool
33
    {
34 1
        return 'time' === $name || 'value' === $name;
35
    }
36
37
    /**
38
     * Returns current value of the specified property, or `null` if the property doesn't exist.
39
     *
40
     * @param string $name property name
41
     *
42
     * @return null|float|int
43
     */
44 7
    public function __get(string $name)
45
    {
46 7
        return match ($name) {
47 7
            'time'  => $this->time,
48 7
            'value' => $this->value,
49 7
            default => null,
50 7
        };
51
    }
52
}
53