Completed
Push — master ( a4ea0b...5e2812 )
by Joschi
02:46
created

Module::configureActionDependencies()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 73
Code Lines 43

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 73
ccs 0
cts 73
cp 0
rs 9.0675
cc 1
eloc 43
nc 1
nop 1
crap 2

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
/**
4
 * apparat-server
5
 *
6
 * @category    Apparat
7
 * @package     Apparat\Server
8
 * @subpackage  Apparat\Server
9
 * @author      Joschi Kuphal <[email protected]> / @jkphl
10
 * @copyright   Copyright © 2016 Joschi Kuphal <[email protected]> / @jkphl
11
 * @license     http://opensource.org/licenses/MIT The MIT License (MIT)
12
 */
13
14
/***********************************************************************************
15
 *  The MIT License (MIT)
16
 *
17
 *  Copyright © 2016 Joschi Kuphal <[email protected]> / @jkphl
18
 *
19
 *  Permission is hereby granted, free of charge, to any person obtaining a copy of
20
 *  this software and associated documentation files (the "Software"), to deal in
21
 *  the Software without restriction, including without limitation the rights to
22
 *  use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
23
 *  the Software, and to permit persons to whom the Software is furnished to do so,
24
 *  subject to the following conditions:
25
 *
26
 *  The above copyright notice and this permission notice shall be included in all
27
 *  copies or substantial portions of the Software.
28
 *
29
 *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
30
 *  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
31
 *  FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
32
 *  COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
33
 *  IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
34
 *  CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35
 ***********************************************************************************/
36
37
namespace Apparat\Server;
38
39
use Apparat\Kernel\Ports\AbstractModule;
40
use Apparat\Kernel\Ports\Contract\DependencyInjectionContainerInterface;
41
use Apparat\Server\Domain\Contract\RouterContainerInterface;
42
use Apparat\Server\Domain\Model\Server;
43
use Apparat\Server\Domain\Service\DayService;
44
use Apparat\Server\Domain\Service\HourService;
45
use Apparat\Server\Domain\Service\MinuteService;
46
use Apparat\Server\Domain\Service\MonthService;
47
use Apparat\Server\Domain\Service\ObjectService;
48
use Apparat\Server\Domain\Service\SecondService;
49
use Apparat\Server\Domain\Service\ServiceInterface;
50
use Apparat\Server\Domain\Service\YearService;
51
use Apparat\Server\Infrastructure\AuraRouterAdapter;
52
use Apparat\Server\Ports\Action\DayAction;
53
use Apparat\Server\Ports\Action\HourAction;
54
use Apparat\Server\Ports\Action\MinuteAction;
55
use Apparat\Server\Ports\Action\MonthAction;
56
use Apparat\Server\Ports\Action\ObjectAction;
57
use Apparat\Server\Ports\Action\SecondAction;
58
use Apparat\Server\Ports\Action\YearAction;
59
use Apparat\Server\Ports\Responder\AbstractResponder;
60
use Apparat\Server\Ports\Responder\DayResponder;
61
use Apparat\Server\Ports\Responder\HourResponder;
62
use Apparat\Server\Ports\Responder\MinuteResponder;
63
use Apparat\Server\Ports\Responder\MonthResponder;
64
use Apparat\Server\Ports\Responder\ObjectResponder;
65
use Apparat\Server\Ports\Responder\ResponderInterface;
66
use Apparat\Server\Ports\Responder\SecondResponder;
67
use Apparat\Server\Ports\Responder\View\TYPO3FluidView;
68
use Apparat\Server\Ports\Responder\View\ViewInterface;
69
use Apparat\Server\Ports\Responder\YearResponder;
70
use Aura\Router\RouterContainer;
71
use Dotenv\Dotenv;
72
use Psr\Http\Message\ResponseInterface;
73
use TYPO3Fluid\Fluid\View\AbstractTemplateView;
74
use Zend\Diactoros\Response;
75
76
/**
77
 * Object module
78
 *
79
 * @package Apparat\Object
80
 * @subpackage Apparat\Object
81
 */
