Passed
Pull Request — master (#190)
by Arman
02:53
created

Model::delete()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
/**
4
 * Quantum PHP Framework
5
 *
6
 * An open source software development framework for PHP
7
 *
8
 * @package Quantum
9
 * @author Arman Ag. <[email protected]>
10
 * @copyright Copyright (c) 2018 Softberg LLC (https://softberg.org)
11
 * @link http://quantum.softberg.org/
12
 * @since 2.9.5
13
 */
14
15
namespace Quantum\Libraries\Database\Adapters\Idiorm\Statements;
16
17
use Quantum\Libraries\Database\Exceptions\DatabaseException;
18
use Quantum\Libraries\Database\Contracts\DbalInterface;
19
20
/**
21
 * Trait Model
22
 * @package Quantum\Libraries\Database
23
 */
24
trait Model
25
{
26
27
    /**
28
     * @inheritDoc
29
     * @throws DatabaseException
30
     */
31
    public function create(): DbalInterface
32
    {
33
        $this->getOrmModel()->create();
0 ignored issues
show
Bug introduced by
It seems like getOrmModel() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

33
        $this->/** @scrutinizer ignore-call */ 
34
               getOrmModel()->create();
Loading history...
34
        return $this;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this returns the type Quantum\Libraries\Databa...Idiorm\Statements\Model which is incompatible with the type-hinted return Quantum\Libraries\Database\Contracts\DbalInterface.
Loading history...
35
    }
36
37
    /**
38
     * @inheritDoc
39
     * @throws DatabaseException
40
     */
41
    public function prop(string $key, $value = null)
42
    {
43
        if (func_num_args() == 2) {
44
            $this->getOrmModel()->$key = $value;
45
        } else {
46
            return $this->getOrmModel()->$key ?? null;
47
        }
48
    }
49
50
    /**
51
     * @inheritDoc
52
     * @throws DatabaseException
53
     */
54
    public function save(): bool
55
    {
56
        return $this->getOrmModel()->save();
57
    }
58
59
    /**
60
     * @inheritDoc
61
     * @throws DatabaseException
62
     */
63
    public function delete(): bool
64
    {
65
        return $this->getOrmModel()->delete();
66
    }
67
68
    /**
69
     * @inheritDoc
70
     * @throws DatabaseException
71
     */
72
    public function deleteMany(): bool
73
    {
74
        return $this->getOrmModel()->delete_many();
75
    }
76
}