Completed
Push — master ( 2b6664...374d4a )
by recca
01:56
created

AbstractRepository::chunk()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 3
cts 3
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 3
crap 1
1
<?php
2
3
namespace Recca0120\Repository;
4
5
use Recca0120\Repository\Contracts\Repository as RepositoryContract;
6
7
abstract class AbstractRepository implements RepositoryContract
8
{
9
    /**
10
     * $model.
11
     *
12
     * @var mixed
13
     */
14
    protected $model;
15
16
    /**
17
     * $transform.
18
     *
19
     * @var string
20
     */
21
    protected $compiler;
22
23
    /**
24
     * $perPage.
25
     *
26
     * @var int
27
     */
28
    public $perPage = 15;
29
30
    /**
31
     * cloneModel.
32
     *
33
     * @return \Illuminate\Database\Eloquent
34
     */
35 28
    public function cloneModel()
36
    {
37 28
        return clone $this->model;
38
    }
39
40
    /**
41
     * match.
42
     *
43
     * @param Criteria|array $criteria
44
     * @return \Illuminate\Database\Eloquent\Collection|\Illuminate\Support\Collection
45
     */
46 20
    public function match($criteria)
47
    {
48 20
        $model = $this->cloneModel();
49 20
        $class = $this->compiler;
50 20
        $compiler = new $class($model);
51
52 20
        return $compiler->push($criteria)->apply();
53
    }
54
55
    /**
56
     * count.
57
     *
58
     * @param Criteria|array $criteria
59
     * @return int
60
     */
61 2
    public function count($criteria = [])
62
    {
63 2
        $model = $this->match($criteria);
64
65 2
        return $model->count();
66
    }
67
}
68