Bind::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 0
nc 1
nop 4
dl 0
loc 6
ccs 1
cts 1
cp 1
crap 1
rs 10
c 1
b 0
f 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace MaxBeckers\AmazonAlexa\Response\Directives\APL\Document;
6
7
use MaxBeckers\AmazonAlexa\Response\Directives\APL\StandardCommand\AbstractStandardCommand;
8
9
class Bind implements \JsonSerializable
10
{
11
    /**
12
     * @param string $name Name of the binding
13
     * @param mixed $value Value to bind
14
     * @param BindType $type Type of the binding
15
     * @param AbstractStandardCommand[] $onChange Commands to run when value changes
16
     */
17 8
    public function __construct(
18
        public string $name,
19
        public mixed $value,
20
        public BindType $type = BindType::ANY,
21
        public array $onChange = [],
22
    ) {
23 8
    }
24
25 4
    public function jsonSerialize(): array
26
    {
27 4
        $data = [
28 4
            'name'  => $this->name,
29 4
            'value' => $this->value,
30 4
            'type'  => $this->type->value,
31 4
        ];
32
33 4
        if (!empty($this->onChange)) {
34 1
            $data['onChange'] = $this->onChange;
35
        }
36
37 4
        return $data;
38
    }
39
}
40