Contact   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 63
Duplicated Lines 26.98 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 6
c 2
b 0
f 0
lcom 1
cbo 2
dl 17
loc 63
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getFilterTagsAttribute() 9 9 2
A setFilterTagsAttribute() 8 8 2
A scopeActive() 0 4 1
A trimArrayItems() 0 6 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
2
3
namespace App;
4
5
use Illuminate\Database\Eloquent\Model;
6
use Illuminate\Database\Eloquent\SoftDeletes;
7
8
/**
9
 * @property string email
10
 * @property string name
11
 * @property array  filter_tags
12
 * @property bool   active
13
 */
14
class Contact extends Model
15
{
16
    use SoftDeletes;
17
18
    protected $casts = [
19
        'active'           => 'boolean',
20
    ];
21
22
    /**
23
     * Attributes
24
     */
25
26 View Code Duplication
    public function getFilterTagsAttribute()
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 (empty($this->attributes['filter_tags'])) {
29
            return [];
30
        }
31
        $tagArray = explode(',', $this->attributes['filter_tags']);
32
33
        return $this->trimArrayItems($tagArray);
34
    }
35
36
37 View Code Duplication
    public function setFilterTagsAttribute($tags)
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...
38
    {
39
        if (is_array($tags)) {
40
            $this->attributes['filter_tags'] = implode(',', $this->trimArrayItems($tags));
41
        } else {
42
            $this->attributes['filter_tags'] = trim($tags);
43
        }
44
    }
45
46
47
    /**
48
     * Scopes
49
     */
50
51
    /**
52
     * Scope a query to only include active pings.
53
     *
54
     * @return \Illuminate\Database\Eloquent\Builder
55
     */
56
    public function scopeActive($query)
57
    {
58
        return $query->where('active', 1);
59
    }
60
61
62
63
    /**
64
     * Trim each item in the array
65
     *
66
     * @param array $tags
67
     *
68
     * @return array
69
     */
70
    private function trimArrayItems(array $tags)
71
    {
72
        return array_map(function($tag) {
73
            return trim($tag);
74
        }, $tags);
75
    }
76
}
77