Passed
Push — master ( c45116...86df6f )
by Iman
06:48
created

HttpClient   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Test Coverage

Coverage 83.33%

Importance

Changes 0
Metric Value
wmc 5
eloc 20
dl 0
loc 49
ccs 15
cts 18
cp 0.8333
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A whenEventHappens() 0 5 1
A exceptionIsThrown() 0 3 1
A __construct() 0 3 1
A __call() 0 3 1
A sendRequest() 0 5 1
1
<?php
2
3
namespace Imanghafoori\HeyMan\MakeSure;
4
5
class HttpClient
6
{
7
    private $chain;
8
9
    private $methods = [
10
        'sendingPostRequest' => 'post',
11
        'sendingJsonPostRequest' => 'postJson',
12
        'sendingDeleteRequest' => 'delete',
13
        'sendingJsonDeleteRequest' => 'deleteJson',
14
        'sendingPutRequest' => 'put',
15
        'sendingJsonPutRequest' => 'putJson',
16 38
        'sendingPatchRequest' => 'patch',
17
        'sendingJsonPatchRequest' => 'patchJson',
18 38
        'sendingGetRequest' => 'get',
19 38
        'sendingJsonGetRequest' => 'getJson',
20
    ];
21 3
22
    /**
23 3
     * HttpClient constructor.
24
     *
25 3
     * @param $phpunit
26
     */
27
    public function __construct($phpunit)
28 1
    {
29
        $this->chain = new Chain($phpunit);
30 1
    }
31
32 1
    public function __call($method, $params)
33
    {
34
        return $this->sendRequest($method, ...$params);
35 2
    }
36
37 2
    public function sendRequest($method, ...$data): IsRespondedWith
38
    {
39 2
        $this->chain->http($this->methods[$method], ...$data);
40
41
        return new IsRespondedWith($this->chain);
42
    }
43
44
    public function exceptionIsThrown($type)
45
    {
46
        $this->chain->data['exception'] = $type;
47
    }
48
49 1
    public function whenEventHappens($event)
50
    {
51 1
        $this->chain->data['event'] = $event;
52
53 1
        return $this;
54
    }
55
}