CrudTrait::fill()
last analyzed

Size

Total Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 0
loc 1
ccs 0
cts 0
cp 0
nc 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\Tag;
13
14
use Tinyissue\Model\Tag;
15
16
/**
17
 * CrudTrait is trait class containing the methods for adding/editing/deleting the Tag model.
18
 *
19
 * @author Mohamed Alsharaf <[email protected]>
20
 *
21
 * @property static $this
22
 */
23
trait CrudTrait
24
{
25
    /**
26
     * Create a new tag.
27
     *
28
     * @param array $input
29
     *
30
     * @return mixed
31
     */
32 1
    public function createTag(array $input)
33
    {
34 1
        $input['group'] = !array_key_exists('group', $input) ? 0 : $input['group'];
35
36 1
        return $this->fill($input)->save();
37
    }
38
39
    /**
40
     * Delete tag.
41
     *
42
     * @return bool|null
43
     *
44
     * @throws \Exception
45
     */
46
    public function delete()
47
    {
48
        // Remove kanban tags
49
        \DB::table('projects_kanban_tags')->where('tag_id', '=', $this->id)->delete();
0 ignored issues
show
Bug introduced by
The property id does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
50
51
        // Remove relation to issues
52
        \DB::table('projects_issues_tags')->where('tag_id', '=', $this->id)->delete();
53
54
        return parent::delete();
55
    }
56
57
    abstract public function fill(array $attributes);
58
}
59