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

Reducer::groupBy()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
rs 10
c 1
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.6.0
13
 */
14
15
namespace Quantum\Libraries\Database\Idiorm\Statements;
16
17
use Quantum\Libraries\Database\DbalInterface;
18
use RecursiveIteratorIterator;
19
use RecursiveArrayIterator;
20
21
/**
22
 * Trait Modifier
23
 * @package Quantum\Libraries\Database\Idiorm\Statements
24
 */
25
trait Reducer
26
{
27
28
    /**
29
     * @inheritDoc
30
     * @throws \Quantum\Exceptions\DatabaseException
31
     */
32
    public function select(...$columns): DbalInterface
33
    {
34
        array_walk($columns, function (&$column) {
35
            if (is_array($column)) {
36
                $column = array_flip($column);
37
            }
38
        });
39
40
        $iterator = new RecursiveIteratorIterator(new RecursiveArrayIterator($columns));
41
        $columns = iterator_to_array($iterator, true);
42
43
        $this->getOrmModel()->select_many($columns);
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

43
        $this->/** @scrutinizer ignore-call */ 
44
               getOrmModel()->select_many($columns);
Loading history...
44
        return $this;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this returns the type Quantum\Libraries\Databa...iorm\Statements\Reducer which is incompatible with the type-hinted return Quantum\Libraries\Database\DbalInterface.
Loading history...
45
    }
46
47
    /**
48
     * @inheritDoc
49
     * @throws \Quantum\Exceptions\DatabaseException
50
     */
51
    public function groupBy(string $column): DbalInterface
52
    {
53
        $this->getOrmModel()->group_by($column);
54
        return $this;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this returns the type Quantum\Libraries\Databa...iorm\Statements\Reducer which is incompatible with the type-hinted return Quantum\Libraries\Database\DbalInterface.
Loading history...
55
    }
56
57
    /**
58
     * @inheritDoc
59
     * @throws \Quantum\Exceptions\DatabaseException
60
     */
61
    public function orderBy(string $column, string $direction): DbalInterface
62
    {
63
        switch (strtolower($direction)) {
64
            case 'asc':
65
                $this->getOrmModel()->order_by_asc($column);
66
                break;
67
            case 'desc':
68
                $this->getOrmModel()->order_by_desc($column);
69
                break;
70
        }
71
72
        return $this;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this returns the type Quantum\Libraries\Databa...iorm\Statements\Reducer which is incompatible with the type-hinted return Quantum\Libraries\Database\DbalInterface.
Loading history...
73
    }
74
75
    /**
76
     * @inheritDoc
77
     * @throws \Quantum\Exceptions\DatabaseException
78
     */
79
    public function offset(int $offset): DbalInterface
80
    {
81
        $this->getOrmModel()->offset($offset);
82
        return $this;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this returns the type Quantum\Libraries\Databa...iorm\Statements\Reducer which is incompatible with the type-hinted return Quantum\Libraries\Database\DbalInterface.
Loading history...
83
    }
84
85
    /**
86
     * @inheritDoc
87
     * @throws \Quantum\Exceptions\DatabaseException
88
     */
89
    public function limit(int $limit): DbalInterface
90
    {
91
        $this->getOrmModel()->limit($limit);
92
        return $this;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this returns the type Quantum\Libraries\Databa...iorm\Statements\Reducer which is incompatible with the type-hinted return Quantum\Libraries\Database\DbalInterface.
Loading history...
93
    }
94
95
}