Completed
Push — master ( 5649ba...c37d73 )
by recca
03:09
created

Criteria::toArray()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 6
nc 1
nop 0
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
ccs 2
cts 2
cp 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
    public static function create()
27
    {
28
        return new static();
29
    }
30
31
    /**
32
     * alias raw.
33
     *
34
     * @param mixed $value
35
     * @return Expression
36
     */
37
    public static function expr($value)
38
    {
39
        return static::raw($value);
40
    }
41
42
    /**
43
     * @param mixed $value
44
     * @return \Recca0120\Repository\Expression
45 25
     */
46
    public static function raw($value)
47 25
    {
48 24
        return new Expression($value);
49
    }
50 24
51
    /**
52
     * each.
53 1
     *
54
     * @param  Closure $callback
55
     * @return void
56
     */
57
    public function each(Closure $callback)
58
    {
59
        foreach ($this->methods as $method) {
60
            $callback($method);
61
        }
62
    }
63 1
64
    /**
65 1
     * toArray.
66
     *
67 1
     * @return array
68
     */
69
    public function toArray()
70
    {
71
        return array_map(function ($method) {
72
            return [
73
                'method' => $method->name,
74
                'parameters' => $method->parameters,
75 22
            ];
76
        }, $this->methods);
77 22
    }
78
}
79