Completed
Pull Request — master (#36)
by Timo
02:48
created

NotAuthorizedException::setTopicName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 4
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
dl 4
loc 4
rs 10
c 1
b 0
f 1
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
/*
4
 * This file is part of the Tidal/WampWatch package.
5
 *   (c) 2016 Timo Michna <timomichna/yahoo.de>
6
 *
7
 *  For the full copyright and license information, please view the LICENSE
8
 *  file that was distributed with this source code.
9
 *
10
 */
11
12
namespace Tidal\WampWatch\Exception;
13
14
/**
15
 * Class NoSuchProcedureException.
16
 *
17
 * Thrown when a router does not support a given meta topic
18
 */
19 View Code Duplication
class NotAuthorizedException extends \OutOfBoundsException
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...
20
{
21
    const ERROR_RESPONSE = 'wamp.error.not_authorized';
22
23
    /**
24
     * @var string name of the topic
25
     */
26
    protected $topicName;
27
28
    /**
29
     * @param string $topicName
30
     * @param        string the router error message
31
     */
32
    public function __construct($topicName, $errorMsg = 'session is not authorized')
33
    {
34
        $this->setTopicName($topicName);
35
36
        parent::__construct($errorMsg);
37
    }
38
39
    /**
40
     * @param string $topicName
41
     */
42
    protected function setTopicName($topicName)
43
    {
44
        $this->topicName = $topicName;
45
    }
46
47
    /**
48
     * @return string the topic name
49
     */
50
    public function getTopicName()
51
    {
52
        return $this->topicName;
53
    }
54
55
    /**
56
     * Checks if a router response is a 'no_such_topic' error.
57
     *
58
     * @param $errorResponse
59
     *
60
     * @return bool
61
     */
62
    public static function isNotAuthrorizedError($errorResponse)
63
    {
64
        return $errorResponse == self::ERROR_RESPONSE;
65
    }
66
}
67