ConstraintView::toString()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 0
dl 0
loc 11
ccs 7
cts 7
cp 1
crap 2
rs 9.9
c 0
b 0
f 0
1
<?php
2
3
namespace NwLaravel\Testing;
4
5
use Illuminate\Contracts\View\View;
6
7
class ConstraintView extends \PHPUnit_Framework_Constraint
8
{
9
    /**
10
     * @var string
11
     */
12
    protected $view;
13
14
    /**
15
     * @var object
16
     */
17
    protected $response;
18
19
    /**
20
     * Construct
21
     *
22
     * @param object $response
23
     */
24 2
    public function __construct($response)
25
    {
26 2
        parent::__construct();
27 2
        $this->response = $response;
28 2
    }
29
30
    /**
31
     * Evaluates the constraint for parameter $other. Returns true if the
32
     * constraint is met, false otherwise.
33
     *
34
     * @param mixed $other Value or object to evaluate.
35
     *
36
     * @return bool
37
     */
38 2
    protected function matches($other)
39
    {
40 2
        if (! isset($this->response->original) || ! $this->response->original instanceof View) {
41 1
            return false;
42
        }
43
44 1
        $this->view = $this->response->original->name();
45
46 1
        return (bool) ($other == $this->view);
47
    }
48
49
    /**
50
     * Returns a string representation of the constraint.
51
     *
52
     * @return string
53
     */
54 2
    public function toString()
55
    {
56 2
        if (is_null($this->view)) {
57 1
            return "The response view not defined";
58
        }
59
60 1
        return sprintf(
61 1
            "The response view actual is '%s'",
62 1
            $this->view
63 1
        );
64
    }
65
}
66