TcpStream   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 32
rs 10
c 0
b 0
f 0
ccs 0
cts 16
cp 0
wmc 4
lcom 1
cbo 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A encrypt() 0 13 2
A decrypt() 0 13 2
1
<?php
2
/**
3
 * Nucleus - XMPP Library for PHP
4
 *
5
 * Copyright (C) 2016, Some rights reserved.
6
 *
7
 * @author Kacper "Kadet" Donat <[email protected]>
8
 *
9
 * Contact with author:
10
 * Xmpp: [email protected]
11
 * E-mail: [email protected]
12
 *
13
 * From Kadet with love.
14
 */
15
16
namespace Kadet\Xmpp\Network;
17
18
use React\Stream\Stream;
19
20
class TcpStream extends Stream implements SecureStream
21
{
22
    private $_secured = false;
23
24
    public function encrypt(int $type = STREAM_CRYPTO_METHOD_ANY_CLIENT) : bool
25
    {
26
        if ($this->_secured) {
27
            return true;
28
        }
29
30
        $result = true;
31
        $result &= stream_set_blocking($this->stream, 1);
32
        $result &= stream_socket_enable_crypto($this->stream, true, $type);
33
        $result &= stream_set_blocking($this->stream, 0);
34
35
        return $this->_secured = $result;
36
    }
37
38
    public function decrypt() : bool
39
    {
40
        if (!$this->_secured) {
41
            return true;
42
        }
43
44
        $result = true;
45
        $result &= stream_set_blocking($this->stream, 1);
46
        $result &= stream_socket_enable_crypto($this->stream, false);
47
        $result &= stream_set_blocking($this->stream, 0);
48
49
        return !($this->_secured = !$result);
50
    }
51
}
52