Passed
Pull Request — master (#8)
by Kevin
15:42
created

PingTask   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Importance

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

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getMethod() 0 3 1
A getOptions() 0 3 1
A __construct() 0 7 1
A getContext() 0 6 1
A getMissingDependencyMessage() 0 3 1
A getUrl() 0 3 1
1
<?php
2
3
namespace Zenstruck\ScheduleBundle\Schedule\Task;
4
5
use Zenstruck\ScheduleBundle\Schedule\HasMissingDependencyMessage;
6
use Zenstruck\ScheduleBundle\Schedule\Task;
7
8
/**
9
 * @author Kevin Bond <[email protected]>
10
 */
11
final class PingTask extends Task implements HasMissingDependencyMessage
12
{
13
    private $url;
14
    private $method;
15
    private $options;
16
17
    /**
18
     * @param array $options See HttpClientInterface::OPTIONS_DEFAULTS
19
     */
20
    public function __construct(string $url, string $method = 'GET', array $options = [])
21
    {
22
        $this->url = $url;
23
        $this->method = $method;
24
        $this->options = $options;
25
26
        parent::__construct("Ping {$url}");
27
    }
28
29
    public function getContext(): array
30
    {
31
        return [
32
            'Url' => $this->url,
33
            'Method' => $this->method,
34
            'Options' => \json_encode($this->options),
35
        ];
36
    }
37
38
    public function getUrl(): string
39
    {
40
        return $this->url;
41
    }
42
43
    public function getMethod(): string
44
    {
45
        return $this->method;
46
    }
47
48
    public function getOptions(): array
49
    {
50
        return $this->options;
51
    }
52
53
    public static function getMissingDependencyMessage(): string
54
    {
55
        return \sprintf('Symfony HttpClient is required to use "%s". Install with "composer require symfony/http-client".', self::class);
56
    }
57
}
58