Completed
Push — master ( e401e5...bd7189 )
by Julien
01:48
created

ContainerXmlMap::__construct()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 78
Code Lines 63

Duplication

Lines 0
Ratio 0 %

Importance

Changes 7
Bugs 1 Features 5
Metric Value
c 7
b 1
f 5
dl 0
loc 78
rs 8.9019
cc 1
eloc 63
nc 1
nop 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
/**
3
 * Fwk
4
 *
5
 * Copyright (c) 2011-2012, Julien Ballestracci <[email protected]>.
6
 * All rights reserved.
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 *
11
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
12
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
13
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
14
 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
15
 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
16
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
17
 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
18
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
19
 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
20
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
21
 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
22
 * POSSIBILITY OF SUCH DAMAGE.
23
 *
24
 * PHP Version 5.3
25
 *
26
 * @category  DependencyInjection
27
 * @package   Fwk\Di
28
 * @author    Julien Ballestracci <[email protected]>
29
 * @copyright 2011-2014 Julien Ballestracci <[email protected]>
30
 * @license   http://www.opensource.org/licenses/bsd-license.php  BSD License
31
 * @link      http://www.nitronet.org/fwk
32
 */
33
namespace Fwk\Di\Xml;
34
35
use Fwk\Xml\Map;
36
use Fwk\Xml\Path;
37
38
/**
39
 * ContainerXmlMap
40
 * 
41
 * Describes the Map to parse an Xml container.
42
 *
43
 * @category Xml
44
 * @package  Fwk\Di
45
 * @author   Julien Ballestracci <[email protected]>
46
 * @license  http://www.opensource.org/licenses/bsd-license.php  BSD License
47
 * @link     http://www.nitronet.org/fwk
48
 */
49
class ContainerXmlMap extends Map
50
{
51
    /**
52
     * Constructor
53
     * 
54
     * Initialize Map paths to return an array of definitions
55
     * 
56
     * @void
57
     */
58
    public function __construct()
59
    {
60
        $this->add(
61
            Path::factory(
62
                '/dependency-injection/class-definition', 
63
                'classDefs', 
64
                array()
65
            )->loop(true, '@name')
66
            ->attribute('shared')
67
            ->attribute('lazy')
68
            ->attribute('class', 'className')
69
            ->addChildren(
70
                Path::factory('argument', 'arguments', array())
71
                ->loop(true)
72
                ->value('value')
73
            )->addChildren(
74
                Path::factory('call', 'methodsCalls', array())
75
                ->loop(true)
76
                ->attribute('method')
77
                ->addChildren(
78
                    Path::factory('argument', 'arguments', array())
79
                    ->loop(true)
80
                    ->value('value')
81
                )
82
            )->addChildren(
83
                Path::factory('data/param', 'data', array())
84
                    ->loop(true, '@key')
85
                    ->value('value')
86
            )
87
        );
88
        
89
        $this->add(
90
            Path::factory(
91
                '/dependency-injection/definition', 
92
                'definitions', 
93
                array()
94
            )->loop(true, '@name')
95
            ->attribute('shared')
96
            ->value('value')
97
        );
98
        
99
        $this->add(
100
            Path::factory('/dependency-injection/ini', 'ini', array())
101
            ->loop(true)
102
            ->attribute('category')
103
            ->value('value')
104
        );
105
        
106
        $this->add(
107
            Path::factory(
108
                '/dependency-injection/array-definition', 
109
                'arrayDefs', 
110
                array()
111
            )->loop(true, '@name')
112
            ->attribute('shared')
113
            ->addChildren(
114
                Path::factory('param', 'params', array())
115
                ->loop(true)
116
                ->attribute('key')
117
                ->value('value')
118
            )
119
            ->addChildren(
120
                Path::factory('data/param', 'data', array())
121
                    ->loop(true, '@key')
122
                    ->value('value')
123
            )
124
        );
125
126
        $this->add(
127
            Path::factory(
128
                '/dependency-injection/listener',
129
                'listeners',
130
                array()
131
            )->loop(true)
132
            ->attribute('class')
133
            ->attribute('service')
134
        );
135
    }
136
}