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

Entity   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 1
dl 0
loc 26
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A save() 0 12 3
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