Completed
Push — 2.0 ( d39b3c...f2914f )
by Kirill
02:52
created

AbstractQuery   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 38
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
dl 38
loc 38
rs 10
c 0
b 0
f 0
wmc 3
lcom 0
cbo 3

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 5 5 1
A args() 4 4 1
queryArguments() 1 1 ?
A queryFor() 4 4 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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 Illuminate\Database\Eloquent\Model;
13
use Illuminate\Database\Eloquent\Builder;
14
use App\GraphQL\Queries\Support\HasValidation;
15
use App\GraphQL\Feature\Kernel\FeaturesSupport;
16
17
/**
18
 * Class AbstractQuery.
19
 */
20 View Code Duplication
abstract class AbstractQuery extends Query
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
21
{
22
    use HasValidation;
23
    use FeaturesSupport;
24
25
    /**
26
     * AbstractQuery constructor.
27
     * @param array $attributes
28
     */
29
    public function __construct($attributes = [])
30
    {
31
        $this->boot();
32
        parent::__construct($attributes);
33
    }
34
35
    /**
36
     * @return array
37
     */
38
    public function args(): array
39
    {
40
        return $this->extendArguments($this->queryArguments());
41
    }
42
43
    /**
44
     * @return array
45
     */
46
    abstract protected function queryArguments(): array;
47
48
    /**
49
     * @param string|Model $model
50
     * @param array  $args
51
     * @return Builder|Model <T>
52
     */
53
    protected function queryFor(string $model, array $args = []): Builder
54
    {
55
        return $this->extendQuery($model::query(), $args);
56
    }
57
}
58