ValidatorShared::floatingPointValidator()   A
last analyzed

Complexity

Conditions 5
Paths 4

Size

Total Lines 14
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 6
c 1
b 0
f 0
dl 0
loc 14
rs 9.6111
cc 5
nc 4
nop 1
1
<?php
2
3
namespace Conlect\ImageIIIF\Validators;
4
5
use Conlect\ImageIIIF\Exceptions\BadRequestException;
6
7
class ValidatorShared
8
{
9
    public function floatingPointValidator(string $value)
10
    {
11
        if (is_float($value + 0)) {
0 ignored issues
show
introduced by
The condition is_float($value + 0) is always false.
Loading history...
12
            // if less than zero and doesn't start with a zero
13
            if ($value + 0 < 1 && ! str_starts_with($value, '0')) {
14
                throw new BadRequestException('Region values less than one require a leading zero.');
15
            }
16
            // option should not have an extra trailing zero
17
            if (str_ends_with($value, '0')) {
18
                throw new BadRequestException('Region values should not contain a trailing zero.');
19
            }
20
        }
21
22
        return true;
23
    }
24
}
25