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 AmmitPhp\Ammit\Domain;
5
6
class StringValidation
7
{
8
    /**
9
     * String between X chars and Y chars
10
     * @param mixed $value String to validate
11
     * @param int $minLength
12
     * @param int $maxLength
13
     * @param string $encoding
14
     *
15
     * @return bool
16
     */
17
    public function isStringBetweenValid($value, int $minLength, int $maxLength, $encoding = 'utf8'): bool
18
    {
19
        if (false ===is_string($value)) {
20
            return false;
21
        }
22
23
        $length = mb_strlen($value, $encoding);
24
        if ($length < $minLength) {
25
            return false;
26
        }
27
28
        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...
29
            return false;
30
        }
31
32
        return true;
33
    }
34
}
35