Acknowledgement::setAcknowledgement()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 1
dl 0
loc 9
ccs 5
cts 5
cp 1
crap 2
rs 9.6666
c 0
b 0
f 0
1
<?php
2
/**
3
 * src/Directives/Acknowledgement.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
 * Acknowledgement
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
 * @link        https://securitytext.org/
24
 */
25
trait Acknowledgement
26
{
27
28
    /**
29
     * The acknowledgement URL.
30
     *
31
     * @var string
32
     */
33
    protected $acknowledgement = null;
34
35
    /**
36
     * Set the acknowledgement URL.
37
     *
38
     * @param  string $acknowledgement
39
     *
40
     * @return SecurityTxt
41
     */
42 3
    public function setAcknowledgement(string $acknowledgement): SecurityTxt
43
    {
44 3
        if (filter_var($acknowledgement, FILTER_VALIDATE_URL) === false) {
45 1
            throw new Exception('Acknowledgement must be a well-formed URL.');
46
        }
47
48 2
        $this->acknowledgement = $acknowledgement;
49
50 2
        return $this;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this returns the type AustinHeap\Security\Txt\Directives\Acknowledgement which includes types incompatible with the type-hinted return AustinHeap\Security\Txt\SecurityTxt.
Loading history...
51
    }
52
53
    /**
54
     * Get the acknowledgement URL.
55
     *
56
     * @return string
57
     */
58 1
    public function getAcknowledgement(): string
59
    {
60 1
        return $this->acknowledgement;
61
    }
62
}
63