CheckExpectations   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 92.86%

Importance

Changes 0
Metric Value
wmc 11
lcom 1
cbo 1
dl 0
loc 68
ccs 26
cts 28
cp 0.9286
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A check() 0 6 1
A checkResponse() 0 7 2
A sendRequest() 0 4 1
A checkResponses() 0 6 2
A fireEvents() 0 6 2
A expectExceptions() 0 6 2
1
<?php
2
3
namespace Imanghafoori\MakeSure;
4
5
class CheckExpectations
6
{
7
    private $chain;
8
9
    private $phpunit;
10
11
    /**
12
     * CheckExpectations constructor.
13
     *
14
     * @param $chain
15
     * @param $phpunit
16
     */
17 14
    public function __construct(Chain $chain, $phpunit)
18
    {
19 14
        $this->chain = $chain;
20 14
        $this->phpunit = $phpunit;
21 14
    }
22
23 14
    public function check()
24
    {
25 14
        $this->expectExceptions();
26 14
        $this->fireEvents();
27 14
        $this->checkResponse();
28 14
    }
29
30 14
    private function checkResponse()
31
    {
32 14
        if (isset($this->chain->data['http'])) {
33 11
            $response = $this->sendRequest(...$this->chain->data['http']);
0 ignored issues
show
Bug introduced by
The call to sendRequest() misses a required argument $data.

This check looks for function calls that miss required arguments.

Loading history...
34 11
            $this->checkResponses($response);
35
        }
36 14
    }
37
38
    /**
39
     * @param $method
40
     * @param $data
41
     *
42
     * @return mixed
43
     */
44 11
    private function sendRequest($method, $data)
45
    {
46 11
        return $this->phpunit->$method(...$data);
47
    }
48
49
    /**
50
     * @param $response
51
     */
52 11
    private function checkResponses($response)
53
    {
54 11
        foreach ($this->chain->data['assertion'] ?? [] as [$type, $value]) {
55 3
            $response->$type($value);
0 ignored issues
show
Bug introduced by
The variable $type does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
Bug introduced by
The variable $value does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
56
        }
57 11
    }
58
59 14
    private function fireEvents()
60
    {
61 14
        if (isset($this->chain->data['event'])) {
62
            event($this->chain->data['event']);
63
        }
64 14
    }
65
66 14
    private function expectExceptions()
67
    {
68 14
        if (isset($this->chain->data['exception'])) {
69
            $this->phpunit->expectException($this->chain->data['exception']);
70
        }
71 14
    }
72
}
73