Test Setup Failed
Push — main ( e03535...dde247 )
by Pieter
03:39
created

OAuthFlows::validateProperties()   B

Complexity

Conditions 10
Paths 7

Size

Total Lines 17
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 1
Metric Value
cc 10
eloc 11
c 1
b 1
f 1
nc 7
nop 0
dl 0
loc 17
rs 7.6666

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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