Passed
Push — master ( e83d2f...c5d235 )
by Dedipyaman
02:10
created

MaximumLength::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: dedipyaman
5
 * Date: 1/25/19
6
 * Time: 3:46 PM
7
 */
8
9
namespace Phypes\Rule\String;
10
11
12
use Phypes\Error\RuleError\RuleError;
13
use Phypes\Error\RuleError\RuleErrorCode;
14
use Phypes\Result;
15
use Phypes\Rule\Rule;
16
17
class MaximumLength implements Rule
18
{
19
    private $maxLength;
20
21
    public function __construct(int $maxLength)
22
    {
23
        $this->maxLength = $maxLength;
24
    }
25
    public function validate($data) : Result
26
    {
27
        if (mb_strlen($data, 'UTF-8') <= $this->maxLength) {
28
            return new Result(true);
29
        }
30
        else return new Result(false,
31
            new RuleError(RuleErrorCode::TOO_LONG,
32
                'The supplied string is too long'));
33
    }
34
}