PdoException::__construct()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 13
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 13
rs 9.2
c 0
b 0
f 0
cc 4
eloc 9
nc 4
nop 1
1
<?php
2
/*
3
 * This file is part of the Borobudur-Cqrs package.
4
 *
5
 * (c) Hexacodelabs <http://hexacodelabs.com>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace Borobudur\Cqrs\ReadModel\Storage\Pdo\Exception;
12
13
/**
14
 * @author      Iqbal Maulana <[email protected]>
15
 * @created     8/20/15
16
 */
17
class PdoException extends \PDOException
18
{
19
    /**
20
     * Constructor.
21
     *
22
     * @param \PDOException $e
23
     */
24
    public function __construct(\PDOException $e)
25
    {
26
        if(strstr($e->getMessage(), 'SQLSTATE[')) {
27
            preg_match('/SQLSTATE\[(\w+)\] \[(\w+)\] (.*)/', $e->getMessage(), $matches);
28
            if (count($matches)) {
29
                $this->code = ($matches[1] == 'HT000' ? $matches[2] : $matches[1]);
30
                $this->message = $matches[3];
31
            } else {
32
                $this->code = $e->getCode();
33
                $this->message = $e->getMessage();
34
            }
35
        }
36
    }
37
}
38