Passed
Push — 2.x ( e966a7...a2237c )
by Terry
02:13
created

ItemMysqlDriver   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 14
c 1
b 0
f 0
dl 0
loc 37
rs 10
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A get() 0 28 2
1
<?php
2
/*
3
 * This file is part of the Shieldon package.
4
 *
5
 * (c) Terry L. <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
declare(strict_types=1);
12
13
namespace Shieldon\Firewall\Firewall\Driver;
14
15
use Shieldon\Firewall\Driver\MysqlDriver;
16
use PDO;
17
use PDOException;
18
19
/**
20
 * Get MySQL driver.
21
 */
22
class ItemMysqlDriver
23
{
24
    /**
25
     * Initialize and get the instance.
26
     *
27
     * @param array $setting The configuration of that driver.
28
     *
29
     * @return RedisDriver|null
0 ignored issues
show
Bug introduced by
The type Shieldon\Firewall\Firewall\Driver\RedisDriver was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
30
     */
31
    public static function get(array $setting)
32
    {
33
        $instance = null;
34
35
        try {
36
37
            // Create a PDO instance.
38
            $pdoInstance = new PDO(
39
                'mysql:host=' 
40
                    . $setting['host']   . ';dbname=' 
41
                    . $setting['dbname'] . ';charset=' 
42
                    . $setting['charset']
43
                , (string) $setting['user']
44
                , (string) $setting['pass']
45
            );
46
47
            // Use MySQL data driver.
48
            $instance = new MysqlDriver($pdoInstance);
49
50
        // @codeCoverageIgnoreStart
51
52
        } catch(PDOException $e) {
53
            echo $e->getMessage();
54
        }
55
56
        // @codeCoverageIgnoreEnd
57
58
        return $instance;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $instance also could return the type Shieldon\Firewall\Driver\MysqlDriver which is incompatible with the documented return type Shieldon\Firewall\Firewall\Driver\RedisDriver|null.
Loading history...
59
    }
60
}