Test Failed
Push — master ( 04af89...50255e )
by Jonathan
03:54
created

Page   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 64
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
c 0
b 0
f 0
lcom 0
cbo 3
dl 64
loc 64
ccs 14
cts 14
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B isValid() 25 25 3

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
/**
4
 * ReportingCloud PHP Wrapper
5
 *
6
 * PHP wrapper for ReportingCloud Web API. Authored and supported by Text Control GmbH.
7
 *
8
 * @link      http://www.reporting.cloud to learn more about ReportingCloud
9
 * @link      https://github.com/TextControl/txtextcontrol-reportingcloud-php for the canonical source repository
10
 * @license   https://raw.githubusercontent.com/TextControl/txtextcontrol-reportingcloud-php/master/LICENSE.md
11
 * @copyright © 2017 Text Control GmbH
12
 */
13
14
namespace TxTextControl\ReportingCloud\Validator;
15
16
use TxTextControl\ReportingCloud\Validator\TypeInteger as TypeIntegerValidator;
17
use Zend\Validator\GreaterThan as GreaterThanValidator;
18
19
/**
20
 * Page validator
21
 *
22
 * @package TxTextControl\ReportingCloud
23
 * @author  Jonathan Maron (@JonathanMaron)
24
 */
25 View Code Duplication
class Page extends AbstractValidator
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in 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...
26
{
27
    /**
28
     * Minimum page number
29
     *
30
     * @const MIN
31
     */
32
    const MIN = 1;
33
    /**
34
     * Invalid type
35
     *
36
     * @const INVALID_TYPE
37
     */
38
    const INVALID_TYPE = 'invalidType';
39
    /**
40
     * Invalid page
41
     *
42
     * @const INVALID_INTEGER
43
     */
44
    const INVALID_INTEGER = 'invalidInteger';
45
46
    /**
47
     * Message templates
48
     *
49
     * @var array
50
     */
51
    protected $messageTemplates = [
52
        self::INVALID_TYPE    => "'%value%' must be an integer",
53
        self::INVALID_INTEGER => "'%value%' contains an invalid page number",
54
    ];
55
56
    /**
57
     * Returns true, if value is valid. False otherwise.
58
     *
59
     * @param mixed $value
60
     *
61
     * @return bool
62
     */
63
    public function isValid($value)
64
    {
65 8
        $this->setValue($value);
66
67 8
        $typeIntegerValidator = new TypeIntegerValidator();
68
69 8
        if (!$typeIntegerValidator->isValid($value)) {
70
            $this->error(self::INVALID_TYPE);
71 8
72 1
            return false;
73 1
        }
74
75
        $greaterThanValidator = new GreaterThanValidator([
76 7
            'min'       => self::MIN,
77 7
            'inclusive' => true,
78 7
        ]);
79 7
80
        if (!$greaterThanValidator->isValid($value)) {
81 7
            $this->error(self::INVALID_INTEGER);
82 3
83 3
            return false;
84
        }
85
86 5
        return true;
87
    }
88
}