Contact::trimArrayItems()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 6
rs 9.4285
cc 1
eloc 4
nc 1
nop 1
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