Passed
Push — master ( ff8ca7...001f87 )
by Julien
05:55 queued 01:01
created

ServiceProvider   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A register() 0 16 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\Url;
13
14
use Phalcon\Di\DiInterface;
15
use Phalcon\Mvc;
16
use Zemit\Mvc\Url;
17
use Zemit\Config\ConfigInterface;
18
use Zemit\Provider\AbstractServiceProvider;
19
20
class ServiceProvider extends AbstractServiceProvider
21
{
22
    protected string $serviceName = 'url';
23
    
24 23
    public function register(DiInterface $di): void
25
    {
26 23
        $di->setShared($this->getName(), function () use ($di) {
27
            
28 1
            $config = $di->get('config');
29 1
            assert($config instanceof ConfigInterface);
30 1
            $urlConfig = $config->pathToArray('ur') ?? [];
31
            
32 1
            $router = $di->get('router');
33 1
            $url = new Url($router instanceof Mvc\RouterInterface ? $router : null);
34 1
            $url->setStaticBaseUri($urlConfig['staticBaseUri'] ?? '/');
35 1
            $url->setBaseUri($urlConfig['baseUri'] ?? '/');
36 1
            $url->setBasePath($urlConfig['basePath'] ?? '/');
37 1
            $url->setDI($di);
38
            
39 1
            return $url;
40 23
        });
41
    }
42
}
43