Code Duplication    Length = 9-19 lines in 2 locations

src/Rules/Cookies/CountRule.php 1 location

@@ 29-47 (lines=19) @@
26
27
    public function validate(ResponseInterface $response)
28
    {
29
        if ($response instanceof CookieAwareResponse) {
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

src/Rules/Html/ResourcesCountRule.php 1 location

@@ 30-38 (lines=9) @@
27
    {
28
        if ($response instanceof ResourcesAwareResponse) {
29
            $resourceCount = count($response->getResources());
30
            if ($resourceCount > $this->maxElements) {
31
                $message = 'Too many resources were loaded. ' . $resourceCount . ' resources loaded, maximum was ' . $this->maxElements . '.';
32
                $result = new CheckResult(CheckResult::STATUS_FAILURE, $message, $resourceCount);
33
                $result->addAttribute(new Attribute('resources', $response->getResources(), true));
34
                return $result;
35
            } else {
36
                $message = $resourceCount . ' resources were loaded.';
37
                return new CheckResult(CheckResult::STATUS_SUCCESS, $message, $resourceCount);
38
            }
39
        } else {
40
            throw new \RuntimeException('Unable to analyze resources count. Please use another response retriever.');
41
        }