RecordDuplicateException   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 3
c 0
b 0
f 0
lcom 0
cbo 1
dl 0
loc 38
ccs 0
cts 15
cp 0
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 1
A getField() 0 4 1
A getValue() 0 4 1
1
<?php
2
3
namespace Thruster\Component\MysqlClient\Exception;
4
5
/**
6
 * Class RecordDuplicateException
7
 *
8
 * @package Thruster\Component\MysqlClient\Exception
9
 * @author  Aurimas Niekis <[email protected]>
10
 */
11
class RecordDuplicateException extends QueryException
12
{
13
    /**
14
     * @var string
15
     */
16
    private $field;
17
18
    /**
19
     * @var string
20
     */
21
    private $value;
22
23
    public function __construct(string $message)
24
    {
25
        preg_match('/Duplicate entry \'([^\']+)\' for key \'([^\']+)\'/', $message, $matches);
26
27
        $this->value = $matches[1] ?? '';
28
        $this->field = $matches[2] ?? '';
29
30
        parent::__construct($message, 1062);
31
    }
32
33
    /**
34
     * @return string
35
     */
36
    public function getField()
37
    {
38
        return $this->field;
39
    }
40
41
    /**
42
     * @return string
43
     */
44
    public function getValue()
45
    {
46
        return $this->value;
47
    }
48
}
49