Completed
Push — master ( f86f76...036c01 )
by Nils
02:33
created

CountRule::validate()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 22
Code Lines 15

Duplication

Lines 19
Ratio 86.36 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 19
loc 22
rs 9.2
cc 3
eloc 15
nc 3
nop 1
1
<?php
2
3
namespace whm\Smoke\Rules\Cookies;
4
5
use phm\HttpWebdriverClient\Http\Response\CookieAwareResponse;
6
use Psr\Http\Message\ResponseInterface;
7
use whm\Smoke\Rules\Attribute;
8
use whm\Smoke\Rules\CheckResult;
9
use whm\Smoke\Rules\Rule;
10
11
/**
12
 * This rule can validate if a http request takes longer than a given max duration.
13
 * A website that is slower than one second is considered as slow.
14
 */
15
class CountRule implements Rule
16
{
17
    private $maxCookies;
18
19
    /**
20
     * @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...
21
     */
22
    public function init($maxCookies = 20)
23
    {
24
        $this->maxCookies = $maxCookies;
25
    }
26
27
    public function validate(ResponseInterface $response)
28
    {
29 View Code Duplication
        if ($response instanceof CookieAwareResponse) {
0 ignored issues
show
Bug introduced by
The class phm\HttpWebdriverClient\...nse\CookieAwareResponse does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
Duplication introduced by
This code seems to be duplicated across 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...
30
            $cookieCount = $response->getCookieCount();
31
32
            if ($cookieCount > $this->maxCookies) {
33
                $result = new CheckResult(
34
                    CheckResult::STATUS_FAILURE,
35
                    $cookieCount . 'cookies were stored (limit was ' . $this->maxCookies . ').',
36
                    $cookieCount);
37
            } else {
38
                $result = new CheckResult(
39
                    CheckResult::STATUS_SUCCESS,
40
                    $cookieCount . ' cookies were stored (limit was ' . $this->maxCookies . ').',
41
                    $cookieCount);
42
            }
43
44
            $result->addAttribute(new Attribute(' cookies', $response->getCookies(), true));
45
46
            return $result;
47
        }
48
    }
49
}
50