Completed
Push — master ( 356849...08f0e0 )
by Changwan
05:29
created

CannotCallMethodException::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 7
nc 2
nop 2
dl 0
loc 10
ccs 8
cts 8
cp 1
crap 2
rs 9.4285
c 0
b 0
f 0
1
<?php
2
namespace Wandu\Http\Exception;
3
4
use RuntimeException;
5
6
class CannotCallMethodException 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 8
    public function __construct($methodName, $className = null)
19
    {
20 8
        $this->methodName = $methodName;
21 8
        $this->className = $className;
22 8
        $message = "cannot call {$methodName}";
23 8
        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 8
            $message .= " in {$className}";
25
        }
26 8
        parent::__construct($message);
27 8
    }
28
29
    /**
30
     * @return string
31
     */
32 8
    public function getMethodName()
33
    {
34 8
        return $this->methodName;
35
    }
36
37
    /**
38
     * @return string
39
     */
40
    public function getClassName()
41
    {
42
        return $this->className;
43
    }
44
}
45