Completed
Pull Request — master (#6)
by Christopher
15:01 queued 06:11
created

EventAuthoriser::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace TechWilk\Rota\Authoriser;
4
5
use TechWilk\Rota\AuthoriserInterface;
6
use TechWilk\Rota\Event;
7
use TechWilk\Rota\EventPersonQuery;
8
use TechWilk\Rota\User;
9
10
class EventAuthoriser implements AuthoriserInterface
11
{
12
    private $event;
13
14
    public function __construct(Event $event)
15
    {
16
        $this->event = $event;
17
    }
18
19
    public function readableBy(User $user)
20
    {
21
        // created by me
22
        if ($this->event->getCreatedBy() === $user) {
23
            return true;
24
        }
25
        // we're a superadmin
26
        if ($user->isAdmin()) {
27
            return true;
28
        }
29
        // we're involved in the event
30
        $involvementCount = EventPersonQuery::create()
31
            ->useUserRoleQuery()
32
                ->filterByUser($user)
33
            ->endUse()
34
            ->filterByEvent($this->event)
35
            ->count();
36
        if ($involvementCount > 0) {
37
            return true;
38
        }
39
40
        return false;
41
    }
42
43
    public static function createableBy(User $user)
44
    {
45
        // we're a superadmin
46
        if ($user->isAdmin()) {
47
            return true;
48
        }
49
50
        return false;
51
    }
52
53 View Code Duplication
    public function updatableBy(User $user)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
54
    {
55
        // created by me
56
        if ($this->event->getCreatedBy() === $user) {
57
            return true;
58
        }
59
        // we're a superadmin
60
        if ($user->isAdmin()) {
61
            return true;
62
        }
63
64
        return false;
65
    }
66
67 View Code Duplication
    public function deteteableBy(User $user)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
68
    {
69
        // created by me
70
        if ($this->event->getCreatedBy() === $user) {
71
            return true;
72
        }
73
        // we're a superadmin
74
        if ($user->isAdmin()) {
75
            return true;
76
        }
77
78
        return false;
79
    }
80
}
81