EloquentMenuRepository   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 32
Duplicated Lines 28.13 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 4
Bugs 0 Features 1
Metric Value
wmc 3
c 4
b 0
f 1
lcom 1
cbo 3
dl 9
loc 32
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A create() 0 8 1
A update() 0 6 1
A allOnline() 9 9 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php namespace Modules\Menu\Repositories\Eloquent;
2
3
use Illuminate\Database\Eloquent\Builder;
4
use Illuminate\Support\Facades\App;
5
use Modules\Core\Repositories\Eloquent\EloquentBaseRepository;
6
use Modules\Menu\Events\MenuWasCreated;
7
use Modules\Menu\Repositories\MenuRepository;
8
9
class EloquentMenuRepository extends EloquentBaseRepository implements MenuRepository
10
{
11
    public function create($data)
12
    {
13
        $menu = $this->model->create($data);
14
15
        event(new MenuWasCreated($menu));
16
17
        return $menu;
18
    }
19
20
    public function update($menu, $data)
21
    {
22
        $menu->update($data);
23
24
        return $menu;
25
    }
26
27
    /**
28
     * Get all online menus
29
     * @return object
30
     */
31 View Code Duplication
    public function allOnline()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
32
    {
33
        $locale = App::getLocale();
34
35
        return $this->model->whereHas('translations', function (Builder $q) use ($locale) {
36
            $q->where('locale', "$locale");
37
            $q->where('status', 1);
38
        })->with('translations')->orderBy('created_at', 'DESC')->get();
39
    }
40
}
41