Completed
Push — master ( 8ace16...5d30f6 )
by Alexey
03:23
created

MaxLenValidation   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 13
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 5
c 1
b 0
f 0
dl 0
loc 13
ccs 5
cts 5
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getErrorMessage() 0 5 2
A isValid() 0 3 1
1
<?php
2
3
4
namespace Lexuss1979\Validol\Validations;
5
6
7
use Lexuss1979\Validol\ValueObject;
8
9
class MaxLenValidation extends AbstractValidation implements ValidationInterface
10
{
11
    protected $errorMessage = null;
12 5
    public function isValid(ValueObject $data)
13
    {
14 5
        return mb_strlen($data->value()) <= $this->options[0];
15
    }
16
17 3
    public function getErrorMessage()
18
    {
19 3
        if(!is_null($this->errorMessage)) return parent::getErrorMessage();
20
21 2
        return "{$this->data->name()} is too long (maximum {$this->options[0]} characters";
22
    }
23
}