StringValidation   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 0
dl 0
loc 29
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A isStringBetweenValid() 0 17 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