RotationValidator::is_in_range()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 2
nc 2
nop 3
1
<?php
2
3
namespace Conlect\ImageIIIF\Validators;
4
5
use Conlect\ImageIIIF\Exceptions\BadRequestException;
6
use Conlect\ImageIIIF\Validators\Contracts\ValidatorInterface;
7
8
class RotationValidator extends ValidatorAbstract implements ValidatorInterface
9
{
10
    public function valid($value)
11
    {
12
        $startValue = $value;
13
        $value = preg_replace('/!/', '', $value);
14
15
        if ($this->is_in_Range($value)) {
16
            return true;
17
        }
18
19
        throw new BadRequestException("Rotation $startValue is invalid.");
20
    }
21
22
    protected function is_in_range($value, $min = 0, $max = 360)
23
    {
24
        return (int)$value >= $min && (int)$value <= $max;
25
    }
26
}
27