Completed
Push — master ( 4d12bd...38508b )
by Nils
05:01
created

RegExExistsRule::doValidation()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 7
rs 9.4285
cc 2
eloc 4
nc 2
nop 1
1
<?php
2
3
namespace whm\Smoke\Rules\Html;
4
5
use whm\Smoke\Http\Response;
6
use whm\Smoke\Rules\StandardRule;
7
8
/**
9
 * This rule will analyze any html document and checks if a given string is contained.
10
 */
11
class RegExExistsRule extends StandardRule
12
{
13
    private $regExs;
14
15
    protected $contentTypes = array('text/html');
16
17
    /**
18
     * @param int $string The string that the document must contain
0 ignored issues
show
Bug introduced by
There is no parameter named $string. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
19
     */
20
    public function init(array $regExs)
21
    {
22
        $this->regExs = $regExs;
23
    }
24
25
    protected function doValidation(Response $response)
26
    {
27
        foreach ($this->regExs as $regEx) {
28
            $this->assert(preg_match('^' . $regEx . '^', (string)$response->getBody()) > 0,
29
                'The given regular expression (' . $regEx . ') was not found in this document.');
30
        }
31
    }
32
}
33