Completed
Pull Request — master (#6)
by Rougin
03:51
created

InstanceHelper   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
lcom 1
cbo 1
dl 0
loc 34
ccs 9
cts 9
cp 1
rs 10
c 1
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A create() 0 6 2
A get() 0 8 2
1
<?php
2
3
namespace Rougin\Credo\Helpers;
4
5
use Rougin\Credo\Credo;
6
7
/**
8
 * Instance Helper
9
 *
10
 * @package Credo
11
 * @author  Rougin Royce Gutib <[email protected]>
12
 */
13
class InstanceHelper
14
{
15
    /**
16
     * @var \Rougin\Credo\Credo
17
     */
18
    protected static $credo;
19
20
    /**
21
     * Factory method to create Credo instance.
22
     *
23
     * @param  \CI_DB_query_builder|null $database
24
     * @return void
25
     */
26 3
    public static function create($database = null)
27
    {
28 3
        if (empty(self::$credo)) {
29 3
            self::$credo = new Credo($database);
0 ignored issues
show
Bug introduced by
It seems like $database defined by parameter $database on line 26 can be null; however, Rougin\Credo\Credo::__construct() does not accept null, maybe add an additional type check?

It seems like you allow that null is being passed for a parameter, however the function which is called does not seem to accept null.

We recommend to add an additional type check (or disallow null for the parameter):

function notNullable(stdClass $x) { }

// Unsafe
function withoutCheck(stdClass $x = null) {
    notNullable($x);
}

// Safe - Alternative 1: Adding Additional Type-Check
function withCheck(stdClass $x = null) {
    if ($x instanceof stdClass) {
        notNullable($x);
    }
}

// Safe - Alternative 2: Changing Parameter
function withNonNullableParam(stdClass $x) {
    notNullable($x);
}
Loading history...
30 3
        }
31 3
    }
32
33
    /**
34
     * Returns the Credo instance.
35
     *
36
     * @return \Rougin\Credo\Credo
37
     */
38 15
    public static function get()
39
    {
40 15
        if (! empty(self::$credo)) {
41 15
            return self::$credo;
42
        }
43
44 3
        return null;
45
    }
46
}
47