Passed
Push — master ( 72964c...b9ea2c )
by Peter
02:46
created

PageViewed::setIsAllowed()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 5
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace AbterPhp\Website\Events;
6
7
use AbterPhp\Website\Domain\Entities\Page as Entity;
8
9
class PageViewed
10
{
11
    /** @var Entity */
12
    private $page;
13
14
    /** @var bool */
15
    private $isAllowed = false;
16
17
    /** @var string[] */
18
    private $userGroupIdentifiers = [];
19
20
    /**
21
     * PageViewed constructor.
22
     *
23
     * @param Entity $page
24
     * @param array   $userGroupIdentifiers
25
     */
26
    public function __construct(Entity $page, array $userGroupIdentifiers)
27
    {
28
        $this->setPage($page);
29
30
        $this->userGroupIdentifiers = $userGroupIdentifiers;
31
    }
32
33
    /**
34
     * @return Entity
35
     */
36
    public function getPage(): Entity
37
    {
38
        return $this->page;
39
    }
40
41
    /**
42
     * @param Entity $page
43
     *
44
     * @return $this
45
     */
46
    public function setPage(Entity $page): PageViewed
47
    {
48
        $this->page      = $page;
49
        $this->isAllowed = !$page->isDraft();
50
51
        return $this;
52
    }
53
54
    /**
55
     * @return bool
56
     */
57
    public function isAllowed(): bool
58
    {
59
        return $this->isAllowed;
60
    }
61
62
    /**
63
     * @return $this
64
     */
65
    public function setIsAllowed(): self
66
    {
67
        $this->isAllowed = true;
68
69
        return $this;
70
    }
71
72
    /**
73
     * @return $this
74
     */
75
    public function setIsNotAllowed(): self
76
    {
77
        $this->isAllowed = false;
78
79
        return $this;
80
    }
81
82
    /**
83
     * @return string[]
84
     */
85
    public function getUserGroupIdentifiers(): array
86
    {
87
        return $this->userGroupIdentifiers;
88
    }
89
}
90