Size::isValid()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 10
rs 9.4285
cc 2
eloc 5
nc 2
nop 0
1
<?php
2
3
/**
4
 * @author: Abdul Qureshi. <[email protected]>
5
 * 
6
 * This file has been modified from the original source.
7
 * See original here:
8
 *
9
 * @link: https://github.com/progsmile/request-validator
10
 */
11
12
namespace TheSupportGroup\Common\Validator\Rules;
13
14
use TheSupportGroup\Common\Validator\Contracts\Rules\RuleInterface;
15
16
class Size extends BaseRule implements RuleInterface
17
{
18
    public function isValid()
19
    {
20
        if ($this->isNotRequiredAndEmpty()) {
21
            return true;
22
        }
23
24
        $value = trim($this->getParams()[1]);
25
26
        return mb_strlen($value) == $this->getParams()[2];
27
    }
28
29
    /**
30
     * Returns error message from rule.
31
     *
32
     * @return string
33
     */
34
    public function getMessage()
35
    {
36
        return 'Field :field: should has exact size :param:';
37
    }
38
}
39