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

DatabaseHelper::getMethodName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 3
cp 0
crap 2
rs 10
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
}