RangeAnnotation::initAnnotation()   B
last analyzed

Complexity

Conditions 11
Paths 12

Size

Total Lines 29
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 11
eloc 16
c 1
b 0
f 0
nc 12
nop 1
dl 0
loc 29
rs 7.3166

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
/**
4
 * This file is part of Blitz PHP framework.
5
 *
6
 * (c) 2022 Dimitri Sitchet Tomkeu <[email protected]>
7
 *
8
 * For the full copyright and license information, please view
9
 * the LICENSE file that was distributed with this source code.
10
 */
11
12
namespace BlitzPHP\Annotations\Validation;
13
14
use BlitzPHP\Annotations\BaseAnnotation;
15
use mindplay\annotations\AnnotationException;
16
17
/**
18
 * Spécifie la validation par rapport à une valeur numérique minimale et/ou maximale.
19
 *
20
 * @usage('property'=>true, 'inherited'=>true)
21
 */
22
class RangeAnnotation extends BaseAnnotation
23
{
24
    /**
25
     * @var float|int
26
     *
27
     * Valeur numérique minimale (entier ou virgule flottante)
28
     */
29
    public $min;
30
31
    /**
32
     * @var float|int
33
     *
34
     * * Valeur numérique maximale (entier ou virgule flottante)
35
     */
36
    public $max;
37
38
    /**
39
     * Initialisation de l'annotation.
40
     */
41
    public function initAnnotation(array $properties)
42
    {
43
        if (isset($properties[0])) {
44
            if (isset($properties[1])) {
45
                $this->min = $properties[0];
46
                $this->max = $properties[1];
47
                unset($properties[1]);
48
            } else {
49
                $this->max = $properties[0];
50
            }
51
52
            unset($properties[0]);
53
        }
54
55
        parent::initAnnotation($properties);
56
57
        if ($this->min !== null && ! is_int($this->min) && ! is_float($this->min)) {
0 ignored issues
show
introduced by
The condition is_float($this->min) is always true.
Loading history...
58
            throw new AnnotationException('RangeAnnotation requires a numeric (float or int) min property');
59
        }
60
61
        if ($this->max !== null && ! is_int($this->max) && ! is_float($this->max)) {
0 ignored issues
show
introduced by
The condition is_float($this->max) is always true.
Loading history...
62
            throw new AnnotationException('RangeAnnotation requires a numeric (float or int) max property');
63
        }
64
65
        if ($this->min === null && $this->max === null) {
66
            throw new AnnotationException('RangeAnnotation requires a min and/or max property');
67
        }
68
69
        $this->value = [$this->min, $this->max];
70
    }
71
}
72