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

ItemSqliteDriver   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 11
c 1
b 0
f 0
dl 0
loc 32
rs 10
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A get() 0 23 3
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\SqliteDriver;
16
use PDO;
17
use PDOException;
18
19
/**
20
 * Get SQLite driver.
21
 */
22
class ItemSqliteDriver
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
        if (empty($setting['directory_path'])) {
36
            return $instance;
37
        }
38
39
        try { 
40
            // Specify the sqlite file location.
41
            $sqliteLocation = $setting['directory_path'] . '/shieldon.sqlite3';
42
            $pdoInstance = new PDO('sqlite:' . $sqliteLocation);
43
            $instance = new SqliteDriver($pdoInstance);
44
45
        // @codeCoverageIgnoreStart
46
47
        } catch(PDOException $e) {
48
            echo $e->getMessage();
49
        }
50
51
        // @codeCoverageIgnoreEnd
52
53
        return $instance;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $instance also could return the type Shieldon\Firewall\Driver\SqliteDriver which is incompatible with the documented return type Shieldon\Firewall\Firewall\Driver\RedisDriver|null.
Loading history...
54
    }
55
}