TableSelectEntity::__construct()   A
last analyzed

Complexity

Conditions 5
Paths 8

Size

Total Lines 18
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 5
eloc 13
c 1
b 0
f 0
nc 8
nop 7
dl 0
loc 18
rs 9.5222
1
<?php
2
3
namespace Lagdo\DbAdmin\Driver\Entity;
4
5
class TableSelectEntity
6
{
7
    /**
8
     * The table name
9
     *
10
     * @var string
11
     */
12
    public $table = '';
13
14
    /**
15
     * The fields to select
16
     *
17
     * @var array
18
     */
19
    public $fields = [];
20
21
    /**
22
     * The where clauses
23
     *
24
     * @var array
25
     */
26
    public $where = [];
27
28
    /**
29
     * The group by clauses
30
     *
31
     * @var array
32
     */
33
    public $group = [];
34
35
    /**
36
     * The order by clauses
37
     *
38
     * @var array
39
     */
40
    public $order = [];
41
42
    /**
43
     * All clauses, formatted
44
     *
45
     * @var string
46
     */
47
    public $clauses = '';
48
49
    /**
50
     * The row limit
51
     *
52
     * @var int
53
     */
54
    public $limit = 1;
55
56
    /**
57
     * The page number
58
     *
59
     * @var int
60
     */
61
    public $page = 0;
62
63
    /**
64
     * The constructor
65
     *
66
     * @param string $table
67
     * @param array $fields
68
     * @param array $where
69
     * @param array $group
70
     * @param array $order
71
     * @param int $limit
72
     * @param int $page
73
     */
74
    public function __construct(string $table, array $fields, array $where,
75
        array $group, array $order = [], int $limit = 1, int $page = 0)
76
    {
77
        $this->table = $table;
78
        $this->fields = $fields;
79
        $this->where = $where;
80
        $this->group = $group;
81
        $this->order = $order;
82
        $this->limit = $limit;
83
        $this->page = $page;
84
        if (!empty($where)) {
85
            $this->clauses = ' WHERE ' . \implode(' AND ', $where);
86
        }
87
        if (!empty($group) && count($group) < count($fields)) {
88
            $this->clauses .= ' GROUP BY ' . \implode(', ', $group);
89
        }
90
        if (!empty($order)) {
91
            $this->clauses .= ' ORDER BY ' . \implode(', ', $order);
92
        }
93
    }
94
}
95