Completed
Push — master ( 2b2467...86fe2f )
by Marco
12:06
created

Encryption   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
c 1
b 0
f 0
lcom 0
cbo 0
dl 0
loc 35
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setEncryption() 0 9 2
A getEncryption() 0 5 1
1
<?php namespace Comodojo\RpcClient\Components;
2
3
use \Exception;
4
5
/**
6
 * Protocol Trait
7
 *
8
 * @package     Comodojo Spare Parts
9
 * @author      Marco Giovinazzi <[email protected]>
10
 * @license     MIT
11
 *
12
 * LICENSE:
13
 *
14
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20
 * THE SOFTWARE.
21
 */
22
23
trait Encryption {
24
25
    /**
26
     * Enable comodojo encrypted transport
27
     *
28
     * @var mixed
29
     */
30
    private $encryption = false;
31
32
    /**
33
     * Set encryption key; this will enable the NOT-STANDARD payload encryption
34
     *
35
     * @param   string  $key Encryption key
36
     *
37
     * @return  \Comodojo\RpcClient\RpcClient
38
     *
39
     * @throws \Exception
40
     */
41
    public function setEncryption($key) {
42
43
        if ( empty($key) ) throw new Exception("Shared key cannot be empty");
44
45
        $this->$encryption = $key;
0 ignored issues
show
Bug introduced by
The variable $encryption does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
46
47
        return $this;
48
49
    }
50
51
    final public function getEncryption() {
52
53
        return $this->encryption;
54
55
    }
56
57
}
58