PathServiceProvider::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 2
dl 0
loc 5
ccs 3
cts 3
cp 1
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
namespace Germania\PathServiceProvider;
3
4
use Pimple\Container;
5
use Pimple\ServiceProviderInterface;
6
7
8
class PathServiceProvider implements ServiceProviderInterface
9
{
10
11
    /**
12
     * @var Callable
13
     */
14
    public $prefixer;
15
16
17
    /**
18
     * @var array
19
     */
20
    public $paths = [];
21
22
23
    /**
24
     * @var Container
25
     */
26
    public $dic;
27
28
29
    /**
30
     * @param array         $paths    Optional array with paths
31
     * @param Callable|null $prefixer Optional callable that prefixes the paths.
32
     */
33 5
    public function __construct ( $paths = array(), Callable $prefixer = null)
34
    {
35 5
        $this->paths = $paths;
36
        $this->prefixer = $prefixer ?: function( $p ) { return $p; } ;
37 5
    }
38
39
40
    /**
41
     * @implements ServiceProviderInterface
42
     */
43 4
    public function register(Container $dic)
44
    {
45
46
        /**
47
         * @return array
48
         */
49 1
        $dic['Paths'] = function($dic) {
0 ignored issues
show
Unused Code introduced by
The parameter $dic is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
50 5
            return $this->paths;
51
        };
52
53
54
        /**
55
         * @return Callable
56
         */
57 1
        $dic['Paths.Prefixer'] = function($dic) {
0 ignored issues
show
Unused Code introduced by
The parameter $dic is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
58 5
            return $this->prefixer;
59
        };
60
61
62
        /**
63
         * @return array
64
         */
65 2
        $dic['Paths.absolute'] = function ($dic) {
66 5
            $paths = $dic['Paths'];
67 5
            $prefixer = $dic['Paths.Prefixer'];
68
69 5
            return $prefixer( $paths );
70
        };
71
72 5
    }
73
}
74
75