PingEndPoint   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 6
dl 0
loc 40
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A handle() 0 14 2
A dispatchEvents() 0 10 3
1
<?php
2
3
namespace Infinitypaul\LaravelUptime\Tasks;
4
5
use GuzzleHttp\Client;
6
use GuzzleHttp\Exception\RequestException;
7
use Infinitypaul\LaravelUptime\Endpoint;
8
use Infinitypaul\LaravelUptime\Events\EndpointIsBackUp;
9
use Infinitypaul\LaravelUptime\Events\EndpointIsDown;
10
use Infinitypaul\LaravelUptime\Scheduler\Task;
11
12
class PingEndPoint extends Task
13
{
14
    protected $client;
15
    /**
16
     * @var \Infinitypaul\LaravelUptime\Endpoint
17
     */
18
    protected $endpoint;
19
20
    public function __construct(Endpoint $endpoint, Client $client)
21
    {
22
        $this->client = $client;
23
        $this->endpoint = $endpoint;
24
    }
25
26
    public function handle()
27
    {
28
        try {
29
            $response = $this->client->request('GET', $this->endpoint->uri);
0 ignored issues
show
Documentation introduced by
The property uri does not exist on object<Infinitypaul\LaravelUptime\Endpoint>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
30
        } catch (RequestException $exception) {
31
            $response = $exception->getResponse();
32
        }
33
34
        $this->endpoint->statuses()->create([
35
            'status_code' => $response->getStatusCode(),
36
        ]);
37
38
        $this->dispatchEvents();
39
    }
40
41
    protected function dispatchEvents()
42
    {
43
        if ($this->endpoint->status->isDown()) {
0 ignored issues
show
Documentation introduced by
The property status does not exist on object<Infinitypaul\LaravelUptime\Endpoint>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
44
            event(new EndpointIsDown($this->endpoint));
45
        }
46
47
        if ($this->endpoint->isBackUp()) {
48
            event(new EndpointIsBackUp($this->endpoint));
49
        }
50
    }
51
}
52