Completed
Push — master ( 19c73b...a73acd )
by Erin
01:51
created

AssertException   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 44
rs 10
c 0
b 0
f 0
wmc 3
lcom 0
cbo 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A handle() 0 4 1
A __construct() 0 18 2
1
<?php
2
namespace Peridot;
3
4
use Exception;
5
use ReflectionClass;
6
7
/**
8
 * Represents a failed assert() call.
9
 *
10
 * @package Peridot
11
 */
12
class AssertException extends Exception
13
{
14
    /**
15
     * Handle a failed assert() call.
16
     *
17
     * @param string $file
18
     * @param int $line
19
     * @param string $expression
20
     * @param string $description
21
     *
22
     * @return self
23
     */
24
    public static function handle($file, $line, $expression, $description)
25
    {
26
        throw new self($file, $line, $expression, $description);
27
    }
28
29
    /**
30
     * Construct a new assert exception.
31
     *
32
     * @param string $file
33
     * @param int $line
34
     * @param string $expression
35
     * @param string $description
36
     */
37
    public function __construct($file, $line, $expression, $description)
38
    {
39
        if ($expression) {
40
            $message = sprintf('%s %s', $expression, $description);
41
        } else {
42
            $message = $description;
43
        }
44
45
        parent::__construct($message);
46
47
        $this->file = $file;
48
        $this->line = $line;
49
50
        $reflector = new ReflectionClass('Exception');
51
        $traceProperty = $reflector->getProperty('trace');
52
        $traceProperty->setAccessible(true);
53
        $traceProperty->setValue($this, array());
54
    }
55
}
56