Completed
Push — master ( 72ff63...b0fbbf )
by Kirill
01:35 queued 01:31
created

Guarded::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 3
dl 0
loc 8
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * Spiral Framework.
5
 *
6
 * @license   MIT
7
 * @author    Anton Titov (Wolfy-J)
8
 */
9
10
declare(strict_types=1);
11
12
namespace Spiral\Domain\Annotation;
13
14
use Attribute;
15
use Doctrine\Common\Annotations\Annotation;
16
use Spiral\Attributes\NamedArgumentConstructor;
17
18
/**
19
 * @Annotation()
20
 * @Annotation\Target({"METHOD", "CLASS"})
21
 * @NamedArgumentConstructor()
22
 */
23
#[Attribute(Attribute::TARGET_METHOD | Attribute::TARGET_CLASS)]
24
#[NamedArgumentConstructor()]
25
final class Guarded
26
{
27
    /**
28
     * @Annotation\Attribute(name="permission", type="string")
29
     * @type null|string
30
     */
31
    public $permission;
32
33
    /**
34
     * @Enum({"notFound", "unauthorized", "forbidden", "badAction", "error"})
35
     * @type string
36
     */
37
    public $else;
38
39
    /**
40
     * Error message in case of error.
41
     *
42
     * @Annotation\Attribute(name="errorMessage", type="string")
43
     * @type null|string
44
     */
45
    public $errorMessage;
46
47
    public function __construct(
48
        ?string $permission = null,
49
        string $else = 'forbidden',
50
        ?string $errorMessage = null
51
    ) {
52
        $this->permission = $permission;
53
        $this->else = $else;
54
        $this->errorMessage = $errorMessage;
55
    }
56
}
57