Passed
Pull Request — master (#42)
by Arman
03:27
created

Result   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 8
eloc 9
c 1
b 0
f 0
dl 0
loc 48
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A findOneBy() 0 4 2
A first() 0 4 2
A asArray() 0 3 1
A count() 0 3 1
A findOne() 0 4 2
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.4.0
13
 */
14
namespace Quantum\Libraries\Database\Statements;
15
16
/**
17
 * Trait Result
18
 * @package Quantum\Libraries\Database\Statements
19
 */
20
trait Result
21
{
22
    /**
23
     * Finds the record by primary key
24
     * @inheritDoc
25
     */
26
    public function findOne(int $id): object
27
    {
28
        $result = $this->ormObject->find_one($id);
29
        return $result ?: $this->ormObject();
0 ignored issues
show
Bug introduced by
It seems like ormObject() 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

29
        return $result ?: $this->/** @scrutinizer ignore-call */ ormObject();
Loading history...
30
    }
31
32
    /**
33
     * Finds the record by given column and value
34
     * @inheritDoc
35
     */
36
    public function findOneBy(string $column, $value): object
37
    {
38
        $result = $this->ormObject->where($column, $value)->find_one();
39
        return $result ?: $this->ormObject();
40
    }
41
42
    /**
43
     * Gets the first item
44
     * @inheritDoc
45
     */
46
    public function first(): object
47
    {
48
        $result = $this->ormObject->find_one();
49
        return $result ?: $this->ormObject();
50
    }
51
52
    /**
53
     * Counts the result set
54
     * @inheritDoc
55
     */
56
    public function count(): int
57
    {
58
        return $this->ormObject->count();
59
    }
60
61
    /**
62
     * Returns the result as array
63
     * @inheritDoc
64
     */
65
    public function asArray(): array
66
    {
67
        return $this->ormObject->as_array();
68
    }
69
70
}