Completed
Push — master ( 28284e...eaa9bf )
by
unknown
12:07
created

Repository   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 49
Duplicated Lines 14.29 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 1
dl 7
loc 49
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A find() 7 7 2
A lists() 0 13 3

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
2
3
namespace App\Repositories;
4
5
use App\Contracts\RepositoryContract;
6
use Illuminate\Database\Eloquent\Model;
7
8
abstract class Repository implements RepositoryContract
9
{
10
    /**
11
     * Ascendent.
12
     */
13
    const ASC = 'asc';
14
15
    /**
16
     * Descendent.
17
     */
18
    const DESC = 'desc';
19
20
    /**
21
     * Find model by id/slug.
22
     *
23
     * @param $slug
24
     * @return Model
25
     */
26 View Code Duplication
    public function find($slug)
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...
27
    {
28
        if (is_numeric($slug))
29
            return $this->getModel()->active()->whereId((int) $slug)->first();
30
31
        return $this->getModel()->active()->whereSlug($slug)->first();
32
    }
33
34
    /**
35
     * Lists the columns.
36
     * @example: $collection->lists('name') will return ['id' => 'name', ...] etc.
37
     *
38
     * @param $column
39
     * @param null $key
40
     * @param bool $active
41
     * @return array
42
     */
43
    public function lists($column, $key = null, $active = false)
44
    {
45
        $items = [];
46
47
        $collection = $active ? $this->getModel()->active()->get() : $this->getModel()->all();
48
49
        foreach ($collection as $item)
50
        {
51
            $items[$item->$key] = $item->$column;
52
        }
53
54
        return $items;
55
    }
56
}