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

QueryBuilder::__call()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 2
Metric Value
cc 1
eloc 3
c 2
b 0
f 2
nc 1
nop 2
dl 0
loc 6
rs 9.4285
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