Passed
Push — master ( 12ed59...661264 )
by Julien
05:22
created

ServiceProvider   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 1 Features 0
Metric Value
wmc 2
eloc 9
c 1
b 1
f 0
dl 0
loc 25
ccs 8
cts 8
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A register() 0 11 2
1
<?php
2
/**
3
 * This file is part of the Zemit Framework.
4
 *
5
 * (c) Zemit Team <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE.txt
8
 * file that was distributed with this source code.
9
 */
10
11
namespace Zemit\Provider\Url;
12
13
use Phalcon\Di\DiInterface;
14
use Phalcon\Mvc\RouterInterface;
15
use Zemit\Url;
16
use Zemit\Provider\AbstractServiceProvider;
17
18
/**
19
 * Class ServiceProvider
20
 *
21
 * @author Julien Turbide <[email protected]>
22
 * @copyright Zemit Team <[email protected]>
23
 *
24
 * @since 1.0
25
 * @version 1.0
26
 *
27
 * @package Zemit\Provider\Url
28
 */
29
class ServiceProvider extends AbstractServiceProvider
30
{
31
    /**
32
     * The Service name.
33
     * @var string
34
     */
35
    protected $serviceName = 'url';
36
    
37
    /**
38
     * {@inheritdoc}
39
     * The URL component is used to generate all kind of urls in the application.
40
     *
41
     * @return void
42
     */
43 7
    public function register(DiInterface $di): void
44
    {
45 7
        $di->setShared($this->getName(), function() use ($di) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space after FUNCTION keyword; 0 found
Loading history...
46 1
            $config = $di->get('config')->app;
47 1
            $router = $di->get('router');
48
            
49 1
            $url = new Url($router instanceof RouterInterface ? $router : null);
50 1
            $url->setStaticBaseUri($config->staticUri ?? '/');
51 1
            $url->setBaseUri($config->uri ?? '/');
52
            
53 1
            return $url;
54 7
        });
55
    }
56
}
57