Completed
Pull Request — master (#34)
by Fèvre
19:42 queued 16:30
created

DiscussThreadRepository::create()   A

Complexity

Conditions 4
Paths 5

Size

Total Lines 19
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 19
rs 9.2
c 0
b 0
f 0
cc 4
eloc 11
nc 5
nop 1
1
<?php
2
namespace Xetaravel\Models\Repositories;
3
4
use Illuminate\Support\Collection;
5
use Illuminate\Support\Facades\Auth;
6
use Xetaravel\Models\DiscussThread;
7
8
class DiscussThreadRepository
9
{
10
11
    /**
12
     * Create the new thread and save it.
13
     *
14
     * @param array $data The data used to create the thread.
15
     *
16
     * @return \Xetaravel\Models\DiscussThread
17
     */
18
    public static function create(array $data): DiscussThread
19
    {
20
        $thread = [
21
            'title' => $data['title'],
22
            'category_id' => $data['category_id'],
23
            'content' => $data['content']
24
        ];
25
26
        $user = Auth::user();
27
28
        if ($user->hasPermission('manage.discuss.threads')) {
29
            $thread += [
30
                'is_locked' => isset($data['is_locked']) ? true : false,
31
                'is_pinned' => isset($data['is_pinned']) ? true : false,
32
            ];
33
        }
34
35
        return DiscussThread::create($thread);
36
    }
37
38
    /**
39
     * Update the article data and save it.
40
     *
41
     * @param array $data The data used to update the article.
42
     * @param \Xetaravel\Models\Article $article The article to update.
0 ignored issues
show
Documentation introduced by
Should the type for parameter $article not be Article?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
43
     *
44
     * @return \Xetaravel\Models\Article
45
     */
46 View Code Duplication
    public static function update(array $data, Article $article): Article
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...
47
    {
48
        $article->title = $data['title'];
49
        $article->category_id = $data['category_id'];
50
        $article->is_display = isset($data['is_display']) ? true : false;
51
        $article->content = $data['content'];
52
        $article->save();
53
54
        return $article;
55
    }
56
}
57