Failed Conditions
Push — refactor/improve-static-analys... ( bdf823...46faab )
by Bas
10:08
created

BuildsSubqueries::parseSub()   B

Complexity

Conditions 9
Paths 5

Size

Total Lines 24
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 13.608

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 12
c 2
b 0
f 0
dl 0
loc 24
ccs 8
cts 13
cp 0.6153
rs 8.0555
cc 9
nc 5
nop 1
crap 13.608
1
<?php
2
3
namespace LaravelFreelancerNL\Aranguent\Query\Concerns;
4
5
use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
6
use Illuminate\Database\Eloquent\Relations\Relation;
7
use Illuminate\Database\Query\Builder as IlluminateQueryBuilder;
8
use InvalidArgumentException;
9
use LaravelFreelancerNL\Aranguent\Query\Builder;
10
use LaravelFreelancerNL\FluentAQL\Expressions\FunctionExpression;
11
use LaravelFreelancerNL\FluentAQL\QueryBuilder;
12
13
trait BuildsSubqueries
14
{
15
    protected function hasLimitOfOne(IlluminateQueryBuilder $query)
16
    {
17
        if (isset($query->limit) && $query->limit == 1) {
18
            return true;
19
        }
20
21
        return false;
22 1
    }
23
24 1
    /**
25
     * Parse the subquery into SQL and bindings.
26
     *
27 1
     * @param  Builder|EloquentBuilder|Relation|QueryBuilder|FunctionExpression|string  $query
28
     * @return array<mixed>|QueryBuilder
29
     *
30 1
     * @throws \InvalidArgumentException
31
     */
32
    //    protected function parseSub($query)
33 1
    //    {
34
    //        if ($query instanceof self || $query instanceof EloquentBuilder || $query instanceof Relation) {
35 1
    //            $query = $this->prependDatabaseNameIfCrossDatabaseQuery($query);
36
    //            $query->grammar->compileSelect($query);
37
    //
38
    //            if (isset($query->limit) && $query->limit == 1) {
39
    //                //Return the value, not an array of values
40
    //                /** @phpstan-ignore-next-line */
41
    //                return $query->aqb->first($query->aqb);
42
    //            }
43
    //
44
    //            return $query->aqb;
45
    //        }
46 2
    //
47
    //        if ($query instanceof QueryBuilder || $query instanceof FunctionExpression) {
48 2
    //            return $query;
49 1
    //        }
50 1
    //
51
    //        if (is_string($query)) {
52 1
    //            return $query;
53
    //        }
54
    //
55 1
    //        throw new InvalidArgumentException(
56
    //            'A subquery must be a query builder instance, a Closure, or a string.'
57
    //        );
58
    //    }
59
}
60