Test Failed
Branch develop (a9f1e9)
by Ludwig
02:28
created

Metadata::validateKinds()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 7
nc 3
nop 2
dl 0
loc 13
rs 10
c 0
b 0
f 0
1
<?php
2
3
/*
4
 * This file is part of the CwdPowerDNS Client
5
 *
6
 * (c) 2018 cwd.at GmbH <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
declare(strict_types=1);
13
14
namespace Cwd\PowerDNSClient\Model;
15
16
use Symfony\Component\Validator\Constraints as Assert;
17
use Symfony\Component\Validator\Context\ExecutionContextInterface;
18
19
class Metadata
20
{
21
    // https://doc.powerdns.com/md/httpapi/api_spec/#zone-metadata
22
    const UPDATE_FORBIDDEN = [
23
        'NSEC3PARAM',
24
        'NSEC3NARROW',
25
        'PRESIGNED',
26
        'LUA-AXFR-SCRIPT',
27
    ];
28
29
    // https://doc.powerdns.com/authoritative/domainmetadata.html
30
    const VALID_KINDs = [
31
        'ALLOW-AXFR-FROM',
32
        'API-RECTIFY',
33
        'AXFR-SOURCE',
34
        'ALLOW-DNSUPDATE-FROM',
35
        'TSIG-ALLOW-DNSUPDATE',
36
        'FORWARD-DNSUPDATE',
37
        'SOA-EDIT-DNSUPDATE',
38
        'NOTIFY-DNSUPDATE',
39
        'ALSO-NOTIFY',
40
        'AXFR-MASTER-TSIG',
41
        'GSS-ALLOW-AXFR-PRINCIPAL',
42
        'GSS-ACCEPTOR-PRINCIPAL',
43
        'IXFR',
44
        'LUA-AXFR-SCRIPT',
45
        'NSEC3NARROW',
46
        'NSEC3PARAM',
47
        'PRESIGNED',
48
        'PUBLISH-CDNSKEY',
49
        'PUBLISH-CDS',
50
        'SOA-EDIT',
51
        'SOA-EDIT-API',
52
        'TSIG-ALLOW-AXFR',
53
        'TSIG-ALLOW-DNSUPDATE',
54
    ];
55
56
    /**
57
     * @var string
58
     * @Assert\NotBlank(groups={"CREATE", "UPDATE"})
59
     */
60
    private $kind;
61
62
    /** @var string[] */
63
    private $metadata = [];
64
65
    /**
66
     * @return string
67
     */
68
    public function getKind(): string
69
    {
70
        return $this->kind;
71
    }
72
73
    /**
74
     * @param string $kind
75
     *
76
     * @return Metadata
77
     */
78
    public function setKind(string $kind): Metadata
79
    {
80
        $this->kind = $kind;
81
82
        return $this;
83
    }
84
85
    /**
86
     * @return string[]
87
     */
88
    public function getMetadata(): array
89
    {
90
        return $this->metadata;
91
    }
92
93
    /**
94
     * @param string[] $metadata
95
     *
96
     * @return Metadata
97
     */
98
    public function setMetadata(array $metadata): Metadata
99
    {
100
        $this->metadata = $metadata;
101
102
        return $this;
103
    }
104
105
    /**
106
     * @param ExecutionContextInterface $context
107
     * @param $payload
108
     * @Assert\Callback(groups={"CREATE", "UPDATE"})
109
     */
110
    public function validateKinds(ExecutionContextInterface $context, $payload)
1 ignored issue
show
Unused Code introduced by
The parameter $payload is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

110
    public function validateKinds(ExecutionContextInterface $context, /** @scrutinizer ignore-unused */ $payload)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
111
    {
112
        if (in_array($this->getKind(), self::VALID_KINDs)) {
113
            return;
114
        }
115
116
        if (0 === strpos(strtoupper($this->getKind()), 'X-')) {
117
            return;
118
        }
119
120
        $context->buildViolation(sprintf('Kind "%s" not in valid kinds or does not start with "X-"', $this->getKind()))
121
            ->atPath('kind')
122
            ->addViolation();
123
    }
124
125
    /**
126
     * @param ExecutionContextInterface $context
127
     * @param $payload
128
     * @Assert\Callback(groups={"UPDATE"})
129
     */
130
    public function validateForbidden(ExecutionContextInterface $context, $payload)
1 ignored issue
show
Unused Code introduced by
The parameter $payload is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

130
    public function validateForbidden(ExecutionContextInterface $context, /** @scrutinizer ignore-unused */ $payload)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
131
    {
132
        if (in_array($this->getKind(), self::UPDATE_FORBIDDEN)) {
133
            $context->buildViolation(sprintf('Kind "%s" cant be updated', $this->getKind()))
134
                ->atPath('kind')
135
                ->addViolation();
136
        }
137
    }
138
}
139