Issues (14)

src/Directives/Encryption.php (1 issue)

1
<?php
2
/**
3
 * src/Directives/Encryption.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
 * Encryption
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 Encryption
26
{
27
28
    /**
29
     * The PGP key file URL.
30
     *
31
     * @var string
32
     */
33
    protected $encryption = null;
34
35
36
    /**
37
     * Set the encryption.
38
     *
39
     * @param  string $encryption
40
     *
41
     * @return SecurityTxt
42
     */
43 3
    public function setEncryption(string $encryption): SecurityTxt
44
    {
45 3
        if (!$this->validEncryption($encryption)) {
46 1
            throw new Exception('Encryption must be a well-formed URL.');
47
        }
48
49 2
        $this->encryption = $encryption;
50
51 2
        return $this;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this returns the type AustinHeap\Security\Txt\Directives\Encryption which includes types incompatible with the type-hinted return AustinHeap\Security\Txt\SecurityTxt.
Loading history...
52
    }
53
54
    /**
55
     * Get the encryption.
56
     *
57
     * @return string
58
     */
59 1
    public function getEncryption(): string
60
    {
61 1
        return $this->encryption;
62
    }
63
64
    /**
65
     * Determines if encryption is valid.
66
     *
67
     * @param string $encryption
68
     *
69
     * @return bool
70
     */
71 3
    public function validEncryption(string $encryption): bool
72
    {
73 3
        return filter_var($encryption, FILTER_VALIDATE_URL) !== false;
74
    }
75
}
76