ValidatableArrayObject::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 4
cts 4
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 3
crap 1
1
<?php
2
3
namespace Assimtech\Tempo\ArrayObject;
4
5
use ArrayObject;
6
7
abstract class ValidatableArrayObject extends ArrayObject
8
{
9
    /**
10
     * {@inheritdoc}
11
     */
12 35
    public function __construct($input = array(), $flags = 0, $iteratorClass = 'ArrayIterator')
13
    {
14 35
        parent::__construct($input, $flags, $iteratorClass);
15
16 35
        $this->validate();
17 31
    }
18
19
    /**
20
     * @param string|null $index The index to validate, if null, validate all properties
21
     * @return void
22
     * @throws \InvalidArgumentException
23
     */
24
    abstract protected function validate($index = null);
25
26
    /**
27
     * {@inheritdoc}
28
     */
29 4
    public function offsetSet($index, $newval)
30
    {
31 4
        parent::offsetSet($index, $newval);
32
33 4
        $this->validate($index);
34 1
    }
35
36
    /**
37
     * {@inheritdoc}
38
     */
39 4
    public function offsetUnset($index)
40
    {
41 4
        parent::offsetUnset($index);
42
43 4
        $this->validate($index);
44 1
    }
45
}
46