Completed
Push — develop ( 1c3d8e...dc7d05 )
by Mohamed
07:44
created

QueryTrait   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 25%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
c 1
b 0
f 0
lcom 0
cbo 1
dl 0
loc 29
ccs 2
cts 8
cp 0.25
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A isModelCreatedByUser() 0 8 1
A latestMessages() 0 4 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\Message\Queue;
13
14
use Illuminate\Database\Eloquent\Eloquent;
15
use Illuminate\Database\Eloquent\Relations;
16
use Tinyissue\Model\Message;
17
use Tinyissue\Model\Project\Issue;
18
use Tinyissue\Model\Tag;
19
use Tinyissue\Model\User;
20
use Tinyissue\Model\Message\Queue;
21
22
/**
23
 * QueryTrait is trait class containing the database queries methods for the message queue model.
24
 *
25
 * @author Mohamed Alsharaf <[email protected]>
26
 *
27
 * @method Relations\BelongsToMany tags()
28
 */
29
trait QueryTrait
30
{
31
    /**
32
     * Check whether an issue has registered add new issue in the queue.
33
     *
34
     * @param Model $model
35
     * @param User  $user
36
     *
37
     * @return bool
38
     */
39
    public function isModelCreatedByUser(Model $model, User $user)
40
    {
41
        return $this->where('event', '=', $this->getAddEventNameFromModel($model))
0 ignored issues
show
Bug introduced by
It seems like getAddEventNameFromModel() 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...
Bug introduced by
It seems like where() 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...
42
            ->where('model_id', '=', $model->id)
43
            ->where('model_type', '=', get_class($model))
44
            ->where('change_by_id', '=', $user->id)
45
            ->first();
46
    }
47
48
    /**
49
     * Get the latest messages queue.
50
     * 
51
     * @return mixed
52
     */
53 4
    public function latestMessages()
54
    {
55 4
        return $this->with('changeBy', 'model')->orderBy('created_at', 'DESC')->orderBy('id', 'DESC');
0 ignored issues
show
Bug introduced by
It seems like with() 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...
56
    }
57
}
58