Completed
Branch master (1f9106)
by Nils
03:23
created

SizeRule   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 20
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
c 1
b 0
f 0
lcom 1
cbo 2
dl 20
loc 20
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A doValidation() 5 5 1
A init() 4 4 1

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
3
namespace whm\Smoke\Rules\Html;
4
5
use whm\Smoke\Http\Response;
6
use whm\Smoke\Rules\StandardRule;
7
8
/**
9
 * This rule calculates the size of a html document. If the document is bigger than a given value
10
 * the test will fail.
11
 */
12 View Code Duplication
class SizeRule extends StandardRule
13
{
14
    private $maxSize;
15
16
    protected $contentTypes = array('text/html');
17
18
    /**
19
     * @param int $maxSize The maximum size of a html file in kilobytes.
20
     */
21
    public function init($maxSize = 200)
22
    {
23
        $this->maxSize = $maxSize;
24
    }
25
26
    protected function doValidation(Response $response)
27
    {
28
        $size = strlen($response->getBody()) / 1000;
29
        $this->assert($size <= $this->maxSize, 'The size of this html file is too big (' . $size . ' KB)');
30
    }
31
}
32