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

PingExtension   A

Complexity

Total Complexity 15

Size/Duplication

Total Lines 86
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 15
eloc 23
c 1
b 0
f 0
dl 0
loc 86
ccs 34
cts 34
cp 1
rs 10

15 Methods

Rating   Name   Duplication   Size   Complexity  
A taskBefore() 0 3 1
A taskSuccess() 0 3 1
A getHook() 0 3 1
A getMethod() 0 3 1
A scheduleBefore() 0 3 1
A taskAfter() 0 3 1
A taskFailure() 0 3 1
A __toString() 0 3 1
A getOptions() 0 3 1
A getMissingDependencyMessage() 0 3 1
A scheduleAfter() 0 3 1
A scheduleFailure() 0 3 1
A getUrl() 0 3 1
A __construct() 0 6 1
A scheduleSuccess() 0 3 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