Passed
Pull Request — master (#32)
by Baptiste
05:02
created

PhpMatcher::response_content_should_match()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 17
Code Lines 10

Duplication

Lines 17
Ratio 100 %

Importance

Changes 0
Metric Value
dl 17
loc 17
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 10
nc 2
nop 1
1
<?php
2
namespace Behapi\Context;
3
4
use Behat\Behat\Context\Context;
5
use Behat\Gherkin\Node\PyStringNode;
6
7
use Coduo\PHPMatcher\Factory\SimpleFactory;
8
9
use Behapi\Tools\HttpHistory;
10
11
class PhpMatcher implements Context
12
{
13
    use ApiTrait;
14
15
    /** @var Factory */
16
    private $factory;
17
18
    public function __construct(HttpHistory $history)
19
    {
20
        $this->history = $history;
21
22
        $this->factory = new SimpleFactory;
0 ignored issues
show
Documentation Bug introduced by
It seems like new \Coduo\PHPMatcher\Factory\SimpleFactory() of type object<Coduo\PHPMatcher\Factory\SimpleFactory> is incompatible with the declared type object<Behapi\Context\Factory> of property $factory.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
23
    }
24
25
    /** @Then the response content should match :pattern */
26 View Code Duplication
    public function response_content_should_match(string $pattern)
1 ignored issue
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
27
    {
28
        $matcher = $this->factory->createMatcher();
29
        $content = (string) $this->getResponse()->getBody();
30
31
        if ($matcher->match($content, $pattern)) {
32
            return;
33
        }
34
35
        throw new InvalidArgumentException(
36
            sprintf(
37
                'The response does not match with the pattern "%s" (error : %s)',
38
                $pattern,
39
                $matcher->getError()
40
            )
41
        );
42
    }
43
44
    /** @Then the response content should not match :pattern */
45 View Code Duplication
    public function response_content_should_not_match(string $pattern)
1 ignored issue
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
46
    {
47
        $matcher = $this->factory->createMatcher();
48
        $content = (string) $this->getResponse()->getBody();
49
50
        if (!$matcher->match($content, $pattern)) {
51
            return;
52
        }
53
54
        throw new InvalidArgumentException(
55
            sprintf(
56
                'The response matches with the pattern "%s" (error : %s)',
57
                $pattern,
58
                $matcher->getError()
59
            )
60
        );
61
    }
62
63
    /** @Then the response content should match: */
64 View Code Duplication
    public function response_content_should_match_PyString(PyStringNode $pattern)
1 ignored issue
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
65
    {
66
        $matcher = $this->factory->createMatcher();
67
        $content = (string) $this->getResponse()->getBody();
68
69
        if ($matcher->match($content, $pattern)) {
70
            return;
71
        }
72
73
        throw new InvalidArgumentException($matcher->getError());
74
    }
75
76
    /** @Then the response content should match: */
77 View Code Duplication
    public function response_content_should_not_match_PyString(PyStringNode $pattern)
1 ignored issue
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
78
    {
79
        $matcher = $this->factory->createMatcher();
80
        $content = (string) $this->getResponse()->getBody();
81
82
        if (!$matcher->match($content, $pattern)) {
83
            return;
84
        }
85
86
        throw new InvalidArgumentException($matcher->getError());
87
    }
88
}
89