StreamErrorException   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
dl 0
loc 23
rs 10
c 0
b 0
f 0
wmc 5
lcom 0
cbo 2

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getError() 0 4 1
A __construct() 0 5 2
A generateMessage() 0 4 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\Exception\Protocol;
17
18
use Exception;
19
use Kadet\Xmpp\Exception\ProtocolException;
20
use Kadet\Xmpp\Stream\Error;
21
22
class StreamErrorException extends ProtocolException
23
{
24
    /**
25
     * @var Error
26
     */
27
    private $_error;
28
29
    public function getError() : Error
30
    {
31
        return $this->_error;
32
    }
33
34
    public function __construct(Error $error, $message = null, $code = 0, Exception $previous = null)
35
    {
36
        $this->_error = $error;
37
        parent::__construct($message ?: $this->generateMessage($error), $code, $previous);
38
    }
39
40
    private function generateMessage(Error $error) : string
41
    {
42
        return 'Stream error: '.str_replace('-', ' ', $error->kind).($error->text ? " ({$error->text})" : null);
43
    }
44
}
45