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

Encryption   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 49
Duplicated Lines 100 %

Importance

Changes 0
Metric Value
dl 49
loc 49
rs 10
c 0
b 0
f 0
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setEncryption() 9 9 2
A getEncryption() 3 3 1
A validEncryption() 3 3 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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
 */
24 View Code Duplication
trait Encryption
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
25
{
26
27
    /**
28
     * The PGP key file URL.
29
     *
30
     * @var string
31
     */
32
    protected $encryption = null;
33
34
35
    /**
36
     * Set the encryption.
37
     *
38
     * @param  string $encryption
39
     *
40
     * @return SecurityTxt
41
     */
42
    public function setEncryption(string $encryption): SecurityTxt
43
    {
44
        if (!$this->validEncryption($encryption)) {
45
            throw new Exception('Encryption must be a well-formed URL.');
46
        }
47
48
        $this->encryption = $encryption;
49
50
        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...
51
    }
52
53
    /**
54
     * Get the encryption.
55
     *
56
     * @return string
57
     */
58
    public function getEncryption(): string
59
    {
60
        return $this->encryption;
61
    }
62
63
    /**
64
     * Determines if encryption is valid.
65
     *
66
     * @param string $encryption
67
     *
68
     * @return bool
69
     */
70
    public function validEncryption(string $encryption): bool
71
    {
72
        return filter_var($encryption, FILTER_VALIDATE_URL) !== false;
73
    }
74
75
}
76