Passed
Push — 2.0 ( 3cd779...fe8057 )
by Kirill
03:09
created

AbstractQuery::whenExists()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 3
dl 0
loc 8
rs 9.4285
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\Kernel\HasValidation;
13
use Illuminate\Database\Eloquent\Model;
14
use App\GraphQL\Kernel\AttributeExists;
15
use Illuminate\Database\Eloquent\Builder;
16
17
/**
18
 * Class AbstractQuery.
19
 */
20
abstract class AbstractQuery extends Query
21
{
22
    use AttributeExists;
23
    use HasValidation;
24
25
    /**
26
     * @return array
27
     */
28
    public function args(): array
29
    {
30
        return $this->queryArguments();
31
    }
32
33
    /**
34
     * @return array
35
     */
36
    abstract protected function queryArguments(): array;
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
        foreach ($args as $field => $value) {
49
            $query = $query->where($field, $value);
50
        }
51
52
        return $query;
53
    }
54
}
55