OrmException::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 4
crap 1
1
<?php
2
namespace Nkey\Caribu\Orm;
3
4
/**
5
 * Derived exception for the Caribu package
6
 *
7
 * This class is part of Caribu package
8
 *
9
 * @author Maik Greubel <[email protected]>
10
 */
11
class OrmException extends \Generics\GenericsException
12
{
13
14
    /**
15
     * Create a new OrmException instance
16
     *
17
     * @param string $message
18
     *            The message to throw
19
     * @param array $context
20
     *            Optional context key-value-pairs
21
     * @param int $number
22
     *            Optional exception code
23
     * @param \Exception $previous
24
     *            Optional previous occured exception to embed
25
     */
26 7
    public function __construct(string $message, array $context = array(), int $number = 0, \Exception $previous = null)
27
    {
28 7
        parent::__construct($message, $context, $number, $previous);
29 7
    }
30
31
    /**
32
     * Throw derived ORMException setting the previous as internal
33
     *
34
     * @param \Exception $exception
35
     *            The original exception
36
     * @param string $message
37
     *            Optional message to embed
38
     * @param int $code
39
     *            Optional exception code to embed
40
     *            
41
     * @throws OrmException
42
     */
43 3
    public static function fromPrevious(\Exception $exception, string $message = null, int $code = 0)
44
    {
45 3
        return new self("Exception {type} occured:{message}", array(
46 3
            'type' => get_class($exception),
47 3
            'message' => (is_null($message) ? "" : " {$message}")
48 3
        ), ($code == 0 ? $exception->getCode() : $code), $exception);
49
    }
50
}
51