Test Failed
Push — master ( 62e8aa...e74fb5 )
by Julien
04:23
created

ServiceProvider   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 12
c 1
b 0
f 0
dl 0
loc 22
ccs 0
cts 11
cp 0
rs 10
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A register() 0 18 2
1
<?php
2
3
/**
4
 * This file is part of the Zemit Framework.
5
 *
6
 * (c) Zemit Team <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE.txt
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Zemit\Provider\Annotations;
13
14
use Phalcon\Annotations\Adapter\Memory;
15
use Phalcon\Di\DiInterface;
16
use Zemit\Config\ConfigInterface;
17
use Zemit\Provider\AbstractServiceProvider;
18
19
class ServiceProvider extends AbstractServiceProvider
20
{
21
    protected string $serviceName = 'annotations';
22
    
23
    public function register(DiInterface $di): void
24
    {
25
        $di->setShared($this->getName(), function () use ($di) {
26
    
27
            // config
28
            $config = $di->get('config');
29
            assert($config instanceof ConfigInterface);
30
            $annotationsConfig = $config->pathToArray('annotations', []);
31
    
32
            // options
33
            $driverName = $annotationsConfig['driver'] ?? 'memory';
34
            $driverOptions = $annotationsConfig['drivers'][$driverName] ?? [];
35
            $defaultOptions = $annotationsConfig['default'] ?? [];
36
            $options = array_merge($defaultOptions, $driverOptions);
37
    
38
            // adapter
39
            $adapter = $driverOptions['adapter'] ?: Memory::class;
40
            return new $adapter($options);
41
        });
42
    }
43
}
44