GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

Subquery   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 129
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
dl 0
loc 129
rs 10
c 0
b 0
f 0
wmc 11
lcom 1
cbo 4

9 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 10 2
A setQuery() 0 4 1
A getQuery() 0 4 1
A getValue() 0 12 2
A getAlias() 0 4 1
A setAlias() 0 6 1
A __set() 0 4 1
A __get() 0 4 1
A __call() 0 4 1
1
<?php
2
3
namespace Sofa\Eloquence;
4
5
use Illuminate\Database\Query\Expression;
6
use Illuminate\Database\Query\Builder as QueryBuilder;
7
use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
8
9
/**
10
 * @mixin QueryBuilder
11
 */
12
class Subquery extends Expression
13
{
14
    /**
15
     * Query builder instance.
16
     *
17
     * @var QueryBuilder
18
     */
19
    protected $query;
20
21
    /**
22
     * Alias for the subquery.
23
     *
24
     * @var string
25
     */
26
    protected $alias;
27
28
    /**
29
     * Create new subquery instance.
30
     *
31
     * @param QueryBuilder|EloquentBuilder
32
     * @param string $alias
33
     */
34
    public function __construct($query, $alias = null)
35
    {
36
        if ($query instanceof EloquentBuilder) {
37
            $query = $query->getQuery();
38
        }
39
40
        $this->setQuery($query);
41
42
        $this->alias = $alias;
43
    }
44
45
    /**
46
     * Set underlying query builder.
47
     *
48
     * @param QueryBuilder $query
49
     */
50
    public function setQuery(QueryBuilder $query)
51
    {
52
        $this->query = $query;
53
    }
54
55
    /**
56
     * Get underlying query builder.
57
     *
58
     * @return QueryBuilder
59
     */
60
    public function getQuery()
61
    {
62
        return $this->query;
63
    }
64
65
    /**
66
     * Evaluate query as string.
67
     *
68
     * @return string
69
     */
70
    public function getValue()
71
    {
72
        $sql = '(' . $this->query->toSql() . ')';
73
74
        if ($this->alias) {
75
            $alias = $this->query->getGrammar()->wrapTable($this->alias);
76
77
            $sql .= ' as ' . $alias;
78
        }
79
80
        return $sql;
81
    }
82
83
    /**
84
     * Get subquery alias.
85
     *
86
     * @return string
87
     */
88
    public function getAlias()
89
    {
90
        return $this->alias;
91
    }
92
93
    /**
94
     * Set subquery alias.
95
     *
96
     * @param  string $alias
97
     * @return $this
98
     */
99
    public function setAlias($alias)
100
    {
101
        $this->alias = $alias;
102
103
        return $this;
104
    }
105
106
    /**
107
     * Pass property calls to the underlying builder.
108
     *
109
     * @param  string $property
110
     * @param  mixed  $value
111
     * @return mixed
112
     */
113
    public function __set($property, $value)
114
    {
115
        return $this->query->{$property} = $value;
116
    }
117
118
    /**
119
     * Pass property calls to the underlying builder.
120
     *
121
     * @param  string $property
122
     * @return mixed
123
     */
124
    public function __get($property)
125
    {
126
        return $this->query->{$property};
127
    }
128
129
    /**
130
     * Pass method calls to the underlying builder.
131
     *
132
     * @param  string $method
133
     * @param  array  $params
134
     * @return mixed
135
     */
136
    public function __call($method, $params)
137
    {
138
        return call_user_func_array([$this->query, $method], $params);
139
    }
140
}
141