Completed
Push — master ( 8e13bf...38fa9e )
by Arman
18s queued 15s
created

Result::paginate()   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
nc 1
nop 2
dl 0
loc 3
rs 10
c 0
b 0
f 0
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.0
13
 */
14
15
namespace Quantum\Libraries\Database\Idiorm\Statements;
16
17
use Quantum\Libraries\Database\PaginatorInterface;
18
use Quantum\Libraries\Database\Idiorm\Paginator;
19
use Quantum\Libraries\Database\DbalInterface;
20
use Quantum\Exceptions\DatabaseException;
21
22
/**
23
 * Trait Result
24
 * @package Quantum\Libraries\Database\Idiorm\Statements
25
 */
26
trait Result
27
{
28
29
    /**
30
     * @inheritDoc
31
     * @throws DatabaseException
32
     */
33
    public function get()
34
    {
35
        return $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

35
        return $this->/** @scrutinizer ignore-call */ getOrmModel()->find_many();
Loading history...
36
    }
37
38
	  /**
39
	   * @param int $perPage
40
	   * @param int $currentPage
41
	   * @return PaginatorInterface
42
	   */
43
	  public function paginate(int $perPage, int $currentPage = 1): PaginatorInterface
44
	  {
45
	  	  return new Paginator($this, $perPage, $currentPage);
46
	  }
47
48
    /**
49
     * @inheritDoc
50
     * @throws DatabaseException
51
     */
52
    public function findOne(int $id): DbalInterface
53
    {
54
        $ormObject = $this->getOrmModel()->find_one($id);
55
56
        if ($ormObject) {
57
            $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

57
            $this->/** @scrutinizer ignore-call */ 
58
                   updateOrmModel($ormObject);
Loading history...
58
        }
59
60
        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...
61
    }
62
63
    /**
64
     * @inheritDoc
65
     * @throws DatabaseException
66
     */
67
    public function findOneBy(string $column, $value): DbalInterface
68
    {
69
        $ormObject = $this->getOrmModel()->where($column, $value)->find_one();
70
        if ($ormObject) {
71
            $this->updateOrmModel($ormObject);
72
        }
73
74
        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...
75
    }
76
77
    /**
78
     * @inheritDoc
79
     * @throws DatabaseException
80
     */
81
    public function first(): DbalInterface
82
    {
83
        $ormObject = $this->getOrmModel()->find_one();
84
        if ($ormObject) {
85
            $this->updateOrmModel($ormObject);
86
        }
87
88
        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...
89
    }
90
91
    /**
92
     * @inheritDoc
93
     * @throws DatabaseException
94
     */
95
    public function count(): int
96
    {
97
        return $this->getOrmModel()->count();
98
    }
99
100
    /**
101
     * @inheritDoc
102
     * @throws DatabaseException
103
     */
104
    public function asArray(): array
105
    {
106
        $result = $this->getOrmModel()->as_array();
107
108
        if (count($this->hidden) > 0) {
109
            $result = $this->setHidden($result);
110
        }
111
112
        return $result;
113
    }
114
115
    /**
116
     * @inheritDoc
117
     */
118
    public function setHidden($result)
119
    {
120
        return array_diff_key($result, array_flip($this->hidden));
121
    }
122
}
123