Map::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 6
cts 6
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 4
crap 1
1
<?php
2
namespace GenericCollections;
3
4
use GenericCollections\Abstracts\AbstractMap;
5
use GenericCollections\Traits\ElementTypeProperty;
6
use GenericCollections\Traits\KeyTypeProperty;
7
use GenericCollections\Traits\OptionsProperty;
8
use GenericCollections\Utils\TypeKeyProperty;
9
use GenericCollections\Utils\TypeProperty;
10
11
class Map extends AbstractMap
12
{
13
    use OptionsProperty;
14
    use KeyTypeProperty;
15
    use ElementTypeProperty {
16
        getElementType as getValueType;
17
        checkElementType as checkValueType;
18
    }
19
20
    /**
21
     * Generic map
22
     *
23
     * example:
24
     * ```php
25
     * new Map('string', Foo::class, [
26
     *     'one' => new Foo(),
27
     *     'two' => new Foo(),
28
     * ];
29
     * ```
30
     *
31
     * Options:
32
     * - Defaults: not allow nulls, allow duplicates, identical comparisons
33
     * - deny duplicates can be activated
34
     * - If allow null elements and deny duplicates, any entry on the map can have a null value
35
     *
36
     * @param string $keyType
37
     * @param string $valueType
38
     * @param array $values
39
     * @param int $options check constants inside Options class
40
     */
41 29
    public function __construct($keyType, $valueType, array $values = [], $options = 0)
42
    {
43 29
        $this->options = new Options($options);
44 29
        $this->keyType = new TypeKeyProperty($keyType, false);
45 28
        $this->elementType = new TypeProperty($valueType, $this->optionAllowNullMembers());
46 28
        $this->putAll($values);
47 28
    }
48
}
49