Passed
Push — master ( da1b99...92df87 )
by Aleksandr
03:12
created

DomainModel::toArray()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 4
c 0
b 0
f 0
nc 2
nop 0
dl 0
loc 6
ccs 5
cts 5
cp 1
crap 2
rs 10
1
<?php
2
/**
3
 * This file is part of the eav package.
4
 * @author    Aleksandr Drobotik <[email protected]>
5
 * @copyright 2023 Aleksandr Drobotik
6
 * @license   https://opensource.org/license/mit  The MIT License
7
 */
8
declare(strict_types=1);
9
10
namespace Drobotik\Eav\Model;
11
12
use Drobotik\Eav\Enum\_DOMAIN;
13
14
class DomainModel extends Model
15
{
16
    private string $name;
17
18 1
    public function __construct()
19
    {
20 1
        $this->setTable(_DOMAIN::table());
21 1
        $this->setKeyName(_DOMAIN::ID->column());
22
    }
23
24 1
    public function getName(): string
25
    {
26 1
        return $this->name;
27
    }
28
29 1
    public function setName($name) : self
30
    {
31 1
        $this->name = $name;
32 1
        return $this;
33
    }
34
35 1
    public function create() : int
36
    {
37 1
        return $this->insert([
38 1
            _DOMAIN::NAME->column() => $this->getName()
39 1
        ]);
40
    }
41
42 1
    public function toArray(): array
43
    {
44 1
        $result = parent::toArray();
45 1
        if(isset($this->name))
46 1
            $result[_DOMAIN::NAME->column()] = $this->getName();
47 1
        return $result;
48
    }
49
50
51
}