ValidatorShared   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 16
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 7
c 1
b 0
f 0
dl 0
loc 16
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A floatingPointValidator() 0 14 5
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