Completed
Push — master ( c37d73...04c6f6 )
by recca
01:30
created

Criteria::expr()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Recca0120\Repository;
4
5
use Closure;
6
7
class Criteria
8
{
9
    use Concerns\BuildsQueries,
10
        Concerns\QueriesRelationships,
11
        Concerns\EloquentBuildsQueries,
12
        Concerns\SoftDeletingScope;
13
14
    /**
15
     * $methods.
16
     *
17
     * @var \Recca0120\Repository\Method[]
18
     */
19
    protected $methods = [];
20
21
    /**
22
     * create.
23
     *
24
     * @return static
25
     */
26 100
    public static function create()
27
    {
28 100
        return new static();
29
    }
30
31
    /**
32
     * alias raw.
33
     *
34
     * @param mixed $value
35
     * @return Expression
36
     */
37 2
    public static function expr($value)
38
    {
39 2
        return static::raw($value);
40
    }
41
42
    /**
43
     * @param mixed $value
44
     * @return \Recca0120\Repository\Expression
45
     */
46 3
    public static function raw($value)
47
    {
48 3
        return new Expression($value);
49
    }
50
51
    /**
52
     * each.
53
     *
54
     * @param  Closure $callback
55
     * @return void
56
     */
57 14
    public function each(Closure $callback)
58
    {
59 14
        foreach ($this->methods as $method) {
60 14
            $callback($method);
61
        }
62 14
    }
63
64
    /**
65
     * toArray.
66
     *
67
     * @return array
68
     */
69
    public function toArray()
70
    {
71 85
        return array_map(function ($method) {
72
            return [
73 85
                'method' => $method->name,
74 85
                'parameters' => $method->parameters,
75
            ];
76 85
        }, $this->methods);
77
    }
78
}
79