CountRule   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 3
dl 0
loc 48
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A init() 0 4 1
A validate() 0 35 5
1
<?php
2
3
namespace whm\Smoke\Rules\Cookies;
4
5
use phm\HttpWebdriverClient\Http\Response\CookieAwareResponse;
6
use phm\HttpWebdriverClient\Http\Response\TimeoutAwareResponse;
7
use Psr\Http\Message\ResponseInterface;
8
use whm\Smoke\Rules\Attribute;
9
use whm\Smoke\Rules\CheckResult;
10
use whm\Smoke\Rules\Rule;
11
12
/**
13
 * This rule can validate if a http request takes longer than a given max duration.
14
 * A website that is slower than one second is considered as slow.
15
 */
16
class CountRule implements Rule
17
{
18
    private $maxCookies;
19
20
    /**
21
     * @param int $maxDuration The maximum duration a http call is allowed to take (time to first byte)
0 ignored issues
show
Bug introduced by
There is no parameter named $maxDuration. 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...
22
     */
23
    public function init($maxElements = 20)
24
    {
25
        $this->maxCookies = $maxElements;
26
    }
27
28
    public function validate(ResponseInterface $response)
29
    {
30
        if ($response instanceof CookieAwareResponse) {
31
32
            if (!$response instanceof TimeoutAwareResponse || !$response->isTimeout()) {
33
34
                $cookieCount = $response->getCookieCount();
35
36
                if ($cookieCount > $this->maxCookies) {
37
                    $result = new CheckResult(
38
                        CheckResult::STATUS_FAILURE,
39
                        $cookieCount . ' cookies were stored (limit was ' . $this->maxCookies . ').',
40
                        $cookieCount);
41
                } else {
42
                    $result = new CheckResult(
43
                        CheckResult::STATUS_SUCCESS,
44
                        $cookieCount . ' cookies were stored (limit was ' . $this->maxCookies . ').',
45
                        $cookieCount);
46
                }
47
48
                $cookies = $response->getCookies();
49
50
                $result->addAttribute(new Attribute('cookies', json_encode($cookies), true));
51
52
                return $result;
53
            } else {
54
                $result = new CheckResult(
55
                    CheckResult::STATUS_SKIPPED,
56
                    'Skipped: Request timed out. Cannot read cookies.',
57
                    0);
58
59
                return $result;
60
            }
61
        }
62
    }
63
}
64