GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( db632b...7eca44 )
by Freek
02:13
created

SiteCollection::checkUptime()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 23
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 13
nc 1
nop 0
dl 0
loc 23
rs 9.0856
c 0
b 0
f 0
1
<?php
2
3
namespace Spatie\UptimeMonitor;
4
5
use Generator;
6
use GuzzleHttp\Client;
7
use GuzzleHttp\Exception\RequestException;
8
use GuzzleHttp\Promise\EachPromise;
9
use Illuminate\Support\Collection;
10
use Psr\Http\Message\ResponseInterface;
11
12
class SiteCollection extends Collection
13
{
14
    public function checkUptime()
15
    {
16
        $this->resetItemKeys();
17
18
        (new EachPromise($this->getPromises(), [
19
            'concurrency' => config('laravel-uptime-monitor.concurrent_uptime_checks'),
20
            'fulfilled' => function (ResponseInterface $response, $index) {
21
                $site = $this->items[$index];
22
23
                uptimeMonitorConsoleOutput()->info("Could reach {$site->url}");
0 ignored issues
show
Documentation Bug introduced by
The method info does not exist on object<Spatie\UptimeMoni...\Helpers\ConsoleOutput>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
24
25
                $site->pingSucceeded($response->getBody());
26
            },
27
28
            'rejected' => function (RequestException $exception, $index) {
29
                $site = $this->items[$index];
30
31
                uptimeMonitorConsoleOutput()->error("Could not reach {$site->url} error: `{$exception->getMessage()}`");
0 ignored issues
show
Documentation Bug introduced by
The method error does not exist on object<Spatie\UptimeMoni...\Helpers\ConsoleOutput>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
32
33
                $site->pingFailed($exception->getMessage());
34
            },
35
        ]))->promise()->wait();
36
    }
37
38
    protected function getPromises() : Generator
39
    {
40
        $client = new Client([
41
            'headers' => [
42
                'User-Agent' => 'spatie/laravel-uptime-monitor uptime checker',
43
            ],
44
        ]);
45
46
        foreach ($this->items as $site) {
47
            uptimeMonitorConsoleOutput()->info("checking {$site->url}");
0 ignored issues
show
Documentation Bug introduced by
The method info does not exist on object<Spatie\UptimeMoni...\Helpers\ConsoleOutput>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
48
49
            $promise = $client->requestAsync(
50
                $site->uptime_check_method,
51
                $site->url,
52
                ['connect_timeout' => 10]
53
            );
54
55
            yield $promise;
56
        }
57
    }
58
59
    /**
60
     * Make sure the keys are in consecutive order without gaps.
61
     */
62
    protected function resetItemKeys()
63
    {
64
        $this->items = $this->values()->all();
65
    }
66
}
67