AbstractOci8Base   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 90.48%

Importance

Changes 2
Bugs 1 Features 0
Metric Value
wmc 6
c 2
b 1
f 0
lcom 1
cbo 1
dl 0
loc 38
ccs 19
cts 21
cp 0.9048
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getError() 0 7 1
B getErrorHandler() 0 21 5
1
<?php
2
3
namespace Jpina\Oci8;
4
5
abstract class AbstractOci8Base
6
{
7
    protected static $errorHandler;
8
    protected $resource;
9
10 4
    public function getError()
11
    {
12 4
        set_error_handler($this->getErrorHandler());
13 4
        $error = oci_error($this->resource);
14 4
        restore_error_handler();
15 4
        return $error;
16
    }
17
18
    /**
19
     * @return callable
20
     */
21 103
    protected static function getErrorHandler()
22
    {
23 103
        if (!static::$errorHandler) {
24 40
            static::$errorHandler = function ($severity, $message, $file = '', $line = 0) {
25 40
                restore_error_handler();
26 40
                $code = 0;
27
28 40
                $patterns = array('/ORA-(\d+)/', '/OCI-(\d+)/');
29 40
                foreach ($patterns as $pattern) {
30 40
                    preg_match($pattern, $message, $matches);
31 40
                    if (is_array($matches) && array_key_exists(1, $matches)) {
32 10
                        $code = (int) $matches[1];
33 10
                    }
34 40
                }
35
36 40
                throw new Oci8Exception($message, $code, $severity, $file, $line);
37
            };
38
        }
39
40 103
        return static::$errorHandler;
41
    }
42
}
43