Equal   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 0
dl 0
loc 57
ccs 11
cts 11
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A validate() 0 7 2
A getMessageParameters() 0 6 1
1
<?php
2
/**
3
 * Particle.
4
 *
5
 * @link      http://github.com/particle-php for the canonical source repository
6
 * @copyright Copyright (c) 2005-2016 Particle (http://particle-php.com)
7
 * @license   https://github.com/particle-php/validator/blob/master/LICENSE New BSD License
8
 */
9
namespace Particle\Validator\Rule;
10
11
use Particle\Validator\Rule;
12
13
/**
14
 * This rule is for validating if a value being validated equals another value.
15
 *
16
 * @package Particle\Validator\Rule
17
 */
18
class Equal extends Rule
19
{
20
    /**
21
     * A constant that will be used when the value is not equal to the expected value.
22
     */
23
    const NOT_EQUAL = 'Equal::NOT_EQUAL';
24
25
    /**
26
     * The message templates which can be returned by this validator.
27
     *
28
     * @var array
29
     */
30
    protected $messageTemplates = [
31
        self::NOT_EQUAL => '{{ name }} must be equal to "{{ testvalue }}"'
32
    ];
33
34
    /**
35
     * @var mixed
36
     */
37
    protected $value;
38
39
    /**
40
     * Construct the equal validator.
41
     *
42
     * @param mixed $value
43
     */
44 2
    public function __construct($value)
45
    {
46 2
        $this->value = $value;
47 2
    }
48
49
    /**
50
     * Validates if each character in $value is a decimal digit.
51
     *
52
     * @param mixed $value
53
     * @return bool
54
     */
55 2
    public function validate($value)
56
    {
57 2
        if ($this->value === $value) {
58 1
            return true;
59
        }
60 1
        return $this->error(self::NOT_EQUAL);
61
    }
62
63
    /**
64
     * Returns the parameters that may be used in a validation message.
65
     *
66
     * @return array
67
     */
68 1
    protected function getMessageParameters()
69
    {
70 1
        return array_merge(parent::getMessageParameters(), [
71 1
            'testvalue' => $this->value
72 1
        ]);
73
    }
74
}
75