Passed
Push — master ( 623d43...242e5d )
by
unknown
03:09 queued 01:24
created

SelectAdapter::getSelectPayload()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
namespace Minerva\FrontQL\Adapter\Select;
4
5
use Minerva\FrontQL\Adapter\Where\WhereAdapter;
6
use Zend\Db\Sql\Select;
7
8
/**
9
 * Class SelectAdapter
10
 *
11
 * @author  Lucas A. de Araújo <[email protected]>
12
 * @package Minerva\FrontQL\Adapter\Select
13
 */
14
class SelectAdapter
15
{
16
    /**
17
     * Payload de seleção de dados
18
     *
19
     * @var SelectPayload
20
     */
21
    protected $selectPayload;
22
23
    /**
24
     * Colunas que não podem ser vistas
25
     *
26
     * @var array
27
     */
28
    protected $protectedColumns;
29
30
    /**
31
     * Retorna o payload de seleção
32
     *
33
     * @return SelectPayload
34
     */
35 1
    public function getSelectPayload()
36
    {
37 1
        return $this->selectPayload;
38
    }
39
40
    /**
41
     * Define o payload de seleção
42
     *
43
     * @param SelectPayload $selectPayload
44
     */
45 1
    public function setSelectPayload($selectPayload)
46
    {
47 1
        $this->selectPayload = $selectPayload;
48 1
    }
49
50
    /**
51
     * @return array
52
     */
53 1
    public function getProtectedColumns()
54
    {
55 1
        if(is_null($this->protectedColumns))
56 1
            $this->protectedColumns = [];
57
58 1
        return $this->protectedColumns;
59
    }
60
61
    /**
62
     * @param array $protectedColumns
63
     */
64 1
    public function setProtectedColumns($protectedColumns)
65
    {
66 1
        $this->protectedColumns = $protectedColumns;
67 1
    }
68
69
    /**
70
     * Retorna a adaptação do select com base no payload
71
     *
72
     * @return Select
73
     * @throws Basis\Exception\InvalidColumnNameException
74
     */
75 1
    public function getSelect()
76
    {
77
        // Remove as colunas protegidas
78 1
        $columns = array_diff($this->getSelectPayload()->getColumns(), $this->getProtectedColumns());
79
80
        // Adapta o payload ao padrão do zend
81 1
        $select = new Select();
82
83 1
        if(!is_null($this->getSelectPayload()->getOrder()))
84 1
            $select->order($this->getSelectPayload()->getOrder());
85
86 1
        $select->columns($columns);
87 1
        $select->where($this->getSelectPayload()->getWhere());
88 1
        $select->limit($this->getSelectPayload()->getLimit());
89
        //$select->offset($this->getSelectPayload()->getOffset());
0 ignored issues
show
Unused Code Comprehensibility introduced by
80% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
90
91 1
        return $select;
92
    }
93
}
94