Exception::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 4
dl 0
loc 5
ccs 4
cts 4
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * @link https://www.yiiframework.com/
4
 * @copyright Copyright (c) 2008 Yii Software LLC
5
 * @license https://www.yiiframework.com/license/
6
 */
7
8
namespace yii\db;
9
10
/**
11
 * Exception represents an exception that is caused by some DB-related operations.
12
 *
13
 * @author Qiang Xue <[email protected]>
14
 * @since 2.0
15
 */
16
class Exception extends \yii\base\Exception
17
{
18
    /**
19
     * @var array the error info provided by a PDO exception. This is the same as returned
20
     * by [PDO::errorInfo](https://www.php.net/manual/en/pdo.errorinfo.php).
21
     */
22
    public $errorInfo = [];
23
24
25
    /**
26
     * Constructor.
27
     * @param string $message PDO error message
28
     * @param array $errorInfo PDO error info
29
     * @param string $code PDO error code
30
     * @param \Throwable|null $previous The previous exception used for the exception chaining.
31
     */
32 2
    public function __construct($message, $errorInfo = [], $code = '', $previous = null)
33
    {
34 2
        parent::__construct($message, 0, $previous);
35 2
        $this->errorInfo = $errorInfo;
36 2
        $this->code = $code;
37
    }
38
39
    /**
40
     * @return string the user-friendly name of this exception
41
     */
42
    public function getName()
43
    {
44
        return 'Database Exception';
45
    }
46
47
    /**
48
     * @return string readable representation of exception
49
     */
50
    public function __toString()
51
    {
52
        return parent::__toString() . PHP_EOL
53
        . 'Additional Information:' . PHP_EOL . print_r($this->errorInfo, true);
0 ignored issues
show
Bug introduced by
Are you sure print_r($this->errorInfo, true) of type string|true can be used in concatenation? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

53
        . 'Additional Information:' . PHP_EOL . /** @scrutinizer ignore-type */ print_r($this->errorInfo, true);
Loading history...
54
    }
55
}
56