Completed
Push — master ( 595e4b...944328 )
by Changwan
07:08
created

NotAllowedMethodException::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 7
nc 2
nop 2
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
1
<?php
2
namespace Wandu\Config\Exception;
3
4
use RuntimeException;
5
6
class NotAllowedMethodException extends RuntimeException
7
{
8
    /** @var string */
9
    protected $methodName;
10
11
    /** @var string */
12
    protected $className;
13
14
    /**
15
     * @param string $methodName
16
     * @param string $className
17
     */
18
    public function __construct($methodName, $className = null)
19
    {
20
        $this->methodName = $methodName;
21
        $this->className = $className;
22
        $message = "cannot call {$methodName}";
23
        if ($className) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $className of type string|null is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
24
            $message .= " in {$className}";
25
        }
26
        parent::__construct($message);
27
    }
28
29
    /**
30
     * @return string
31
     */
32
    public function getMethodName()
33
    {
34
        return $this->methodName;
35
    }
36
37
    /**
38
     * @return string
39
     */
40
    public function getClassName()
41
    {
42
        return $this->className;
43
    }
44
}
45