RotationValidator   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 17
Duplicated Lines 0 %

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A valid() 0 10 2
A is_in_range() 0 3 2
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