RecordDuplicateException::getValue()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 2
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