Completed
Push — master ( ea20ea...a25393 )
by Timo
41s
created

NoSuchProcedureException::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 10
rs 9.4285
cc 1
eloc 6
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
namespace Tidal\WampWatch\Exception;
12
13
/**
14
 * Class NoSuchProcedureException.
15
 *
16
 * Thrown when a router does not support a given meta procedure
17
 */
18
class NoSuchProcedureException extends \OutOfBoundsException
19
{
20
    const ERROR_RESPONSE = 'wamp.error.no_such_procedure';
21
22
    /**
23
     * @var string name of the procedure
24
     */
25
    protected $procedureName;
26
27
    /**
28
     * @param string $procedureName
29
     */
30
    public function __construct($procedureName)
31
    {
32
        $this->setprocedureName($procedureName);
33
34
        parent::__construct(sprintf(
35
            "Server seems to not support meta procedure '%s'. Response was: '%s'",
36
            $procedureName,
37
            self::ERROR_RESPONSE
38
        ));
39
    }
40
41
    /**
42
     * @param string $procedureName
43
     */
44
    protected function setProcedureName($procedureName)
45
    {
46
        $this->procedureName = $procedureName;
47
    }
48
49
    /**
50
     * @return string the procedure name
51
     */
52
    public function getProcedureName()
53
    {
54
        return $this->procedureName;
55
    }
56
57
    /**
58
     * Checks if a router response is a 'no_such_procedure' error.
59
     *
60
     * @param $errorResponse
61
     *
62
     * @return bool
63
     */
64
    public static function isNoProcedureError($errorResponse)
65
    {
66
        return $errorResponse == self::ERROR_RESPONSE;
67
    }
68
}
69