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

Result   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 84
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 16
dl 0
loc 84
rs 10
c 1
b 0
f 0
wmc 6

6 Methods

Rating   Name   Duplication   Size   Complexity  
A findOneBy() 0 8 1
A get() 0 3 1
A count() 0 3 1
A first() 0 8 1
A asArray() 0 3 1
A findOne() 0 8 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\Sleekdb\Statements;
16
17
use Quantum\Libraries\Database\DbalInterface;
18
19
/**
20
 * Trait Result
21
 * @package Quantum\Libraries\Database\Sleekdb\Statements
22
 */
23
trait Result
24
{
25
26
    /**
27
     * @inheritDoc
28
     * @throws \Quantum\Exceptions\DatabaseException
29
     * @throws \SleekDB\Exceptions\IOException
30
     * @throws \SleekDB\Exceptions\InvalidArgumentException
31
     * @throws \SleekDB\Exceptions\InvalidConfigurationException
32
     */
33
    public function get()
34
    {
35
        return $this->getBuilder()->getQuery()->fetch();
0 ignored issues
show
Bug introduced by
It seems like getBuilder() 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

35
        return $this->/** @scrutinizer ignore-call */ getBuilder()->getQuery()->fetch();
Loading history...
36
    }
37
38
    /**
39
     * @inheritDoc
40
     * @throws \Quantum\Exceptions\DatabaseException
41
     * @throws \SleekDB\Exceptions\IOException
42
     * @throws \SleekDB\Exceptions\InvalidArgumentException
43
     * @throws \SleekDB\Exceptions\InvalidConfigurationException
44
     */
45
    public function findOne(int $id): DbalInterface
46
    {
47
        $result = $this->getOrmModel()->findById($id);
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

47
        $result = $this->/** @scrutinizer ignore-call */ getOrmModel()->findById($id);
Loading history...
48
49
        $this->data = $result;
0 ignored issues
show
Bug Best Practice introduced by
The property data does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
50
        $this->modifiedFields = $result;
0 ignored issues
show
Bug Best Practice introduced by
The property modifiedFields does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
51
52
        return $this;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this returns the type Quantum\Libraries\Databa...eekdb\Statements\Result which is incompatible with the type-hinted return Quantum\Libraries\Database\DbalInterface.
Loading history...
53
    }
54
55
    /**
56
     * @inheritDoc
57
     * @throws \Quantum\Exceptions\DatabaseException
58
     * @throws \SleekDB\Exceptions\IOException
59
     * @throws \SleekDB\Exceptions\InvalidArgumentException
60
     * @throws \SleekDB\Exceptions\InvalidConfigurationException
61
     */
62
    public function findOneBy(string $column, $value): DbalInterface
63
    {
64
        $result = $this->getOrmModel()->findOneBy([$column, '=', $value]);
65
66
        $this->data = $result;
0 ignored issues
show
Bug Best Practice introduced by
The property data does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
67
        $this->modifiedFields = $result;
0 ignored issues
show
Bug Best Practice introduced by
The property modifiedFields does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
68
69
        return $this;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this returns the type Quantum\Libraries\Databa...eekdb\Statements\Result which is incompatible with the type-hinted return Quantum\Libraries\Database\DbalInterface.
Loading history...
70
    }
71
72
    /**
73
     * @inheritDoc
74
     * @throws \Quantum\Exceptions\DatabaseException
75
     * @throws \SleekDB\Exceptions\IOException
76
     * @throws \SleekDB\Exceptions\InvalidArgumentException
77
     * @throws \SleekDB\Exceptions\InvalidConfigurationException
78
     */
79
    public function first(): DbalInterface
80
    {
81
        $result = $this->getBuilder()->getQuery()->first();
82
83
        $this->data = $result;
0 ignored issues
show
Bug Best Practice introduced by
The property data does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
84
        $this->modifiedFields = $result;
0 ignored issues
show
Bug Best Practice introduced by
The property modifiedFields does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
85
86
        return $this;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this returns the type Quantum\Libraries\Databa...eekdb\Statements\Result which is incompatible with the type-hinted return Quantum\Libraries\Database\DbalInterface.
Loading history...
87
    }
88
89
    /**
90
     * @inheritDoc
91
     * @throws \Quantum\Exceptions\DatabaseException
92
     * @throws \SleekDB\Exceptions\IOException
93
     * @throws \SleekDB\Exceptions\InvalidArgumentException
94
     * @throws \SleekDB\Exceptions\InvalidConfigurationException
95
     */
96
    public function count(): int
97
    {
98
        return count($this->getBuilder()->getQuery()->fetch());
99
    }
100
101
    /**
102
     * @inheritDoc
103
     */
104
    public function asArray(): array
105
    {
106
        return $this->data;
107
    }
108
109
}