Completed
Push — develop ( 12ceca...974b72 )
by Mohamed
04:39
created

CrudTrait   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 52.63%

Importance

Changes 4
Bugs 1 Features 0
Metric Value
wmc 3
c 4
b 1
f 0
lcom 1
cbo 2
dl 0
loc 64
ccs 10
cts 19
cp 0.5263
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A createNote() 0 20 1
A updateBody() 0 9 1
A delete() 0 9 1
1
<?php
2
3
/*
4
 * This file is part of the Tinyissue package.
5
 *
6
 * (c) Mohamed Alsharaf <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Tinyissue\Model\Traits\Project\Note;
13
14
use Illuminate\Database\Eloquent;
15
use Illuminate\Database\Eloquent\Relations;
16
use Tinyissue\Model;
17
18
/**
19
 * CrudTrait is trait class containing the methods for adding/editing/deleting the Project\Note model.
20
 *
21
 * @author Mohamed Alsharaf <[email protected]>
22
 *
23
 * @property int                  $project_id
24
 * @property int                  $created_by
25
 * @property string               $body
26
 * @property Model\Project        $project
27
 * @property Model\User           $createdBy
28
 *
29
 * @method   Relations\BelongsTo  belongsTo($related, $foreignKey = null, $otherKey = null, $relation = null)
30
 * @method   Eloquent\Model       save()
31
 * @method   Relations\HasOne     activity()
32
 */
33
trait CrudTrait
34
{
35
    /**
36
     * Create a new note.
37
     *
38
     * @param array $input
39
     *
40
     * @return $this
41
     */
42 2
    public function createNote(array $input)
43
    {
44 2
        $this->body       = $input['note_body'];
45 2
        $this->project_id = $this->project->id;
46 2
        $this->created_by = $this->createdBy->id;
47
48
        // Add event on successful save
49 2
        static::saved([$this, 'queueAdd']);
50
51 2
        $this->save();
52
53
        // Add to user's activity log
54
        $this->activity()->save(new Model\User\Activity([
55
            'type_id'   => Model\Activity::TYPE_NOTE,
56
            'parent_id' => $this->project->id,
57
            'user_id'   => $this->createdBy->id,
58
        ]));
59
60
        return $this;
61
    }
62
63
    /**
64
     * Update the note body.
65
     *
66
     * @param string $body
67
     *
68
     * @return Eloquent\Model
69
     */
70 1
    public function updateBody($body)
71
    {
72 1
        $this->body = $body;
73
74
        // Add event on successful save
75 1
        static::saved([$this, 'queueUpdate']);
76
77 1
        return $this->save();
78
    }
79
80
    /**
81
     * Delete a note.
82
     *
83
     * @return bool|null
84
     *
85
     * @throws \Exception
86
     */
87
    public function delete()
88
    {
89
        $this->activity()->delete();
90
91
        // Add event on successful delete
92
        static::deleted([$this, 'queueDelete']);
0 ignored issues
show
Bug introduced by
The method deleted() does not exist on Tinyissue\Model\Traits\Project\Note\CrudTrait. Did you maybe mean delete()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
93
94
        return parent::delete();
95
    }
96
}
97