Passed
Pull Request — master (#51)
by Arman
04:26
created

Result   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 74
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 18
dl 0
loc 74
rs 10
c 1
b 0
f 0
wmc 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A findOne() 0 9 2
A findOneBy() 0 8 2
A asArray() 0 3 1
A get() 0 6 2
A first() 0 8 2
A count() 0 3 1
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 Result
21
 * @package Quantum\Libraries\Database\Idiorm\Statements
22
 */
23
trait Result
24
{
25
26
    /**
27
     * @inheritDoc
28
     * @throws \Quantum\Exceptions\DatabaseException
29
     */
30
    public function get(?int $returnType = self::TYPE_ARRAY)
0 ignored issues
show
Bug introduced by
The constant Quantum\Libraries\Databa...ents\Result::TYPE_ARRAY was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
31
    {
32
        return ($returnType == self::TYPE_OBJECT) ?
0 ignored issues
show
Bug introduced by
The constant Quantum\Libraries\Databa...nts\Result::TYPE_OBJECT was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
33
            $this->getOrmModel()->find_many()
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()->find_many()
Loading history...
34
            :
35
            $this->getOrmModel()->find_array();
36
    }
37
38
    /**
39
     * @inheritDoc
40
     * @throws \Quantum\Exceptions\DatabaseException
41
     */
42
    public function findOne(int $id): DbalInterface
43
    {
44
        $ormObject = $this->getOrmModel()->find_one($id);
45
46
        if ($ormObject) {
47
            $this->updateOrmModel($ormObject);
0 ignored issues
show
Bug introduced by
It seems like updateOrmModel() 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

47
            $this->/** @scrutinizer ignore-call */ 
48
                   updateOrmModel($ormObject);
Loading history...
48
        }
49
50
        return $this;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this returns the type Quantum\Libraries\Databa...diorm\Statements\Result which is incompatible with the type-hinted return Quantum\Libraries\Database\DbalInterface.
Loading history...
51
    }
52
53
    /**
54
     * @inheritDoc
55
     * @throws \Quantum\Exceptions\DatabaseException
56
     */
57
    public function findOneBy(string $column, $value): DbalInterface
58
    {
59
        $ormObject = $this->getOrmModel()->where($column, $value)->find_one();
60
        if ($ormObject) {
61
            $this->updateOrmModel($ormObject);
62
        }
63
64
        return $this;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this returns the type Quantum\Libraries\Databa...diorm\Statements\Result which is incompatible with the type-hinted return Quantum\Libraries\Database\DbalInterface.
Loading history...
65
    }
66
67
    /**
68
     * @inheritDoc
69
     * @throws \Quantum\Exceptions\DatabaseException
70
     */
71
    public function first(): DbalInterface
72
    {
73
        $ormObject = $this->getOrmModel()->find_one();
74
        if ($ormObject) {
75
            $this->updateOrmModel($ormObject);
76
        }
77
78
        return $this;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this returns the type Quantum\Libraries\Databa...diorm\Statements\Result which is incompatible with the type-hinted return Quantum\Libraries\Database\DbalInterface.
Loading history...
79
    }
80
81
    /**
82
     * @inheritDoc
83
     * @throws \Quantum\Exceptions\DatabaseException
84
     */
85
    public function count(): int
86
    {
87
        return $this->getOrmModel()->count();
88
    }
89
90
    /**
91
     * @inheritDoc
92
     * @throws \Quantum\Exceptions\DatabaseException
93
     */
94
    public function asArray(): array
95
    {
96
        return $this->getOrmModel()->as_array();
97
    }
98
99
}