Article   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 83
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A store() 0 14 1
A getCategoriesAttribute() 0 10 2
1
<?php
2
3
namespace App\Models;
4
5
use Sofa\Eloquence\Eloquence;
6
use Sofa\Eloquence\Mappable;
7
8
/**
9
 * Class Article.
10
 */
11
class Article extends ChocolateyModel
12
{
13
    use Eloquence, Mappable;
14
15
    /**
16
     * The table associated with the model.
17
     *
18
     * @var string
19
     */
20
    protected $table = 'chocolatey_articles';
21
22
    /**
23
     * Primary Key of the Table.
24
     *
25
     * @var string
26
     */
27
    protected $primaryKey = 'id';
28
29
    /**
30
     * The attributes that will be mapped.
31
     *
32
     * @var array
33
     */
34
    protected $maps = ['updatedAt' => 'updated_at', 'createdAt' => 'created_at'];
35
36
    /**
37
     * The Appender(s) of the Model.
38
     *
39
     * @var array
40
     */
41
    protected $appends = ['updatedAt', 'createdAt'];
42
43
    /**
44
     * The attributes excluded from the model's JSON form.
45
     *
46
     * @var array
47
     */
48
    protected $hidden = ['updated_at', 'created_at'];
49
50
    /**
51
     * Store a new CMS Article.
52
     *
53
     * @param string $title
54
     * @param string $description
55
     * @param string $content
56
     * @param string $author
57
     * @param string $categories
58
     * @param string $imageUrl
59
     * @param string $thumbnailUrl
60
     *
61
     * @return Article
62
     */
63
    public function store(string $title, string $description, string $content, string $author, string $categories, string $imageUrl, string $thumbnailUrl): Article
64
    {
65
        $this->attributes['title'] = $title;
66
        $this->attributes['description'] = $description;
67
        $this->attributes['content'] = $content;
68
        $this->attributes['author'] = $author;
69
        $this->attributes['categories'] = $categories;
70
        $this->attributes['imageUrl'] = $imageUrl;
71
        $this->attributes['thumbnailUrl'] = $thumbnailUrl;
72
73
        $this->save();
74
75
        return $this;
76
    }
77
78
    /**
79
     * Get All Article Categories from the Article.
80
     *
81
     * @return array
82
     */
83
    public function getCategoriesAttribute(): array
84
    {
85
        $categories = [];
86
87
        foreach (explode(',', $this->attributes['categories']) as $articleCategory) {
88
            $categories[] = ArticleCategory::query()->where('link', $articleCategory)->first();
89
        }
90
91
        return $categories;
92
    }
93
}
94