GrantDecision::getResourceOwner()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
/**
3
 * @author Boris Guéry <[email protected]>
4
 */
5
6
namespace Bgy\OAuth2\GrantType;
7
8
use Bgy\OAuth2\ResourceOwner;
9
use Bgy\OAuth2\Utils\Ensure;
10
11
final class GrantDecision
12
{
13
    const ALLOWED = 'allowed';
14
    const DENIED  = 'denied';
15
16
    private $decision;
17
18
    /**
19
     * @var ResourceOwner
20
     */
21
    private $resourceOwner;
22
23
    /**
24
     * @var GrantError
25
     */
26
    private $error;
27
28
    private function __construct() {}
29
30
    public static function denied(GrantError $error)
31
    {
32
        $d = new self();
33
        $d->decision = self::DENIED;
34
        $d->error    = $error;
35
36
        return $d;
37
    }
38
39
    public static function allowed(ResourceOwner $resourceOwner = null)
40
    {
41
        $d = new self();
42
        $d->decision = self::ALLOWED;
43
        $d->resourceOwner = $resourceOwner;
44
        $d->error         = GrantError::none();
45
46
        return $d;
47
    }
48
49
    public function getResourceOwner()
50
    {
51
        return $this->resourceOwner;
52
    }
53
54
    public function getError()
55
    {
56
        return $this->error;
57
    }
58
59
    public function isAllowed()
60
    {
61
        return $this->decision === self::ALLOWED;
62
    }
63
64
    public function isDenied()
65
    {
66
        return $this->decision === self::DENIED;
67
    }
68
69
    public function __toString()
70
    {
71
        return $this->decision;
72
    }
73
74
    public function equals(GrantDecision $decision)
75
    {
76
        return $this->decision === $decision->decision;
77
    }
78
}
79