Completed
Branch master (162e0f)
by Evan
02:29
created

QueryBuilder   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 3
Bugs 0 Features 2
Metric Value
c 3
b 0
f 2
dl 0
loc 49
rs 10
wmc 3
lcom 0
cbo 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
newQuery() 0 1 ?
A query() 0 4 1
A __callStatic() 0 4 1
A __call() 0 6 1
1
<?php
2
3
namespace Silk\Query;
4
5
use Silk\Contracts\BuildsQueries;
6
7
trait QueryBuilder
8
{
9
    /**
10
     * Get a new query builder for the model.
11
     *
12
     * @return BuildsQueries
13
     */
14
    abstract public function newQuery();
15
16
    /**
17
     * Create a new query builder instance for this model type.
18
     *
19
     * @return BuildsQueries
20
     */
21
    public static function query()
22
    {
23
        return (new static)->newQuery();
24
    }
25
26
    /**
27
     * Handle dynamic static method calls on the model class.
28
     *
29
     * Proxies calls to direct method calls on a new instance
30
     *
31
     * @param string $method
32
     * @param array $arguments
33
     *
34
     * @return mixed
35
     */
36
    public static function __callStatic($method, array $arguments)
37
    {
38
        return call_user_func_array([new static, $method], $arguments);
39
    }
40
41
    /**
42
     * Handle dynamic method calls into the model.
43
     *
44
     * @param  string $method
45
     * @param  array $arguments
46
     *
47
     * @return mixed
48
     */
49
    public function __call($method, $arguments)
50
    {
51
        $query = $this->newQuery();
52
53
        return call_user_func_array([$query, $method], $arguments);
54
    }
55
}
56