Entity::__debugInfo()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 0
cts 5
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 2
1
<?php
2
3
namespace Basis\Test;
4
5
use Basis\Test;
6
use Tarantool\Mapper\Entity as MapperEntity;
7
8
class Entity extends MapperEntity
9
{
10
    public $id;
11
12
    private $_test;
13
    private $_key;
14
    
15 2
    public function __construct(Test $test, string $key)
16
    {
17 2
        $this->_test = $test;
18 2
        $this->_key = $key;
19 2
    }
20
21 2
    public function save() : MapperEntity
22
    {
23 2
        if (!$this->id) {
24 2
            $max = 0;
25 2
            if (count($this->_test->data[$this->_key])) {
26 2
                $max = max(array_keys($this->_test->data[$this->_key]));
27
            }
28 2
            $this->id = $max + 1;
29
        }
30 2
        $this->_test->data[$this->_key][$this->id] = $this;
31 2
        return $this;
32
    }
33
34
    public function __debugInfo()
35
    {
36
        $info = parent::__debugInfo();
37
        unset($info['_test']);
38
        unset($info['_key']);
39
        return $info;
40
    }
41
}
42