OptionInt   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 1
dl 0
loc 64
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A setMin() 0 4 1
A setMax() 0 4 1
A setValue() 0 10 2
1
<?php
2
3
/*
4
 * A PSR7 aware cURL client (https://github.com/juliangut/spiral).
5
 *
6
 * @license BSD-3-Clause
7
 * @link https://github.com/juliangut/spiral
8
 * @author Julián Gutiérrez <[email protected]>
9
 */
10
11
namespace Jgut\Spiral\Option;
12
13
/**
14
 * Integer cURL option wrapper.
15
 */
16
class OptionInt extends DefaultOption
17
{
18
    /**
19
     * Minimum valid value.
20
     *
21
     * @var int
22
     */
23
    protected $min = 0;
24
25
    /**
26
     * Maximum valid value.
27
     *
28
     * @var int
29
     */
30
    protected $max;
31
32
    /**
33
     * Create integer cURL option.
34
     *
35
     * @param int $option
36
     */
37
    public function __construct($option)
38
    {
39
        parent::__construct($option);
40
41
        $this->value = 0;
42
    }
43
44
    /**
45
     * Set minimum value.
46
     *
47
     * @param int $min
48
     */
49
    public function setMin($min)
50
    {
51
        $this->min = (int) $min;
52
    }
53
54
    /**
55
     * Set maximum value.
56
     *
57
     * @param int $max
58
     */
59
    public function setMax($max)
60
    {
61
        $this->max = (int) $max;
62
    }
63
64
    /**
65
     * {@inheritdoc}
66
     *
67
     * @param int $value
68
     */
69
    public function setValue($value)
70
    {
71
        $value = max($this->min, $value);
72
73
        if ($this->max !== null) {
74
            $value = min($value, $this->max);
75
        }
76
77
        $this->value = $value;
78
    }
79
}
80