Completed
Push — master ( 195b94...858be2 )
by Mohamed
07:34
created

CrudTrait::createTagFromString()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 14
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 14
ccs 0
cts 6
cp 0
rs 9.4285
cc 2
eloc 6
nc 2
nop 1
crap 6
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 Illuminate\Database\Eloquent;
15
use Tinyissue\Model\Project;
16
use Tinyissue\Model\Tag;
17
18
/**
19
 * CrudTrait is trait class containing the methods for adding/editing/deleting the Tag model.
20
 *
21
 * @author Mohamed Alsharaf <[email protected]>
22
 *
23
 * @method Eloquent\Model where($column, $operator = null, $value = null, $boolean = 'and')
24
 */
25
trait CrudTrait
26
{
27
    /**
28
     * Create a new tag.
29
     *
30
     * @param array $input
31
     *
32
     * @return mixed
33
     */
34 1
    public function createTag(array $input)
35
    {
36 1
        $input['group'] = !array_key_exists('group', $input)? 0 : $input['group'];
37 1
        return $this->fill($input)->save();
0 ignored issues
show
Bug introduced by
It seems like fill() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
38
    }
39
40
    /**
41
     * Delete tag.
42
     *
43
     * @return bool|null
44
     *
45
     * @throws \Exception
46
     */
47
    public function delete()
48
    {
49
        // Remove kanban tags
50
        \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...
51
52
        // Remove relation to issues
53
        \DB::table('projects_issues_tags')->where('tag_id', '=', $this->id)->delete();
54
55
        return parent::delete();
56
    }
57
}
58