ChecksPermissions   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 2
Bugs 1 Features 0
Metric Value
dl 0
loc 30
rs 10
c 2
b 1
f 0
wmc 4
lcom 0
cbo 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A hasPermissionTo() 0 7 2
A owns() 0 7 2
1
<?php
2
3
namespace Acacha\Events\Http\Requests\Traits;
4
5
use Auth;
6
7
/**
8
 * Trait ChecksPermissions.
9
 *
10
 * @package Acacha\Events\Http\Requests\Traits
11
 */
12
trait ChecksPermissions
13
{
14
    /**
15
     * Logged as permission to.
16
     *
17
     * @param $permission
18
     * @return bool
19
     */
20
    protected function hasPermissionTo($permission)
21
    {
22
        if (Auth::user()->hasPermissionTo($permission)) {
23
            return true;
24
        }
25
        return false;
26
    }
27
28
    /**
29
     * Owns model.
30
     *
31
     * @param $model
32
     * @return bool
33
     */
34
    protected function owns($model, $field = 'user_id')
35
    {
36
        if (Auth::user()->id == $this->$model->$field) {
37
            return true;
38
        }
39
        return false;
40
    }
41
}
42