Completed
Push — master ( 24bfb3...287957 )
by Iman
10:04
created

HttpClient   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 96
Duplicated Lines 0 %

Test Coverage

Coverage 47.73%

Importance

Changes 0
Metric Value
wmc 11
eloc 30
dl 0
loc 96
ccs 21
cts 44
cp 0.4773
rs 10
c 0
b 0
f 0

11 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A whenEventHappens() 0 5 1
A whenYouReachCheckPoint() 0 3 1
A sendingDeleteRequest() 0 5 1
A exceptionIsThrown() 0 3 1
A __destruct() 0 3 1
A sendingPostRequest() 0 5 1
A sendingPutRequest() 0 5 1
A sendingPatchRequest() 0 5 1
A http() 0 7 1
A sendingGetRequest() 0 9 1
1
<?php
2
3
namespace Imanghafoori\HeyMan\MakeSure;
4
5
class HttpClient
6
{
7
    public $http = [];
8
9
    public $assertion;
10
11
    public $app;
12
13
    public $event;
14
15
    public $exception;
16
17
    /**
18
     * HttpClient constructor.
19
     *
20
     * @param $app
21
     */
22 27
    public function __construct($app)
23
    {
24 27
        $this->app = $app;
25 27
    }
26
27 2
    public function sendingPostRequest($uri, array $data = [], array $headers = []): IsRespondedWith
28
    {
29 2
        $this->http($uri, $data, $headers, 'post');
30 2
31 2
        return new IsRespondedWith($this);
32 2
    }
33 2
34
    public function sendingDeleteRequest($uri, array $data = [], array $headers = [])
35
    {
36 2
        $this->http($uri, $data, $headers, 'delete');
37
38
        return new IsRespondedWith($this);
39
    }
40
41
    public function sendingPutRequest($uri, array $data = [], array $headers = [])
42
    {
43
        $this->http($uri, $data, $headers, 'put');
44
45
        return new IsRespondedWith($this);
46
    }
47
48
    public function sendingPatchRequest($uri, array $data = [], array $headers = [])
49
    {
50
        $this->http($uri, $data, $headers, 'patch');
51
52
        return new IsRespondedWith($this);
53
    }
54
55
    public function sendingGetRequest($url): IsRespondedWith
56
    {
57
        $this->http = [
58
            'method' => 'get',
59
            'url'    => $url,
60
            'data'   => [],
61
        ];
62
63
        return new IsRespondedWith($this);
64
    }
65
66
    public function exceptionIsThrown($type)
67
    {
68
        $this->exception = $type;
69
    }
70
71
    public function whenEventHappens($event)
72
    {
73
        $this->event = $event;
74
75 24
        return $this;
76
    }
77 24
78 24
    public function whenYouReachCheckPoint($name)
79 24
    {
80
        return $this->whenEventHappens('heyman_checkpoint_'.$name);
81
    }
82
83 24
    public function __destruct()
84
    {
85
        (new CheckExpectations($this))->check();
86 1
    }
87
88 1
    /**
89 1
     * @param $uri
90
     * @param array $data
91 1
     * @param array $headers
92
     * @param $str
93 1
     */
94
    private function http($uri, array $data, array $headers, $str)
95 1
    {
96
        $this->http = [
97
            'method' => $str,
98
            'url' => $uri,
99
            'data' => $data,
100
            'headers' => $headers,
101
        ];
102
    }
103
}
104