Passed
Push — master ( 023570...3c9f2b )
by Aleksandr
02:49
created

DomainModel::create()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 8
nc 1
nop 1
dl 0
loc 11
ccs 10
cts 10
cp 1
crap 1
rs 10
c 0
b 0
f 0
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 Doctrine\DBAL\Exception;
13
use Drobotik\Eav\Enum\_DOMAIN;
14
15
class DomainModel extends Model
16
{
17 1
    public function __construct()
18
    {
19 1
        $this->setTable(_DOMAIN::table());
20 1
        $this->setKeyName(_DOMAIN::ID->column());
21
    }
22
    /**
23
     * @throws Exception
24
     */
25 1
    public function create(array $data) : int
26
    {
27 1
        $conn = $this->db();
28 1
        $conn->createQueryBuilder()
29 1
            ->insert(_DOMAIN::table())
30 1
            ->values([
31 1
                _DOMAIN::NAME->column() => '?'
32 1
            ])
33 1
            ->setParameter(0, $data[_DOMAIN::NAME->column()])
34 1
            ->executeQuery();
35 1
        return (int) $conn->lastInsertId();
36
    }
37
38
}