Issues (18)

src/Objects/Check.php (1 issue)

Labels
Severity
1
<?php
2
/**
3
 * Copyright (c) 2019 - present
4
 * updown - Check.php
5
 * author: Roberto Belotti - [email protected]
6
 * web : robertobelotti.com, github.com/biscolab
7
 * Initial version created on: 15/2/2019
8
 * MIT license: https://github.com/biscolab/updown-php/blob/master/LICENSE
9
 */
10
11
namespace Biscolab\UpDown\Objects;
12
13
use Biscolab\UpDown\Enum\UpDownFieldType;
14
use Biscolab\UpDown\Fields\CheckFields;
15
use Biscolab\UpDown\Types\Checks;
16
use Biscolab\UpDown\Types\DownTimes;
17
use Biscolab\UpDown\Types\Metrics;
18
use Biscolab\UpDown\Types\Ssl;
19
20
/**
21
 * Class Check
22
 * @property string token
23
 * @property string url
24
 * @property int    period
25
 * @property float  apdex_t
26
 * @property bool   enabled
27
 * @property bool   published
28
 * @property string alias
29
 * @property string string_match
30
 * @property string mute_until
31
 * @property string http_verb
32
 * @property string http_body
33
 * @property array  disabled_locations
34
 * @property array  custom_headers
35
 * @property bool   down
36
 * @property int    down_since
37
 * @property int    last_status
38
 * @property string error
39
 * @property int    last_check_at
40
 * @property int    next_check_at
41
 * @property string favicon_url
42
 * @property Ssl    ssl
43
 * @package Biscolab\UpDown\Object
44
 */
45
class Check extends CrudObject
46
{
47
48
    /**
49
     * @var string
50
     */
51
    protected static $endpoint = 'checks';
52
53
    /**
54
     * @var string
55
     */
56
    protected static $collection_type = Checks::class;
57
58
    /**
59
     * @var string
60
     */
61
    protected static $key = 'token';
62
63
    /**
64
     * @var array
65
     */
66
    protected $typeCheck = [
67
        CheckFields::TOKEN              => UpDownFieldType::STRING,
68
        CheckFields::URL                => UpDownFieldType::STRING,
69
        CheckFields::URL                => UpDownFieldType::STRING,
70
        CheckFields::PERIOD             => UpDownFieldType::INT,
71
        CheckFields::APDEX_T            => UpDownFieldType::FLOAT,
72
        CheckFields::ENABLED            => UpDownFieldType::BOOL,
73
        CheckFields::PUBLISHED          => UpDownFieldType::BOOL,
74
        CheckFields::ALIAS              => UpDownFieldType::STRING,
75
        CheckFields::STRING_MATCH       => UpDownFieldType::STRING,
76
        CheckFields::MUTE_UNTIL         => UpDownFieldType::STRING,
77
        CheckFields::HTTP_VERB          => UpDownFieldType::STRING,
78
        CheckFields::HTTP_BODY          => UpDownFieldType::STRING,
79
        CheckFields::DISABLED_LOCATIONS => UpDownFieldType::ARRAY,
80
        CheckFields::CUSTOM_HEADERS     => UpDownFieldType::ARRAY,
81
        CheckFields::DOWN               => UpDownFieldType::BOOL,
82
        CheckFields::DOWN_SINCE         => UpDownFieldType::DATETIME,
83
        CheckFields::LAST_STATUS        => UpDownFieldType::INT,
84
        CheckFields::ERROR              => UpDownFieldType::STRING,
85
        CheckFields::LAST_CHECK_AT      => UpDownFieldType::DATETIME,
86
        CheckFields::NEXT_CHECK_AT      => UpDownFieldType::DATETIME,
87
        CheckFields::FAVICON_URL        => UpDownFieldType::STRING,
88
        CheckFields::SSL                => Ssl::class,
89
    ];
90
91
    /**
92
     * @param int|null    $from
93
     * @param int|null    $to
94
     * @param null|string $group
95
     *
96
     * @return Metrics
97
     */
98
    public function getMetrics(?int $from = null, ?int $to = null, ?string $group = null): Metrics
99
    {
100
101
        $path = $this->prepareApiPath() . '/metrics';
102
103
        $response = $this->updown->get($path, [
0 ignored issues
show
The method get() does not exist on null. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

103
        /** @scrutinizer ignore-call */ 
104
        $response = $this->updown->get($path, [

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
104
            'from'  => ($from) ? date(DATE_ISO8601, $from) : $from,
105
            'to'    => ($to) ? date(DATE_ISO8601, $to) : $to,
106
            'group' => $group,
107
        ]);
108
109
        return new Metrics($response->getResult()->getData());
110
    }
111
112
    /**
113
     * @param int $page
114
     *
115
     * @return DownTimes
116
     */
117
    public function getDowntimes($page = 1): DownTimes
118
    {
119
120
        $path = $this->prepareApiPath() . '/downtimes';
121
122
        $response = $this->updown->get($path, [
123
            'page' => $page
124
        ]);
125
126
        return new DownTimes($response->getResult()->getData());
127
    }
128
129
}