Passed
Push — master ( cb6c43...38c078 )
by Mike
06:01
created

DatabaseHelper::getHelper()   A

Complexity

Conditions 5
Paths 7

Size

Total Lines 18
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 30

Importance

Changes 0
Metric Value
cc 5
eloc 9
nc 7
nop 1
dl 0
loc 18
ccs 0
cts 15
cp 0
crap 30
rs 9.6111
c 0
b 0
f 0
1
<?php
2
3
4
namespace Xervice\Database\LocatorHelper;
5
6
7
use Xervice\Core\HelperClass\HelperInterface;
8
use Xervice\Core\Locator\Proxy\ProxyInterface;
9
10
class DatabaseHelper implements HelperInterface
11
{
12
    /**
13
     * @var array
14
     */
15
    private $databaseContainer;
16
17
    /**
18
     * @return string
19
     */
20
    public function getMethodName(): string
21
    {
22
        return 'queryContainer';
23
    }
24
25
    /**
26
     * @param \Xervice\Core\Locator\Proxy\ProxyInterface $proxy
27
     *
28
     * @return mixed|void
29
     */
30
    public function getHelper(ProxyInterface $proxy)
31
    {
32
        $serviceName = $proxy->getServiceName();
33
34
        if (!isset($this->databaseContainer[$serviceName])) {
35
            foreach ($proxy->getServiceNamespaces('QueryContainer') as $class) {
36
                if (class_exists($class)) {
37
                    $this->databaseContainer[$serviceName] = new $class();
38
                    break;
39
                }
40
            }
41
42
            if ($this->databaseContainer[$serviceName] === null) {
43
                $this->databaseContainer[$serviceName] = new EmptyQueryContainer();
44
            }
45
        }
46
47
        return $this->databaseContainer[$serviceName];
48
    }
49
}