Test Failed
Branch master (a0b8e2)
by Konstantin
02:59
created

AbstractDatabaseQuery   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 100
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 7
c 1
b 0
f 1
lcom 1
cbo 3
dl 0
loc 100
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A firstLetters() 0 6 1
A regionCode() 0 6 1
A parentId() 0 6 1
A findAll() 0 4 1
A findOne() 0 4 1
A kladrCode() 0 6 1
1
<?php
2
3
namespace GeoFixer\models\queries;
4
5
use Cake\Database\Connection;
6
use GeoFixer\models\DatabaseConnection;
7
8
/**
9
 * Class AbstractDatabaseQuery
10
 *
11
 * @package GeoFixer\models\queries
12
 */
13
class AbstractDatabaseQuery
14
{
15
    /**
16
     * Address levels в базе ФИАС
17
     */
18
    const CITY = 4;
19
    const SETTLEMENT = 6;
20
    const STREET = 7;
21
22
    /**
23
     * @var Connection::newQuery()
24
     */
25
    protected $db;
26
27
    /**
28
     * AbstractDatabaseQuery constructor.
29
     *
30
     * @uses Connection::newQuery()
31
     */
32
    public function __construct()
33
    {
34
        $this->db = DatabaseConnection::connection()->newQuery();
35
    }
36
37
    /**
38
     * Первые буквы равны
39
     *
40
     * @param $letters
41
     *
42
     * @return $this
43
     */
44
    public function firstLetters($letters)
45
    {
46
        $this->db = $this->db->andWhere(['title LIKE' => $letters . '%']);
47
48
        return $this;
49
    }
50
51
    /**
52
     * Код региона равен
53
     *
54
     * @param $code
55
     *
56
     * @return $this
57
     */
58
    public function regionCode($code)
59
    {
60
        $this->db = $this->db->andWhere(['region_code' => $code]);
61
62
        return $this;
63
    }
64
65
    /**
66
     * Код КЛАДР равен
67
     *
68
     * @param $code
69
     *
70
     * @return $this
71
     */
72
    public function kladrCode($code)
73
    {
74
        $this->db = $this->db->andWhere(['code' => $code]);
75
76
        return $this;
77
    }
78
79
    /**
80
     * ID родителя равен
81
     *
82
     * @param $id
83
     *
84
     * @return $this
85
     */
86
    public function parentId($id)
87
    {
88
        $this->db = $this->db->andWhere(['parent_id' => $id]);
89
90
        return $this;
91
    }
92
93
    /**
94
     * Получаем массив значений
95
     *
96
     * @return array
97
     */
98
    public function findAll()
99
    {
100
        return $this->db->execute()->fetchAll('assoc');
101
    }
102
103
    /**
104
     * Получаем одно значение
105
     *
106
     * @return array
107
     */
108
    public function findOne()
109
    {
110
        return $this->db->execute()->fetch('assoc');
111
    }
112
}