Completed
Push — master ( 7c429e...75748b )
by Michael
03:23
created

XsdWiring::wire()   B

Complexity

Conditions 5
Paths 8

Size

Total Lines 57
Code Lines 34

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 57
rs 8.7433
cc 5
eloc 34
nc 8
nop 1

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
 * Contains class XsdWiring.
4
 *
5
 * PHP version 5.5
6
 *
7
 * LICENSE:
8
 * This file is part of Yet Another Php Eve Api Library also know as Yapeal
9
 * which can be used to access the Eve Online API data and place it into a
10
 * database.
11
 * Copyright (C) 2016 Michael Cummings
12
 *
13
 * This program is free software: you can redistribute it and/or modify it
14
 * under the terms of the GNU Lesser General Public License as published by the
15
 * Free Software Foundation, either version 3 of the License, or (at your
16
 * option) any later version.
17
 *
18
 * This program is distributed in the hope that it will be useful, but WITHOUT
19
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
21
 * for more details.
22
 *
23
 * You should have received a copy of the GNU Lesser General Public License
24
 * along with this program. If not, see
25
 * <http://www.gnu.org/licenses/>.
26
 *
27
 * You should be able to find a copy of this license in the LICENSE.md file. A
28
 * copy of the GNU GPL should also be available in the GNU-GPL.md file.
29
 *
30
 * @copyright 2016 Michael Cummings
31
 * @license   LGPL-3.0+
32
 * @author    Michael Cummings <[email protected]>
33
 */
34
namespace Yapeal\Configuration;
35
36
use Twig_Environment;
37
use Twig_Loader_Filesystem;
38
use Twig_SimpleFilter;
39
use Yapeal\Container\ContainerInterface;
40
41
/**
42
 * Class XsdWiring.
43
 */
44
class XsdWiring implements WiringInterface
45
{
46
    /**
47
     * @param ContainerInterface $dic
48
     *
49
     * @return self Fluent interface.
50
     * @throws \LogicException
51
     * @throws \InvalidArgumentException
52
     */
53
    public function wire(ContainerInterface $dic)
54
    {
55
        if (empty($dic['Yapeal.Xsd.Creator'])) {
56
            $dic['Yapeal.Xsd.Creator'] = $dic->factory(
57
                function ($dic) {
58
                    $loader = new Twig_Loader_Filesystem($dic['Yapeal.Xsd.dir']);
59
                    $twig = new Twig_Environment(
60
                        $loader, ['debug' => true, 'strict_variables' => true, 'autoescape' => false]
61
                    );
62
                    $filter = new Twig_SimpleFilter(
63
                        'ucFirst', function ($value) {
64
                        return ucfirst($value);
65
                    }
66
                    );
67
                    $twig->addFilter($filter);
68
                    $filter = new Twig_SimpleFilter(
69
                        'lcFirst', function ($value) {
70
                        return lcfirst($value);
71
                    }
72
                    );
73
                    $twig->addFilter($filter);
74
                    /**
75
                     * @var \Yapeal\Xsd\Creator $create
76
                     */
77
                    $create = new $dic['Yapeal.Xsd.create']($twig, $dic['Yapeal.Xsd.dir']);
78
                    if (array_key_exists('Yapeal.Create.overwrite', $dic)) {
79
                        $create->setOverwrite($dic['Yapeal.Create.overwrite']);
80
                    }
81
                    return $create;
82
                }
83
            );
84
        }
85
        if (empty($dic['Yapeal.Xsd.Validator'])) {
86
            $dic['Yapeal.Xsd.Validator'] = $dic->factory(
87
                function ($dic) {
88
                    return new $dic['Yapeal.Xsd.validate']($dic['Yapeal.Xsd.dir']);
89
                }
90
            );
91
        }
92
        if (!isset($dic['Yapeal.Event.Mediator'])) {
93
            $mess = 'Tried to call Mediator before it has been added';
94
            throw new \LogicException($mess);
95
        }
96
        /**
97
         * @var \Yapeal\Event\MediatorInterface $mediator
98
         */
99
        $mediator = $dic['Yapeal.Event.Mediator'];
100
        $mediator->addServiceSubscriberByEventList(
101
            'Yapeal.Xsd.Creator',
102
            ['Yapeal.EveApi.create' => ['createXsd', 'last']]
103
        );
104
        $mediator->addServiceSubscriberByEventList(
105
            'Yapeal.Xsd.Validator',
106
            ['Yapeal.EveApi.validate' => ['validateEveApi', 'last']]
107
        );
108
        return $this;
109
    }
110
}
111