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

PingTask::getMethod()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 1
c 1
b 0
f 1
dl 0
loc 3
rs 10
cc 1
nc 1
nop 0
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