Completed
Push — master ( e17d9a...f8eac8 )
by Austin
01:42
created

Disclosure::validDisclosure()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * src/Directives/Disclosure.php
4
 *
5
 * @package     php-security-txt
6
 * @author      Austin Heap <[email protected]>
7
 * @version     v0.4.0
8
 */
9
10
declare(strict_types = 1);
11
12
namespace AustinHeap\Security\Txt\Directives;
13
14
use AustinHeap\Security\Txt\SecurityTxt;
15
use Exception;
16
17
/**
18
 * Disclosure
19
 *
20
 * @link        https://github.com/austinheap/php-security-txt
21
 * @link        https://packagist.org/packages/austinheap/php-security-txt
22
 * @link        https://austinheap.github.io/php-security-txt/classes/AustinHeap.Security.Txt.SecurityTxt.html
23
 */
24
trait Disclosure
25
{
26
27
    /**
28
     * The disclosure policy.
29
     *
30
     * @var string
31
     */
32
    protected $disclosure = null;
33
34
    /**
35
     * Set the disclosure policy.
36
     *
37
     * @param  string $disclosure
38
     *
39
     * @return \AustinHeap\Security\Txt\SecurityTxt
40
     */
41
    public function setDisclosure(string $disclosure): SecurityTxt
42
    {
43
        if (!$this->validDisclosure($disclosure)) {
44
            throw new Exception('Disclosure policy must be either "full", "partial", or "none".');
45
        }
46
47
        $this->disclosure = $disclosure;
48
49
        return $this;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this returns the type AustinHeap\Security\Txt\Directives\Disclosure which includes types incompatible with the type-hinted return AustinHeap\Security\Txt\SecurityTxt.
Loading history...
50
    }
51
52
    /**
53
     * Get the disclosure policy.
54
     *
55
     * @return string
56
     */
57
    public function getDisclosure(): string
58
    {
59
        return $this->disclosure;
60
    }
61
62
    /**
63
     * Determines if disclosure is valid.
64
     *
65
     * @param string $disclosure
66
     *
67
     * @return bool
68
     */
69
    public function validDisclosure(string $disclosure): bool
70
    {
71
        return in_array($disclosure, ['full', 'partial', 'none'], true);
72
    }
73
74
}
75