MongoDbDuplicateError   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 13
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 13
c 0
b 0
f 0
wmc 1
lcom 0
cbo 1
ccs 6
cts 6
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A from() 0 10 1
1
<?php
2
/**
3
 * Created by gerk on 30.10.17 06:59
4
 */
5
6
namespace PeekAndPoke\Component\Slumber\Data\MongoDb\Error;
7
8
use MongoDB\Driver\Exception\WriteException;
9
use PeekAndPoke\Component\Slumber\Data\Error\DuplicateError;
10
11
/**
12
 *
13
 *
14
 * @author Karsten J. Gerber <[email protected]>
15
 */
16
class MongoDbDuplicateError extends DuplicateError
17
{
18 2
    public static function from(WriteException $exception)
19
    {
20 2
        preg_match('/^E11000 duplicate key error collection: (.*) index: (.*) dup key: (.*)$/', $exception->getMessage(), $matches);
21
22 2
        $table = $matches[1] ?? '';
23 2
        $index = $matches[2] ?? '';
24 2
        $data  = $matches[3] ?? '';
25
26 2
        return new static($exception->getMessage(), $table, $index, $data, $exception);
27
    }
28
}
29