HealthCheckResponseBuilder::name()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 2
c 1
b 0
f 0
dl 0
loc 5
rs 10
cc 1
nc 1
nop 1
1
<?php
2
namespace Health\Builder;
3
4
use Health\HealthCheck;
5
6
/**
7
 * Builder
8
 */
9
class HealthCheckResponseBuilder implements HealthCheckResponseBuilderInterface
10
{
11
12
    /**
13
     * Check name
14
     *
15
     * @var string
16
     */
17
    private $name = '';
18
19
    /**
20
     * Check state
21
     *
22
     * @var string
23
     */
24
    private $state = '';
25
26
    /**
27
     * Extra data
28
     *
29
     * @var array
30
     */
31
    private $data = [];
32
33
    /**
34
     * {@inheritdoc}
35
     *
36
     * @see \Health\Builder\HealthCheckResponseBuilderInterface::name()
37
     */
38
    public function name(string $name)
39
    {
40
        $this->name = $name;
41
42
        return $this;
43
    }
44
45
    /**
46
     * {@inheritdoc}
47
     *
48
     * @see \Health\Builder\HealthCheckResponseBuilderInterface::up()
49
     */
50
    public function up()
51
    {
52
        $this->state = HealthCheck::STATE_UP;
53
54
        return $this;
55
    }
56
57
    /**
58
     * {@inheritdoc}
59
     *
60
     * @see \Health\Builder\HealthCheckResponseBuilderInterface::down()
61
     */
62
    public function down()
63
    {
64
        $this->state = HealthCheck::STATE_DOWN;
65
66
        return $this;
67
    }
68
69
    /**
70
     * {@inheritdoc}
71
     *
72
     * @see \Health\Builder\HealthCheckResponseBuilderInterface::state()
73
     */
74
    public function state(bool $up)
75
    {
76
        $this->state = $up ? HealthCheck::STATE_UP : HealthCheck::STATE_DOWN;
77
78
        return $this;
79
    }
80
81
    /**
82
     * {@inheritdoc}
83
     *
84
     * @see \Health\Builder\HealthCheckResponseBuilderInterface::withData()
85
     */
86
    public function withData(string $key, $value)
87
    {
88
        $this->data[$key] = $value;
89
90
        return $this;
91
    }
92
93
    /**
94
     * {@inheritdoc}
95
     *
96
     * @see \Health\Builder\HealthCheckResponseBuilderInterface::build()
97
     */
98
    public function build()
99
    {
100
        return new HealthCheck($this->name, $this->state, $this->data);
101
    }
102
}
103