Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
50.00% covered (danger)
50.00%
9 / 18
25.00% covered (danger)
25.00%
3 / 12
CRAP
0.00% covered (danger)
0.00%
0 / 1
SessionAnonymousTrait
50.00% covered (danger)
50.00%
9 / 18
25.00% covered (danger)
25.00%
3 / 12
53.12
0.00% covered (danger)
0.00%
0 / 1
 isTrueProperty
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
5
 isEnabledLogin
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 isEnabledSignup1
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 isEnabledSignup2
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 isPasswordReminder
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 isPasswordReset
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 throwHttpStatusIfIsDisabled
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
2
 throwHttpStatusIfNotLogin
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 throwHttpStatusIfNotSignup1
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 throwHttpStatusIfNotSignup2
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 throwHttpStatusIfNotPasswordReminder
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 throwHttpStatusIfNotPasswordReset
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3declare(strict_types=1);
4
5namespace PeServer\App\Models\Domain\Page;
6
7use PeServer\App\Models\Data\SessionAnonymous;
8use PeServer\App\Models\SessionKey;
9use PeServer\Core\Http\HttpStatus;
10use PeServer\Core\Throws\HttpStatusException;
11
12trait SessionAnonymousTrait
13{
14    #region function
15
16    private function isTrueProperty(string $propertyName): bool
17    {
18        if ($this->existsSession(SessionKey::ANONYMOUS)) {
19            $sessionAnonymous = $this->getSession(SessionKey::ANONYMOUS);
20            if ($sessionAnonymous !== null && $sessionAnonymous instanceof SessionAnonymous) {
21                /** @var SessionAnonymous $sessionAnonymous */
22                if ($sessionAnonymous->$propertyName) {
23                    return true;
24                }
25            }
26        }
27
28        return false;
29    }
30
31    protected function isEnabledLogin(): bool
32    {
33        return $this->isTrueProperty('login');
34    }
35
36    protected function isEnabledSignup1(): bool
37    {
38        return $this->isTrueProperty('signup1');
39    }
40
41    protected function isEnabledSignup2(): bool
42    {
43        return $this->isTrueProperty('signup2');
44    }
45
46    protected function isPasswordReminder(): bool
47    {
48        return $this->isTrueProperty('passwordReminder');
49    }
50
51    protected function isPasswordReset(): bool
52    {
53        return $this->isTrueProperty('passwordReset');
54    }
55
56    private function throwHttpStatusIfIsDisabled(string $propertyName, HttpStatus $httpStatus): void
57    {
58        if (!$this->isTrueProperty($propertyName)) {
59            throw new HttpStatusException($httpStatus);
60        }
61    }
62
63    protected function throwHttpStatusIfNotLogin(HttpStatus $httpStatus): void
64    {
65        $this->throwHttpStatusIfIsDisabled('login', $httpStatus);
66    }
67
68    protected function throwHttpStatusIfNotSignup1(HttpStatus $httpStatus): void
69    {
70        $this->throwHttpStatusIfIsDisabled('signup1', $httpStatus);
71    }
72
73    protected function throwHttpStatusIfNotSignup2(HttpStatus $httpStatus): void
74    {
75        $this->throwHttpStatusIfIsDisabled('signup2', $httpStatus);
76    }
77
78    protected function throwHttpStatusIfNotPasswordReminder(HttpStatus $httpStatus): void
79    {
80        $this->throwHttpStatusIfIsDisabled('passwordReminder', $httpStatus);
81    }
82
83    protected function throwHttpStatusIfNotPasswordReset(HttpStatus $httpStatus): void
84    {
85        $this->throwHttpStatusIfIsDisabled('passwordReset', $httpStatus);
86    }
87
88    #endregion
89}