ValidatableArrayObject   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 0
dl 0
loc 39
ccs 12
cts 12
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
validate() 0 1 ?
A offsetSet() 0 6 1
A offsetUnset() 0 6 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