IsConcatenableRelation   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
dl 0
loc 32
rs 10
c 1
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A mergeWhereConstraints() 0 9 1
A addEagerConstraintsToDeepRelationship() 0 5 1
1
<?php
2
3
namespace Staudenmeir\EloquentJsonRelations\Relations\Traits\Concatenation;
4
5
use Illuminate\Database\Eloquent\Builder;
6
7
trait IsConcatenableRelation
8
{
9
    /**
10
     * Set the constraints for an eager load of the deep relation.
11
     *
12
     * @param \Illuminate\Database\Eloquent\Builder $query
13
     * @param array $models
14
     * @return void
15
     */
16
    public function addEagerConstraintsToDeepRelationship(Builder $query, array $models): void
17
    {
18
        $this->addEagerConstraints($models);
0 ignored issues
show
Bug introduced by
The method addEagerConstraints() does not exist on Staudenmeir\EloquentJson...\IsConcatenableRelation. Did you maybe mean addEagerConstraintsToDeepRelationship()? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

18
        $this->/** @scrutinizer ignore-call */ 
19
               addEagerConstraints($models);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
19
20
        $this->mergeWhereConstraints($query, $this->query);
21
    }
22
23
    /**
24
     * Merge the where constraints from another query to the current query.
25
     *
26
     * @param \Illuminate\Database\Eloquent\Builder $query
27
     * @param \Illuminate\Database\Eloquent\Builder $from
28
     * @return \Illuminate\Database\Eloquent\Builder
29
     */
30
    public function mergeWhereConstraints(Builder $query, Builder $from): Builder
31
    {
32
        $whereBindings = $from->getQuery()->getRawBindings()['where'] ?? [];
33
34
        $wheres = $from->getQuery()->wheres;
35
36
        return $query->withoutGlobalScopes(
0 ignored issues
show
Bug Best Practice introduced by
The expression return $query->withoutGl...wheres, $whereBindings) could return the type Illuminate\Database\Query\Builder which is incompatible with the type-hinted return Illuminate\Database\Eloquent\Builder. Consider adding an additional type-check to rule them out.
Loading history...
37
            $from->removedScopes()
38
        )->mergeWheres($wheres, $whereBindings);
39
    }
40
}
41