FunctionException::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 10
ccs 8
cts 8
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 6
nc 2
nop 2
crap 2
1
<?php
2
3
namespace mindplay\walkway;
4
5
use Closure;
6
use Exception;
7
use ReflectionFunction;
8
9
/**
10
 * Base-class for exception types, optionally adding some helpful diagnostic information
11
 * about a user-defined closure that caused a problem.
12
 */
13
abstract class FunctionException extends Exception
14
{
15
    /**
16
     * @param string       $message the error-message
17
     * @param Closure|null $func    an anonymous function related to the error-message
18
     */
19 1
    public function __construct($message, Closure $func = null)
20
    {
21 1
        if ($func !== null) {
22 1
            $fn = new ReflectionFunction($func);
23 1
            $source = $fn->getFileName() . '#' . $fn->getStartLine();
24 1
            $message = $message . ' at ' . $source;
25 1
        }
26
27 1
        parent::__construct($message);
28 1
    }
29
}
30