StringValidation::isStringBetweenValid()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 17
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 17
rs 9.2
c 0
b 0
f 0
cc 4
eloc 9
nc 4
nop 4
1
<?php
2
declare(strict_types = 1);
3
4
namespace Imedia\Ammit\Domain;
5
6
/**
7
 * @author Guillaume MOREL <[email protected]>
8
 */
9
class StringValidation
10
{
11
    /**
12
     * String between X chars and Y chars
13
     * @param mixed $value String to validate
14
     * @param int $minLength
15
     * @param int $maxLength
16
     * @param string $encoding
17
     *
18
     * @return bool
19
     */
20
    public function isStringBetweenValid($value, int $minLength, int $maxLength, $encoding = 'utf8'): bool
21
    {
22
        if (false ===is_string($value)) {
23
            return false;
24
        }
25
26
        $length = mb_strlen($value, $encoding);
27
        if ($length < $minLength) {
28
            return false;
29
        }
30
31
        if ($length > $maxLength) {
0 ignored issues
show
Unused Code introduced by
This if statement, and the following return statement can be replaced with return !($length > $maxLength);.
Loading history...
32
            return false;
33
        }
34
35
        return true;
36
    }
37
}
38