CRUD::setModel()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 5
rs 10
ccs 3
cts 3
cp 1
crap 1
1
<?php
2
3
namespace Yaro\Jarboe\Table;
4
5
use Yaro\Jarboe\Table\Actions\ActionsContainer;
6
use Yaro\Jarboe\Table\CrudTraits\BatchCheckboxesTrait;
7
use Yaro\Jarboe\Table\CrudTraits\ColumnsAndFieldsTrait;
8
use Yaro\Jarboe\Table\CrudTraits\FormClassTrait;
9
use Yaro\Jarboe\Table\CrudTraits\LocalesTrait;
10
use Yaro\Jarboe\Table\CrudTraits\PaginateTrait;
11
use Yaro\Jarboe\Table\CrudTraits\PreferencesHelperTrait;
12
use Yaro\Jarboe\Table\CrudTraits\RowAttributesTrait;
13
use Yaro\Jarboe\Table\CrudTraits\SoftDeleteTrait;
14
use Yaro\Jarboe\Table\CrudTraits\SortableWeightTrait;
15
use Yaro\Jarboe\Table\CrudTraits\TabsTrait;
16
use Yaro\Jarboe\Table\CrudTraits\ToolbarTrait;
17
use Yaro\Jarboe\Table\CrudTraits\UrlTrait;
18
use Yaro\Jarboe\Table\Repositories\ModelRepositoryInterface;
19
use Yaro\Jarboe\Table\Repositories\PreferencesRepository;
20
21
class CRUD
22
{
23
    use BatchCheckboxesTrait;
24
    use ColumnsAndFieldsTrait;
25
    use FormClassTrait;
26
    use LocalesTrait;
27
    use PaginateTrait;
28
    use PreferencesHelperTrait;
29
    use SoftDeleteTrait;
30
    use SortableWeightTrait;
31
    use TabsTrait;
32
    use ToolbarTrait;
33
    use UrlTrait;
34
    use RowAttributesTrait;
35
36
    const BASE_URL_DELIMITER = '/~/';
37
38
    private $model = '';
39
    private $repo;
40
    private $preferences;
41
    private $actions;
42
43 115
    public function __construct(ModelRepositoryInterface $repo, PreferencesRepository $preferences, ActionsContainer $actions)
44
    {
45 115
        $this->repo = $repo;
46 115
        $this->preferences = $preferences;
47 115
        $this->actions = $actions;
48 115
    }
49
50 58
    public function setModel($model)
51
    {
52 58
        $this->model = $model;
53
54 58
        return $this;
55
    }
56
57 60
    public function repo(): ModelRepositoryInterface
58
    {
59 60
        $this->repo->setCrud($this);
60
61 60
        return $this->repo;
62
    }
63
64 10
    public function preferences()
65
    {
66 10
        return $this->preferences;
67
    }
68
69
    public function order(string $column, string $direction)
70
    {
71
        $this->repo()->order($column, $direction);
72
73
        return $this;
74
    }
75
76 58
    public function filter(\Closure $callback)
77
    {
78 58
        $this->repo()->filter($callback);
79
80 58
        return $this;
81
    }
82
83 58
    public function getModel()
84
    {
85 58
        return $this->model;
86
    }
87
88 79
    public function actions()
89
    {
90 79
        return $this->actions;
91
    }
92
}
93