Options::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 11
ccs 9
cts 9
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 8
nc 2
nop 1
crap 2
1
<?php
2
namespace GenericCollections;
3
4
use GenericCollections\Exceptions\OptionsException;
5
use GenericCollections\Interfaces\BaseOptionsInterface;
6
7
/**
8
 * This class implements the BaseOptionsInterface
9
 *
10
 * Is a ValueObject (read-only) that defines the the container behavior
11
 *
12
 * @package GenericCollections
13
 */
14
class Options implements BaseOptionsInterface
15
{
16
    /** @var bool null members property */
17
    private $allowNullMembers;
18
19
    /** @var bool duplicates property */
20
    private $uniqueValues;
21
22
    /** @var bool comparison is identical */
23
    private $comparisonIsIdentical;
24
25
    /** @var int original options value */
26
    private $options;
27
28
    /**
29
     * Create a Options object based on a numeric value
30
     *
31
     * @param int $options
32
     */
33 149
    public function __construct($options)
34
    {
35 149
        if (! is_int($options)) {
36 1
            throw new OptionsException('The supplied options value is not an integer');
37
        }
38 148
        $options = $options & 7; // truncate to max value (3 ^ 2 - 1)
39 148
        $this->options = $options;
40 148
        $this->allowNullMembers = (bool) ($options & self::ALLOW_NULLS);
41 148
        $this->uniqueValues = (bool) ($options & self::UNIQUE_VALUES);
42 148
        $this->comparisonIsIdentical = ! (bool) ($options & self::COMPARISON_EQUAL);
43 148
    }
44
45 147
    public function optionAllowNullMembers()
46
    {
47 147
        return $this->allowNullMembers;
48
    }
49
50 120
    public function optionUniqueValues()
51
    {
52 120
        return $this->uniqueValues;
53
    }
54
55 116
    public function optionComparisonIsIdentical()
56
    {
57 116
        return $this->comparisonIsIdentical;
58
    }
59
60
    /**
61
     * Return the options value
62
     *
63
     * @return int
64
     */
65 9
    public function getOptions()
66
    {
67 9
        return $this->options;
68
    }
69
}
70