MinRule::errorMessage()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 3
Ratio 100 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 3
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
4
namespace SolBianca\Validator\Rules;
5
6
7
use SolBianca\Validator\Interfaces\RuleInterface;
8
9 View Code Duplication
class MinRule implements RuleInterface
0 ignored issues
show
Duplication introduced by
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...
10
{
11
    /**
12
     * {@inheritdoc}
13
     */
14
    public function run($value, array $input, array $args): bool
15
    {
16
        $number = isset($args[1]) && $args[1] === 'number';
17
        if ($number) {
18
            return (float)$value >= (float)$args[0];
19
        }
20
        return mb_strlen($value) >= (int)$args[0];
21
    }
22
23
    /**
24
     * {@inheritdoc}
25
     */
26
    public function errorMessage(): string
27
    {
28
        return 'Field `{field}` must be a minimum of `{$0}`.';
29
    }
30
31
    /**
32
     * {@inheritdoc}
33
     */
34
    public function canSkip(): bool
35
    {
36
        return true;
37
    }
38
}