Completed
Push — master ( 3b34b0...1f6e23 )
by Adrian
01:20
created

Matching::validate()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 11
ccs 6
cts 6
cp 1
rs 9.9
c 0
b 0
f 0
cc 2
nc 2
nop 2
crap 2
1
<?php
2
declare(strict_types=1);
3
namespace Sirius\Validation\Rule;
4
5
class Matching extends AbstractRule
6
{
7
    const OPTION_ITEM = 'item';
8
9
    const MESSAGE = 'This input does not match {item}';
10
    const LABELED_MESSAGE = '{label} does not match {item}';
11
12
    protected $optionsIndexMap = [
13
        0 => self::OPTION_ITEM
14
    ];
15
16 5
    public function validate($value, string $valueIdentifier = null):bool
17
    {
18 5
        $this->value = $value;
19 5
        if (isset($this->options[self::OPTION_ITEM])) {
20 3
            $this->success = ($value == $this->context->getItemValue($this->options[self::OPTION_ITEM]));
21
        } else {
22 2
            $this->success = true;
23
        }
24
25 5
        return $this->success;
26
    }
27
}
28