OAuthFlows::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 1 Features 1
Metric Value
cc 1
eloc 0
c 2
b 1
f 1
nc 1
nop 0
dl 0
loc 2
rs 10
1
<?php
2
3
4
namespace Apie\OpenapiSchema\Spec;
5
6
use Apie\OpenapiSchema\Concerns\CompositeValueObjectWithExtension;
7
use Apie\OpenapiSchema\Exceptions\OAuthRequiresAuthorizationUrl;
8
use Apie\OpenapiSchema\Exceptions\OAuthRequiresTokenUrl;
9
use Apie\ValueObjects\ValueObjectInterface;
10
11
/**
12
 * @see https://swagger.io/specification/#oauth-flows-object
13
 */
14
class OAuthFlows implements ValueObjectInterface
15
{
16
    use CompositeValueObjectWithExtension;
0 ignored issues
show
Bug introduced by
The trait Apie\OpenapiSchema\Conce...alueObjectWithExtension requires the property $name which is not provided by Apie\OpenapiSchema\Spec\OAuthFlows.
Loading history...
17
18
    /**
19
     * @var OAuthFlow|null
20
     */
21
    private $implicit;
22
23
    /**
24
     * @var OAuthFlow|null
25
     */
26
    private $password;
27
28
    /**
29
     * @var OAuthFlow|null
30
     */
31
    private $clientCredentials;
32
33
    /**
34
     * @var OAuthFlow|null
35
     */
36
    private $authorizationCode;
37
38
    private function __construct()
39
    {
40
    }
41
42
    protected function validateProperties(): void
43
    {
44
        if ($this->implicit && null === $this->implicit->getAuthorizationUrl()) {
45
            throw new OAuthRequiresAuthorizationUrl();
46
        }
47
        if ($this->password && null === $this->password->getTokenUrl()) {
48
            throw new OAuthRequiresTokenUrl();
49
        }
50
        if ($this->clientCredentials && $this->clientCredentials->getTokenUrl()) {
51
            throw new OAuthRequiresTokenUrl();
52
        }
53
        if ($this->authorizationCode) {
54
            if (null === $this->authorizationCode->getAuthorizationUrl()) {
55
                throw new OAuthRequiresAuthorizationUrl();
56
            }
57
            if (null === $this->authorizationCode->getTokenUrl()) {
58
                throw new OAuthRequiresTokenUrl();
59
            }
60
        }
61
    }
62
}
63