LessThanOrEqual::useTrailer()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
namespace Er1z\FakeMock\Decorator\AssertDecorator;
4
5
use Er1z\FakeMock\Accessor;
6
use Er1z\FakeMock\Metadata\FieldMetadata;
7
use phpDocumentor\Reflection\Types\Float_;
8
use Symfony\Component\Validator\Constraint;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Validator\Constraint was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
9
10
class LessThanOrEqual implements AssertDecoratorInterface
11
{
12 36
    public function decorate(&$value, FieldMetadata $field, Constraint $configuration, ?string $group = null): bool
13
    {
14 36
        if (!is_null($value) && !is_numeric($value)) {
15 6
            throw new \InvalidArgumentException('Non-numeric value supplied');
16
        }
17
18 30
        $trailer = 0;
19 30
        if ($this->useTrailer()) {
20 15
            $trailer = $field->type instanceof Float_ ? 0.00001 : 1;
21
        }
22
23
        /*
24
         * @var \Symfony\Component\Validator\Constraints\LessThan|\Symfony\Component\Validator\Constraints\LessThanOrEqual
25
         */
26 30
        if ($configuration->value && $value >= $configuration->value) {
27 12
            $value -= $value - $configuration->value + $trailer;
28 18
        } elseif ($configuration->propertyPath) {
29 18
            $compare = Accessor::getPropertyValue($field->object, $configuration->propertyPath);
30
31 18
            if (!is_numeric($compare)) {
32 6
                throw new \InvalidArgumentException('Non-numeric value supplied');
33
            }
34
35 12
            if ($value >= $compare) {
36 12
                $value -= $value - $compare + $trailer;
37
            }
38
        }
39
40 24
        return true;
41
    }
42
43 15
    protected function useTrailer()
44
    {
45 15
        return false;
46
    }
47
}
48