Passed
Push — master ( 76636e...a7cce5 )
by Kevin
03:12
created

PingExtension::getOptions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
namespace Zenstruck\ScheduleBundle\Schedule\Extension;
4
5
use Zenstruck\ScheduleBundle\Schedule;
6
use Zenstruck\ScheduleBundle\Schedule\HasMissingDependencyMessage;
7
use Zenstruck\ScheduleBundle\Schedule\Task;
8
9
/**
10
 * @author Kevin Bond <[email protected]>
11
 */
12
final class PingExtension implements HasMissingDependencyMessage
13
{
14
    private $hook;
15
    private $url;
16
    private $method;
17
    private $options;
18
19
    /**
20
     * @param array $options See HttpClientInterface::OPTIONS_DEFAULTS
21
     */
22 5
    private function __construct(string $hook, string $url, string $method = 'GET', array $options = [])
23
    {
24 5
        $this->hook = $hook;
25 5
        $this->url = $url;
26 5
        $this->method = $method;
27 5
        $this->options = $options;
28 5
    }
29
30 2
    public function __toString(): string
31
    {
32 2
        return "{$this->hook}, ping \"{$this->url}\"";
33
    }
34
35 2
    public function getHook(): string
36
    {
37 2
        return $this->hook;
38
    }
39
40 2
    public function getUrl(): string
41
    {
42 2
        return $this->url;
43
    }
44
45 2
    public function getMethod(): string
46
    {
47 2
        return $this->method;
48
    }
49
50 2
    public function getOptions(): array
51
    {
52 2
        return $this->options;
53
    }
54
55 2
    public static function getMissingDependencyMessage(): string
56
    {
57 2
        return 'Symfony HttpClient is required to use the ping extension. Install with "composer require symfony/http-client".';
58
    }
59
60 3
    public static function taskBefore(string $url, string $method = 'GET', array $options = []): self
61
    {
62 3
        return new self(Task::BEFORE, $url, $method, $options);
63
    }
64
65 3
    public static function taskAfter(string $url, string $method = 'GET', array $options = []): self
66
    {
67 3
        return new self(Task::AFTER, $url, $method, $options);
68
    }
69
70 3
    public static function taskSuccess(string $url, string $method = 'GET', array $options = []): self
71
    {
72 3
        return new self(Task::SUCCESS, $url, $method, $options);
73
    }
74
75 5
    public static function taskFailure(string $url, string $method = 'GET', array $options = []): self
76
    {
77 5
        return new self(Task::FAILURE, $url, $method, $options);
78
    }
79
80 2
    public static function scheduleBefore(string $url, string $method = 'GET', array $options = []): self
81
    {
82 2
        return new self(Schedule::BEFORE, $url, $method, $options);
83
    }
84
85 2
    public static function scheduleAfter(string $url, string $method = 'GET', array $options = []): self
86
    {
87 2
        return new self(Schedule::AFTER, $url, $method, $options);
88
    }
89
90 2
    public static function scheduleSuccess(string $url, string $method = 'GET', array $options = []): self
91
    {
92 2
        return new self(Schedule::SUCCESS, $url, $method, $options);
93
    }
94
95 2
    public static function scheduleFailure(string $url, string $method = 'GET', array $options = []): self
96
    {
97 2
        return new self(Schedule::FAILURE, $url, $method, $options);
98
    }
99
}
100