Completed
Push — master ( 408932...ce7eb5 )
by Dawid
06:58
created

StorageManager   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 14
dl 0
loc 62
ccs 0
cts 25
cp 0
rs 10
c 0
b 0
f 0
wmc 13

11 Methods

Rating   Name   Duplication   Size   Complexity  
A getDefaultConnection() 0 6 2
A hasDefaultConnection() 0 3 1
A __construct() 0 1 1
A getRepository() 0 2 1
A addRepository() 0 2 1
A getConnection() 0 7 2
A configure() 0 3 1
A getEntityManager() 0 2 1
A hasConnection() 0 3 1
A addConnection() 0 3 1
A hasRepository() 0 2 1
1
<?php declare(strict_types=1);
2
3
namespace Igni\Storage;
4
5
use Igni\Storage\Driver\Connection;
6
use Igni\Storage\Driver\ConnectionManager;
7
use Igni\Storage\Exception\StorageException;
8
9
final class StorageManager
10
{
11
    private static $connections = [];
12
    private static $defaultConnection;
13
    private static $storage;
14
15
    private function __construct() {}
16
17
    public static function configure()
18
    {
19
        self::$storage = $storage;
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $storage seems to be never defined.
Loading history...
20
    }
21
22
    public static function addConnection(Connection $connection, string $name = 'default'): void
23
    {
24
        ConnectionManager::addConnection($connection, $name);
25
    }
26
27
    public static function hasConnection(string $name): bool
28
    {
29
        return ConnectionManager::hasConnection($name);
30
    }
31
32
    public static function hasDefaultConnection(): bool
33
    {
34
        return self::$defaultConnection !== null;
35
    }
36
37
    public static function getDefaultConnection(): Connection
38
    {
39
        if (!self::hasDefaultConnection()) {
40
            throw StorageException::forNotRegisteredConnection('default');
41
        }
42
        return self::$defaultConnection;
43
    }
44
45
    public static function getConnection(string $name): Connection
46
    {
47
        if (!self::hasConnection($name)) {
48
            throw StorageException::forNotRegisteredConnection($name);
49
        }
50
51
        return self::$connections[$name];
52
    }
53
54
    public static function getRepository(string $entity): Repository
0 ignored issues
show
Unused Code introduced by
The parameter $entity is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

54
    public static function getRepository(/** @scrutinizer ignore-unused */ string $entity): Repository

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
55
    {
56
57
    }
0 ignored issues
show
Bug Best Practice introduced by
In this branch, the function will implicitly return null which is incompatible with the type-hinted return Igni\Storage\Repository. Consider adding a return statement or allowing null as return value.

For hinted functions/methods where all return statements with the correct type are only reachable via conditions, ?null? gets implicitly returned which may be incompatible with the hinted type. Let?s take a look at an example:

interface ReturnsInt {
    public function returnsIntHinted(): int;
}

class MyClass implements ReturnsInt {
    public function returnsIntHinted(): int
    {
        if (foo()) {
            return 123;
        }
        // here: null is implicitly returned
    }
}
Loading history...
58
59
    public static function hasRepository(string $entity): bool
0 ignored issues
show
Unused Code introduced by
The parameter $entity is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

59
    public static function hasRepository(/** @scrutinizer ignore-unused */ string $entity): bool

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
60
    {
61
62
    }
0 ignored issues
show
Bug Best Practice introduced by
In this branch, the function will implicitly return null which is incompatible with the type-hinted return boolean. Consider adding a return statement or allowing null as return value.

For hinted functions/methods where all return statements with the correct type are only reachable via conditions, ?null? gets implicitly returned which may be incompatible with the hinted type. Let?s take a look at an example:

interface ReturnsInt {
    public function returnsIntHinted(): int;
}

class MyClass implements ReturnsInt {
    public function returnsIntHinted(): int
    {
        if (foo()) {
            return 123;
        }
        // here: null is implicitly returned
    }
}
Loading history...
63
64
    public static function addRepository(Repository ...$repositories): void
0 ignored issues
show
Unused Code introduced by
The parameter $repositories is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

64
    public static function addRepository(/** @scrutinizer ignore-unused */ Repository ...$repositories): void

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
65
    {
66
67
    }
68
69
    public static function getEntityManager(): EntityManager
70
    {
71
72
    }
0 ignored issues
show
Bug Best Practice introduced by
In this branch, the function will implicitly return null which is incompatible with the type-hinted return Igni\Storage\EntityManager. Consider adding a return statement or allowing null as return value.

For hinted functions/methods where all return statements with the correct type are only reachable via conditions, ?null? gets implicitly returned which may be incompatible with the hinted type. Let?s take a look at an example:

interface ReturnsInt {
    public function returnsIntHinted(): int;
}

class MyClass implements ReturnsInt {
    public function returnsIntHinted(): int
    {
        if (foo()) {
            return 123;
        }
        // here: null is implicitly returned
    }
}
Loading history...
73
}
74