Issues (97)

src/Relations/Postgres/HasOneOrMany.php (9 issues)

1
<?php
2
3
namespace Staudenmeir\EloquentJsonRelations\Relations\Postgres;
4
5
use Illuminate\Database\Eloquent\Builder;
6
7
trait HasOneOrMany
8
{
9
    use IsPostgresRelation;
10
11
    /**
12
     * Add the constraints for a relationship query.
13
     *
14
     * @param \Illuminate\Database\Eloquent\Builder $query
15
     * @param \Illuminate\Database\Eloquent\Builder $parentQuery
16
     * @param array|mixed $columns
17
     * @return \Illuminate\Database\Eloquent\Builder
18
     */
19
    public function getRelationExistenceQuery(Builder $query, Builder $parentQuery, $columns = ['*'])
20
    {
21
        if ($query->getQuery()->from == $parentQuery->getQuery()->from) {
22
            return $this->getRelationExistenceQueryForSelfRelation($query, $parentQuery, $columns);
23
        }
24
25
        $second = $this->jsonColumn($query, $this->parent, $this->getExistenceCompareKey(), $this->localKey);
0 ignored issues
show
It seems like getExistenceCompareKey() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

25
        $second = $this->jsonColumn($query, $this->parent, $this->/** @scrutinizer ignore-call */ getExistenceCompareKey(), $this->localKey);
Loading history...
26
27
        return $query->select($columns)->whereColumn(
0 ignored issues
show
Bug Best Practice introduced by
The expression return $query->select($c...eyName(), '=', $second) also could return the type Illuminate\Database\Query\Builder which is incompatible with the documented return type Illuminate\Database\Eloquent\Builder.
Loading history...
28
            $this->getQualifiedParentKeyName(),
0 ignored issues
show
It seems like getQualifiedParentKeyName() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

28
            $this->/** @scrutinizer ignore-call */ 
29
                   getQualifiedParentKeyName(),
Loading history...
29
            '=',
30
            $second
0 ignored issues
show
$second of type Illuminate\Database\Query\Expression is incompatible with the type null|string expected by parameter $second of Illuminate\Database\Query\Builder::whereColumn(). ( Ignorable by Annotation )

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

30
            /** @scrutinizer ignore-type */ $second
Loading history...
31
        );
32
    }
33
34
    /**
35
     * Add the constraints for a relationship query on the same table.
36
     *
37
     * @param \Illuminate\Database\Eloquent\Builder $query
38
     * @param \Illuminate\Database\Eloquent\Builder $parentQuery
39
     * @param array|mixed $columns
40
     * @return \Illuminate\Database\Eloquent\Builder
41
     */
42
    public function getRelationExistenceQueryForSelfRelation(Builder $query, Builder $parentQuery, $columns = ['*'])
0 ignored issues
show
The parameter $parentQuery is not used and could be removed. ( Ignorable by Annotation )

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

42
    public function getRelationExistenceQueryForSelfRelation(Builder $query, /** @scrutinizer ignore-unused */ Builder $parentQuery, $columns = ['*'])

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
43
    {
44
        $query->from($query->getModel()->getTable().' as '.$hash = $this->getRelationCountHash());
0 ignored issues
show
It seems like getRelationCountHash() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

44
        $query->from($query->getModel()->getTable().' as '.$hash = $this->/** @scrutinizer ignore-call */ getRelationCountHash());
Loading history...
45
46
        $query->getModel()->setTable($hash);
47
48
        $second = $this->jsonColumn($query, $this->parent, $hash.'.'.$this->getForeignKeyName(), $this->localKey);
0 ignored issues
show
It seems like getForeignKeyName() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

48
        $second = $this->jsonColumn($query, $this->parent, $hash.'.'.$this->/** @scrutinizer ignore-call */ getForeignKeyName(), $this->localKey);
Loading history...
49
50
        return $query->select($columns)->whereColumn(
0 ignored issues
show
Bug Best Practice introduced by
The expression return $query->select($c...eyName(), '=', $second) also could return the type Illuminate\Database\Query\Builder which is incompatible with the documented return type Illuminate\Database\Eloquent\Builder.
Loading history...
51
            $this->getQualifiedParentKeyName(),
52
            '=',
53
            $second
0 ignored issues
show
$second of type Illuminate\Database\Query\Expression is incompatible with the type null|string expected by parameter $second of Illuminate\Database\Query\Builder::whereColumn(). ( Ignorable by Annotation )

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

53
            /** @scrutinizer ignore-type */ $second
Loading history...
54
        );
55
    }
56
}
57