MongoDbGuard   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 75%

Importance

Changes 0
Metric Value
dl 0
loc 22
c 0
b 0
f 0
wmc 4
lcom 0
cbo 3
ccs 6
cts 8
cp 0.75
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A guard() 0 18 4
1
<?php
2
/**
3
 * Created by gerk on 03.12.17 18:20
4
 */
5
6
namespace PeekAndPoke\Component\Slumber\Data\MongoDb;
7
8
use MongoDB\Driver\Exception\ConnectionException;
9
use MongoDB\Driver\Exception\WriteException;
10
use PeekAndPoke\Component\Slumber\Data\MongoDb\Error\MongoDbConnectionError;
11
use PeekAndPoke\Component\Slumber\Data\MongoDb\Error\MongoDbDuplicateError;
12
use PeekAndPoke\Component\Slumber\Data\MongoDb\Error\MongoDbUnknownError;
13
14
/**
15
 * Guards the execution of connecting, reading, writing and normalize exceptions
16
 *
17
 * @author Karsten J. Gerber <[email protected]>
18
 */
19
class MongoDbGuard
20
{
21
22 34
    public static function guard(callable $action)
23
    {
24
        try {
25 34
            return $action();
26
        }
27
            // duplicate key exception
28 9
        catch (WriteException $e) {
0 ignored issues
show
Bug introduced by
The class MongoDB\Driver\Exception\WriteException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
29 2
            throw MongoDbDuplicateError::from($e);
30
        }
31
            // connection exception
32 7
        catch (ConnectionException $e) {
0 ignored issues
show
Bug introduced by
The class MongoDB\Driver\Exception\ConnectionException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
33 7
            throw MongoDbConnectionError::from($e);
34
        }
35
            // general mongodb exception
36
        catch (\Exception $e) {
37
            throw MongoDbUnknownError::from($e);
38
        }
39
    }
40
}
41