Status   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 77
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 14
c 1
b 0
f 0
dl 0
loc 77
rs 10
wmc 6

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getStatus() 0 3 1
A hasNoErrors() 0 3 1
A getContext() 0 3 1
A getId() 0 3 1
A __construct() 0 6 1
A getOptionalReference() 0 3 1
1
<?php
2
3
namespace Apie\StatusCheckPlugin\ApiResources;
4
5
use Apie\Core\Annotations\ApiResource;
6
use Apie\StatusCheckPlugin\DataLayers\StatusCheckRetriever;
7
8
/**
9
 * Creates a status api resource. It's best practice to have an end point to do a health check for your REST API.
10
 *
11
 * @ApiResource(
12
 *     retrieveClass=StatusCheckRetriever::class
13
 * )
14
 */
15
class Status
16
{
17
    /**
18
     * @var string
19
     */
20
    private $id;
21
22
    /**
23
     * @var string
24
     */
25
    private $status;
26
27
    /**
28
     * @var string|null
29
     */
30
    private $optionalReference;
31
32
    /**
33
     * @var array|null
34
     */
35
    private $context;
36
37
    public function __construct(string $id, string $status = 'OK', ?string $optionalReference = null, ?array $context = null)
38
    {
39
        $this->id = $id;
40
        $this->status = $status;
41
        $this->optionalReference = $optionalReference;
42
        $this->context = $context;
43
    }
44
45
    /**
46
     * @return string
47
     */
48
    public function getId(): string
49
    {
50
        return $this->id;
51
    }
52
53
    /**
54
     * Returns some status string. The string 'OK' assumes no error was there.
55
     *
56
     * @return string
57
     */
58
    public function getStatus(): string
59
    {
60
        return $this->status;
61
    }
62
63
    /**
64
     * Return some reference to some arbitrary URL. Useful to link people to a maintenance page with information
65
     * how long it takes before it's operational again.
66
     *
67
     * @return string|null
68
     */
69
    public function getOptionalReference(): ?string
70
    {
71
        return $this->optionalReference;
72
    }
73
74
    /**
75
     * Returns an array with arbitrary data. Can be anything....
76
     *
77
     * @return array|null
78
     */
79
    public function getContext(): ?array
80
    {
81
        return $this->context;
82
    }
83
84
    /**
85
     * Returns true to tell the status check is 'healthy'.
86
     *
87
     * @return bool
88
     */
89
    public function hasNoErrors(): bool
90
    {
91
        return $this->status === 'OK';
92
    }
93
}
94