PdoException   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 0
dl 0
loc 21
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 13 4
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