Test Failed
Push — feature-laravel-5.4 ( 6f3b9a...66d75b )
by Kirill
03:40
created

AbstractQuery::args()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 0
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
1
<?php
2
/**
3
 * This file is part of laravel.su package.
4
 * For the full copyright and license information, please view the LICENSE
5
 * file that was distributed with this source code.
6
 */
7
declare(strict_types=1);
8
9
namespace App\GraphQL\Queries;
10
11
use Folklore\GraphQL\Support\Query;
12
use App\GraphQL\Queries\Support\QueryLimit;
13
use App\GraphQL\Queries\Support\WhereInSelection;
14
use Illuminate\Database\Eloquent\Builder;
15
use Illuminate\Database\Eloquent\Model;
16
17
/**
18
 * Class AbstractQuery.
19
 */
20
abstract class AbstractQuery extends Query
21
{
22
    use QueryLimit;
23
    use WhereInSelection;
24
25
    /**
26
     * @return array
27
     */
28
    final public function args(): array
29
    {
30
        $args = $this->queryArguments();
31
32
        $args = $this->argumentsWithLimit($args);
33
        $args = $this->argumentsWithWhereIn($args);
34
35
        return $args;
36
    }
37
38
    /**
39
     * @return array
40
     */
41
    abstract protected function queryArguments(): array;
42
43
    /**
44
     * @param string $model
45
     * @param array  $args
46
     * @return Builder|Model <T>
47
     * @internal param $ string|Model|Model<T> $model
48
     */
49
    protected function queryFor(string $model, array $args = []): Builder
50
    {
51
        $query = $model::query();
52
53
        $query = $this->queryWithLimit($query, $args);
54
        $query = $this->queryWithWhereIn($query, $args);
55
56
        foreach ($args as $field => $value) {
57
            $query = $query->where($field, $value);
58
        }
59
60
        return $query;
61
    }
62
}