Completed
Push — 2.0 ( b567d9...afe19a )
by Kirill
02:58
created

AbstractCollectionQuery::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 Illuminate\Database\Eloquent\Builder;
12
use App\GraphQL\Queries\Support\QueryLimit;
13
use App\GraphQL\Queries\Support\WhereInSelection;
14
use Illuminate\Database\Eloquent\Model;
15
16
/**
17
 * Class AbstractCollectionQuery
18
 * @package App\GraphQL\Queries
19
 */
20
abstract class AbstractCollectionQuery extends AbstractQuery
21
{
22
    use QueryLimit;
23
    use WhereInSelection;
24
25
    /**
26
     * @return array
27
     */
28
    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
     * @param string $model
40
     * @param array  $args
41
     * @return Builder|Model <T>
42
     * @internal param $ string|Model|Model<T> $model
43
     */
44
    protected function queryFor(string $model, array $args = []): Builder
45
    {
46
        $query = $model::query();
47
48
        $query = $this->queryWithLimit($query, $args);
49
        $query = $this->queryWithWhereIn($query, $args);
50
51
        foreach ($args as $field => $value) {
52
            $query = $query->where($field, $value);
53
        }
54
55
        return $query;
56
    }
57
}