OrmExceptionHandler   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 87.5%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
lcom 0
cbo 2
dl 0
loc 37
ccs 7
cts 8
cp 0.875
rs 10
c 1
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A handleException() 0 17 4
1
<?php
2
namespace Nkey\Caribu\Orm;
3
4
/**
5
 * Exception handling functionality
6
 *
7
 * This class is part of Caribu package
8
 *
9
 * @author Maik Greubel <[email protected]>
10
 */
11
trait OrmExceptionHandler
12
{
13
14
    /**
15
     * Handle a previous occured pdo exception
16
     *
17
     * @param \Nkey\Caribu\Orm\Orm $orm
18
     *            The orm instance
19
     * @param \PDOStatement $statement
20
     *            The statement which caused the exception to rollback
21
     * @param \Exception $ex
22
     *            The exception cause
23
     * @param string $message
24
     *            Optional message
25
     * @param int $code
26
     *            Optional code
27
     *            
28
     * @return OrmException
29
     */
30 2
    private static function handleException(Orm $orm, $statement, \Exception $ex, string $message = null, int $code = 0)
31
    {
32 2
        $toThrow = OrmException::fromPrevious($ex, $message, $code);
33
        
34
        try {
35 2
        	if ($statement != null && $statement instanceof \PDOStatement) {
36 1
                $statement->closeCursor();
37
            }
38 2
            unset($statement);
39
        } catch (\PDOException $cex) {
40
            // Ignore close cursor exception
41
        }
42
        
43 2
        $toThrow = $orm->rollBackTX($toThrow);
44
        
45 2
        return $toThrow;
46
    }
47
}
48