TeamworkTeamTrait::invites()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Mpociot\Teamwork\Traits;
4
5
use Illuminate\Database\Eloquent\Model;
6
use Illuminate\Support\Facades\Config;
7
8
trait TeamworkTeamTrait
9
{
10
    /**
11
     * One-to-Many relation with the invite model.
12
     * @return mixed
13
     */
14
    public function invites()
15
    {
16
        return $this->hasMany(Config::get('teamwork.invite_model'), 'team_id', 'id');
0 ignored issues
show
Bug introduced by
It seems like hasMany() 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...
17
    }
18
19
    /**
20
     * Many-to-Many relations with the user model.
21
     *
22
     * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
23
     */
24
    public function users()
25
    {
26
        return $this->belongsToMany(Config::get('teamwork.user_model'), Config::get('teamwork.team_user_table'), 'team_id', 'user_id')->withTimestamps();
0 ignored issues
show
Bug introduced by
It seems like belongsToMany() 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...
27
    }
28
29
    /**
30
     * Has-One relation with the user model.
31
     * This indicates the owner of the team.
32
     *
33
     * @return \Illuminate\Database\Eloquent\Relations\HasOne
34
     */
35
    public function owner()
36
    {
37
        $userModel = Config::get('teamwork.user_model');
38
        $userKeyName = ( new $userModel() )->getKeyName();
39
40
        return $this->belongsTo($userModel, 'owner_id', $userKeyName);
0 ignored issues
show
Bug introduced by
It seems like belongsTo() 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...
41
    }
42
43
    /**
44
     * Helper function to determine if a user is part
45
     * of this team.
46
     *
47
     * @param Model $user
48
     * @return bool
49
     */
50
    public function hasUser(Model $user)
51
    {
52
        return $this->users()->where($user->getKeyName(), '=', $user->getKey())->first() ? true : false;
53
    }
54
}
55