MinLength   A
last analyzed

Coupling/Cohesion

Components 1
Dependencies 2

Complexity

Total Complexity 4

Size/Duplication

Total Lines 32
Duplicated Lines 100 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 32
loc 32
ccs 9
cts 9
cp 1
rs 10
c 0
b 0
f 0
wmc 4
lcom 1
cbo 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 4 4 1
A validate() 11 11 3

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace League\JsonGuard\Constraint\DraftFour;
4
5
use League\JsonGuard;
6
use League\JsonGuard\Assert;
7
use League\JsonGuard\ConstraintInterface;
8
use League\JsonGuard\Validator;
9
use function League\JsonGuard\error;
10
11 View Code Duplication
final class MinLength implements ConstraintInterface
0 ignored issues
show
Duplication introduced by Matt Allan
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
12
{
13
    const KEYWORD = 'minLength';
14
15
    /**
16
     * @var string
17
     */
18
    private $charset;
19
20
    /**
21
     * @param string $charset
22
     */
23 14
    public function __construct($charset = 'UTF-8')
24
    {
25 14
        $this->charset = $charset;
26 14
    }
27
28
    /**
29
     * {@inheritdoc}
30
     */
31 14
    public function validate($value, $parameter, Validator $validator)
32
    {
33 14
        Assert::type($parameter, 'number', self::KEYWORD, $validator->getSchemaPath());
34 12
        Assert::nonNegative($parameter, self::KEYWORD, $validator->getSchemaPath());
35
36 10
        if (!is_string($value) || JsonGuard\strlen($value, $this->charset) >= $parameter) {
37 10
            return null;
38
        }
39
40 6
        return error('The string must be at least {parameter} characters long.', $validator);
41
    }
42
}
43