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

PhpMatcher   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 78
Duplicated Lines 71.79 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 3
dl 56
loc 78
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A response_content_should_match() 17 17 2
A response_content_should_not_match() 17 17 2
A response_content_should_match_PyString() 11 11 2
A response_content_should_not_match_PyString() 11 11 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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