Lte::check()   B
last analyzed

Complexity

Conditions 7
Paths 14

Size

Total Lines 17
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 7

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 7
eloc 8
c 1
b 0
f 0
nc 14
nop 1
dl 0
loc 17
ccs 5
cts 5
cp 1
crap 7
rs 8.8333
1
<?php
2
3
/**
4
 * This file is part of Dimtrovich/Validation.
5
 *
6
 * (c) 2023 Dimitri Sitchet Tomkeu <[email protected]>
7
 *
8
 * For the full copyright and license information, please view
9
 * the LICENSE file that was distributed with this source code.
10
 */
11
12
namespace Dimtrovich\Validation\Rules;
13
14
class Lte extends AbstractRule
15
{
16
    /**
17
     * @var array
18
     */
19
    protected $fillableParams = ['value'];
20
21
    /**
22
     * {@inheritDoc}
23
     */
24
    public function check($value): bool
25
    {
26 2
        $this->requireParameters($this->fillableParams);
27
28
        if (is_int($value) || is_float($value)) {
29 2
            $value = (string) $value;
30
        }
31
32
        if (! is_string($value)) {
33 2
            return false;
34
        }
35
36
        if (! is_numeric($compare = $this->parameter('value'))) {
37 2
            $compare = $this->getAttribute()->getValue($compare);
38
        }
39
40 2
        return is_numeric($value) && is_numeric($compare) && $value <= $compare;
41
    }
42
}
43