Completed
Push — master ( 1add5f...99c403 )
by Dmitry
07:16
created

Entity   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 1
dl 0
loc 34
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A save() 0 12 3
A __debugInfo() 0 7 1
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
    public function __debugInfo()
34
    {
35
        $info = get_object_vars($this);
36
        unset($info['_test']);
37
        unset($info['_key']);
38
        return $info;
39
    }
40
}
41