82
class Module extends AbstractModule
83
{
84
    /**
85
     * Module name
86
     *
87
     * @var string
88
     */
89
    const NAME = 'server';
90
91
    /**
92
     * Validate the environment
93
     *
94
     * @param Dotenv $environment Environment
95
     */
96
    protected static function validateEnvironment(Dotenv $environment)
97
    {
98
        parent::validateEnvironment($environment);
99
100
        // Validate the required environment variables
101
//        $environment->required('APPARAT_BASE_URL')->notEmpty();
102
//        $environment->required('OBJECT_DATE_PRECISION')->isInteger()->allowedValues([0, 1, 2, 3, 4, 5, 6]);
103
    }
104
105
    /**
106
     * Configure the dependency injection container
107
     *
108
     * @param DependencyInjectionContainerInterface $diContainer Dependency injection container
109
     * @return void
110
     */
111
    public function configureDependencyInjection(DependencyInjectionContainerInterface $diContainer)
112
    {
113
        parent::configureDependencyInjection($diContainer);
114
115
        // Configure the server
116
        $diContainer->register(Server::class, [
117
            'shared' => true,
118
            'substitutions' => [
119
                RouterContainerInterface::class => [
120
                    'instance' => AuraRouterAdapter::class,
121
                ]
122
            ]
123
        ]);
124
125
        // Configure the server
126
        $diContainer->register(RouterContainer::class, [
127
            'constructParams' => [
128
                parse_url(getenv('APPARAT_BASE_URL'), PHP_URL_PATH) ?: null
129
            ]
130
        ]);
131
132
        // Configure the responder: Diactoros Response and TYPO3Fluid template view
133
        $diContainer->register(AbstractResponder::class, [
134
            'substitutions' => [
135
                ResponseInterface::class => [
136
                    'instance' => Response::class,
137
                ],
138
                ViewInterface::class => [
139
                    'instance' => TYPO3FluidView::class,
140
                ]
141
            ]
142
        ]);
143
144
        // Configure the TYPO3Fluid template view
145
        $diContainer->register(AbstractTemplateView::class, [
146
            'constructParams' => [null]
147
        ]);
148
149
        // Configure the action dependencies
150
        $this->configureActionDependencies($diContainer);
151
    }
152
153
    /**
154
     * Configure the action dependencies
155
     *
156
     * @param DependencyInjectionContainerInterface $diContainer Dependency injection container
157
     */
158
    protected function configureActionDependencies(DependencyInjectionContainerInterface $diContainer)
159
    {
160
        $diContainer->register(YearAction::class, [
161
            'substitutions' => [
162
                ServiceInterface::class => [
163
                    'instance' => YearService::class,
164
                ],
165
                ResponderInterface::class => [
166
                    'instance' => YearResponder::class,
167
                ]
168
            ]
169
        ]);
170
        $diContainer->register(MonthAction::class, [
171
            'substitutions' => [
172
                ServiceInterface::class => [
173
                    'instance' => MonthService::class,
174
                ],
175
                ResponderInterface::class => [
176
                    'instance' => MonthResponder::class,
177
                ]
178
            ]
179
        ]);
180
        $diContainer->register(DayAction::class, [
181
            'substitutions' => [
182
                ServiceInterface::class => [
183
                    'instance' => DayService::class,
184
                ],
185
                ResponderInterface::class => [
186
                    'instance' => DayResponder::class,
187
                ]
188
            ]
189
        ]);
190
        $diContainer->register(HourAction::class, [
191
            'substitutions' => [
192
                ServiceInterface::class => [
193
                    'instance' => HourService::class,
194
                ],
195
                ResponderInterface::class => [
196
                    'instance' => HourResponder::class,
197
                ]
198
            ]
199
        ]);
200
        $diContainer->register(MinuteAction::class, [
201
            'substitutions' => [
202
                ServiceInterface::class => [
203
                    'instance' => MinuteService::class,
204
                ],
205
                ResponderInterface::class => [
206
                    'instance' => MinuteResponder::class,
207
                ]
208
            ]
209
        ]);
210
        $diContainer->register(SecondAction::class, [
211
            'substitutions' => [
212
                ServiceInterface::class => [
213
                    'instance' => SecondService::class,
214
                ],
215
                ResponderInterface::class => [
216
                    'instance' => SecondResponder::class,
217
                ]
218
            ]
219
        ]);
220
        $diContainer->register(ObjectAction::class, [
221
            'substitutions' => [
222
                ServiceInterface::class => [
223
                    'instance' => ObjectService::class,
224
                ],
225
                ResponderInterface::class => [
226
                    'instance' => ObjectResponder::class,
227
                ]
228
            ]
229
        ]);
230
    }
231
}
232