Completed
Push — master ( ef3cb7...1add5f )
by Dmitry
09:13
created

Entity::save()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 12
rs 9.8666
c 0
b 0
f 0
cc 3
nc 3
nop 0
1
<?php
2
3
namespace Basis\Test;
4
5
use Basis\Test;
6
7
class Entity 
8
{
9
    public $id;
10
11
    private $_test;
12
    private $_key;
13
    
14
    public function __construct(Test $test, string $key)
15
    {
16
        $this->_test = $test;
17
        $this->_key = $key;
18
    }
19
20
    public function save()
21
    {
22
        if (!$this->id) {
23
            $max = 0;
24
            if (count($this->_test->data[$this->_key])) {
25
                $max = max(array_keys($this->_test->data[$this->_key]));
26
            }
27
            $this->id = $max + 1;
28
        }
29
        $this->_test->data[$this->_key][$this->id] = $this;
30
        return $this;
31
    }
32
}
33