Completed
Branch master (fafb06)
by Nate
04:30
created

Domains   A

Complexity

Total Complexity 17

Size/Duplication

Total Lines 186
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 17
lcom 1
cbo 4
dl 0
loc 186
ccs 0
cts 77
cp 0
rs 10
c 0
b 0
f 0

12 Methods

Rating   Name   Duplication   Size   Complexity  
A getQuery() 0 4 1
A findAll() 0 4 1
A find() 0 4 1
A get() 0 8 2
A findByCondition() 0 7 1
A getByCondition() 0 8 2
A findByCriteria() 0 8 1
A getByCriteria() 0 8 2
A findAllByCondition() 0 7 1
A getAllByCondition() 0 9 2
A findAllByCriteria() 0 8 1
A getAllByCriteria() 0 9 2
1
<?php
2
3
/**
4
 * @copyright  Copyright (c) Flipbox Digital Limited
5
 * @license    https://flipboxfactory.com/software/domains/license
6
 * @link       https://www.flipboxfactory.com/software/domains/
7
 */
8
9
namespace flipbox\domains\services;
10
11
use flipbox\domains\db\DomainsQuery;
12
use flipbox\domains\fields\Domains as DomainsField;
13
use flipbox\ember\exceptions\NotFoundException;
14
use flipbox\ember\helpers\RecordHelper;
15
use flipbox\ember\services\traits\queries\BaseAccessor;
16
use yii\base\Component;
17
use yii\db\QueryInterface;
18
19
/**
20
 * @author Flipbox Factory <[email protected]>
21
 * @since 1.0.0
22
 */
23
class Domains extends Component
24
{
25
    use BaseAccessor;
26
27
    /**
28
     * @param DomainsField $field
29
     * @inheritdoc
30
     */
31
    public function getQuery(DomainsField $field, $config = []): QueryInterface
32
    {
33
        return new DomainsQuery($field, $config);
34
    }
35
36
    /*******************************************
37
     * FIND / GET
38
     *******************************************/
39
40
    /**
41
     * @param DomainsField $field
42
     * @return array[]
43
     */
44
    public function findAll(DomainsField $field)
45
    {
46
        return $this->findAllByCondition($field, null);
0 ignored issues
show
Documentation introduced by
null is of type null, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
47
    }
48
49
    /**
50
     * @param DomainsField $field
51
     * @param $identifier
52
     * @return mixed|null
53
     */
54
    public function find(DomainsField $field, $identifier)
55
    {
56
        return $this->findByCondition($field, $identifier);
57
    }
58
59
    /**
60
     * @param DomainsField $field
61
     * @param $identifier
62
     * @return mixed
63
     * @throws NotFoundException
64
     */
65
    public function get(DomainsField $field, $identifier)
66
    {
67
        if (null === ($object = $this->find($field, $identifier))) {
68
            $this->notFoundException();
69
        }
70
71
        return $object;
72
    }
73
74
75
    /*******************************************
76
     * ONE CONDITION
77
     *******************************************/
78
79
    /**
80
     * @param DomainsField $field
81
     * @param $condition
82
     * @return mixed|null
83
     */
84
    public function findByCondition(DomainsField $field, $condition)
85
    {
86
        return $this->findByCriteria(
87
            $field,
88
            RecordHelper::conditionToCriteria($condition)
89
        );
90
    }
91
92
    /**
93
     * @param DomainsField $field
94
     * @param $condition
95
     * @return mixed
96
     * @throws NotFoundException
97
     */
98
    public function getByCondition(DomainsField $field, $condition)
99
    {
100
        if (null === ($object = $this->findByCondition($field, $condition))) {
101
            $this->notFoundException();
102
        }
103
104
        return $object;
105
    }
106
107
108
    /*******************************************
109
     * ONE CRITERIA
110
     *******************************************/
111
112
    /**
113
     * @param DomainsField $field
114
     * @param $criteria
115
     * @return mixed|null
116
     */
117
    public function findByCriteria(DomainsField $field, $criteria)
118
    {
119
        $object = $this->findByQuery(
120
            $this->getQuery($field, $criteria)
121
        );
122
123
        return $object;
124
    }
125
126
    /**
127
     * @param DomainsField $field
128
     * @param $criteria
129
     * @return mixed
130
     * @throws NotFoundException
131
     */
132
    public function getByCriteria(DomainsField $field, $criteria)
133
    {
134
        if (null === ($record = $this->findByCriteria($field, $criteria))) {
135
            $this->notFoundException();
136
        }
137
138
        return $record;
139
    }
140
141
142
    /*******************************************
143
     * ALL CONDITION
144
     *******************************************/
145
146
    /**
147
     * @param DomainsField $field
148
     * @param array $condition
149
     * @return array
150
     */
151
    public function findAllByCondition(DomainsField $field, $condition = []): array
152
    {
153
        return $this->findAllByCriteria(
154
            $field,
155
            RecordHelper::conditionToCriteria($condition)
156
        );
157
    }
158
159
    /**
160
     * @param DomainsField $field
161
     * @param array $condition
162
     * @return array
163
     * @throws NotFoundException
164
     */
165
    public function getAllByCondition(DomainsField $field, $condition = []): array
166
    {
167
        $records = $this->findAllByCondition($field, $condition);
168
        if (empty($records)) {
169
            $this->notFoundException();
170
        }
171
172
        return $records;
173
    }
174
175
    /*******************************************
176
     * ALL CRITERIA
177
     *******************************************/
178
179
    /**
180
     * @param DomainsField $field
181
     * @param array $criteria
182
     * @return array
183
     */
184
    public function findAllByCriteria(DomainsField $field, $criteria = []): array
185
    {
186
        $records = $this->findAllByQuery(
187
            $this->getQuery($field, $criteria)
188
        );
189
190
        return $records;
191
    }
192
193
    /**
194
     * @param DomainsField $field
195
     * @param array $criteria
196
     * @return array
197
     * @throws NotFoundException
198
     */
199
    public function getAllByCriteria(DomainsField $field, $criteria = []): array
200
    {
201
        $records = $this->findAllByCriteria($field, $criteria);
202
        if (empty($records)) {
203
            $this->notFoundException();
204
        }
205
206
        return $records;
207
    }
208
}
209