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 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