Passed
Push — master ( 5f9e30...9e7e6b )
by Dedipyaman
02:07
created

MinimumLength::__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/23/19
6
 * Time: 1:53 AM
7
 */
8
9
namespace Phypes\Rule\String;
10
11
use Phypes\Error\RuleError\RuleError;
12
use Phypes\Error\RuleError\RuleErrorCode;
13
use Phypes\Result;
14
use Phypes\Rule\Rule;
15
16
class MinimumLength implements Rule
17
{
18
    private $minLength;
19
20
    public function __construct(int $minLength)
21
    {
22
        $this->minLength = $minLength;
23
    }
24
25
    public function validate($data) : Result
26
    {
27
        if (mb_strlen($data, 'UTF-8') >= $this->minLength) {
28
            return new Result(true);
29
        }
30
        else return new Result(false,
31
            new RuleError(RuleErrorCode::TOO_SHORT,
32
            'The supplied string is too short'));
33
    }
34
}