Passed
Pull Request — master (#51)
by Arman
05:24 queued 02:50
created

Model::get()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 1
c 0
b 0
f 0
nc 2
nop 1
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.6.0
13
 */
14
15
namespace Quantum\Libraries\Database\Idiorm\Statements;
16
17
use Quantum\Libraries\Database\DbalInterface;
18
19
/**
20
 * Trait Model
21
 * @package Quantum\Libraries\Database\Idiorm\Statements
22
 */
23
trait Model
24
{
25
26
    /**
27
     * @inheritDoc
28
     * @throws \Quantum\Exceptions\DatabaseException
29
     */
30
    public function create(): DbalInterface
31
    {
32
        $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

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