Completed
Push — manage-articles ( 1fa998...1c60ef )
by Fèvre
02:30
created

ArticleRepository::create()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 7

Duplication

Lines 10
Ratio 100 %

Importance

Changes 0
Metric Value
dl 10
loc 10
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 7
nc 2
nop 1
1
<?php
2
namespace Xetaravel\Models\Repositories;
3
4
use Illuminate\Support\Collection;
5
use Xetaravel\Models\Article;
6
7
class ArticleRepository
8
{
9
    /**
10
     * Find the latest articles for the sidebar.
11
     *
12
     * @return \Illuminate\Database\Eloquent\Collection
13
     */
14
    public static function sidebar(): Collection
15
    {
16
        return Article::latest()->take(5)->get();
17
    }
18
19
    /**
20
     * Create the new article and save it.
21
     *
22
     * @param array $data The data used to create the article.
23
     *
24
     * @return bool
25
     */
26 View Code Duplication
    public static function create(array $data): bool
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
        $article = new Article;
29
        $article->title = $data['title'];
30
        $article->category_id = $data['category_id'];
31
        $article->is_display = isset($data['is_display']) ? true : false;
32
        $article->content = $data['content'];
33
34
        return $article->save();
35
    }
36
37
    /**
38
     * Update the article data and save it.
39
     *
40
     * @param array $data The data used to update the article.
41
     *
42
     * @return bool
43
     */
44 View Code Duplication
    public static function update(array $data, Article $article): bool
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...
45
    {
46
        $article->title = $data['title'];
47
        $article->category_id = $data['category_id'];
48
        $article->is_display = isset($data['is_display']) ? true : false;
49
        $article->content = $data['content'];
50
51
        return $article->save();
52
    }
53
}
54