EloquentPageRepository   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 4
Bugs 0 Features 1
Metric Value
wmc 4
c 4
b 0
f 1
lcom 0
cbo 2
dl 0
loc 47
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A findHomepage() 0 4 1
A countAll() 0 4 1
A create() 0 8 1
A update() 0 8 1
1
<?php namespace Modules\Page\Repositories\Eloquent;
2
3
use Modules\Core\Repositories\Eloquent\EloquentBaseRepository;
4
use Modules\Page\Events\PageWasCreated;
5
use Modules\Page\Events\PageWasUpdated;
6
use Modules\Page\Repositories\PageRepository;
7
8
class EloquentPageRepository extends EloquentBaseRepository implements PageRepository
9
{
10
    /**
11
     * Find the page set as homepage
12
     * @return object
13
     */
14
    public function findHomepage()
15
    {
16
        return $this->model->where('is_home', 1)->first();
17
    }
18
19
    /**
20
     * Count all records
21
     * @return int
22
     */
23
    public function countAll()
24
    {
25
        return $this->model->count();
26
    }
27
28
    /**
29
     * @param  mixed  $data
30
     * @return object
31
     */
32
    public function create($data)
33
    {
34
        $page = $this->model->create($data);
35
36
        event(new PageWasCreated($page->id, $data));
37
38
        return $page;
39
    }
40
41
    /**
42
     * @param $model
43
     * @param  array  $data
44
     * @return object
45
     */
46
    public function update($model, $data)
47
    {
48
        $model->update($data);
49
50
        event(new PageWasUpdated($model->id, $data));
51
52
        return $model;
53
    }
54
}
55