Completed
Push — experimental/3.1 ( 10dd6d...44919f )
by Yangsin
148:12 queued 142:12
created

EccubeServiceProvider   C

Complexity

Total Complexity 3

Size/Duplication

Total Lines 227
Duplicated Lines 7.49 %

Coupling/Cohesion

Components 0
Dependencies 34

Test Coverage

Coverage 60%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
dl 17
loc 227
ccs 69
cts 115
cp 0.6
rs 5
c 2
b 0
f 0
wmc 3
lcom 0
cbo 34

2 Methods

Rating   Name   Duplication   Size   Complexity  
B register() 17 207 2
A subscribe() 0 8 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
/*
3
 * This file is part of EC-CUBE
4
 *
5
 * Copyright(c) 2000-2015 LOCKON CO.,LTD. All Rights Reserved.
6
 *
7
 * http://www.lockon.co.jp/
8
 *
9
 * This program is free software; you can redistribute it and/or
10
 * modify it under the terms of the GNU General Public License
11
 * as published by the Free Software Foundation; either version 2
12
 * of the License, or (at your option) any later version.
13
 *
14
 * This program is distributed in the hope that it will be useful,
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 * GNU General Public License for more details.
18
 *
19
 * You should have received a copy of the GNU General Public License
20
 * along with this program; if not, write to the Free Software
21
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22
 */
23
24
25
namespace Eccube\ServiceProvider;
26
27
use Doctrine\Common\Collections\ArrayCollection;
28
use Eccube\Entity\ItemHolderInterface;
29
use Eccube\Entity\BaseInfo;
30
use Eccube\EventListener\ForwardOnlyListener;
31
use Eccube\EventListener\TransactionListener;
32
use Eccube\Repository\BaseInfoRepository;
33
use Eccube\Repository\DeliveryRepository;
34
use Eccube\Service\PurchaseFlow\Processor\AdminOrderRegisterPurchaseProcessor;
35
use Eccube\Service\PurchaseFlow\Processor\DeletedProductValidator;
36
use Eccube\Service\PurchaseFlow\Processor\DeliveryFeeFreeProcessor;
37
use Eccube\Service\PurchaseFlow\Processor\DeliveryFeeProcessor;
38
use Eccube\Service\PurchaseFlow\Processor\DeliverySettingValidator;
39
use Eccube\Service\PurchaseFlow\Processor\DisplayStatusValidator;
40
use Eccube\Service\PurchaseFlow\Processor\PaymentProcessor;
41
use Eccube\Service\PurchaseFlow\Processor\PaymentTotalLimitValidator;
42
use Eccube\Service\PurchaseFlow\Processor\PaymentTotalNegativeValidator;
43
use Eccube\Service\PurchaseFlow\Processor\SaleLimitValidator;
44
use Eccube\Service\PurchaseFlow\Processor\StockValidator;
45
use Eccube\Service\PurchaseFlow\Processor\UpdateDatePurchaseProcessor;
46
use Eccube\Service\PurchaseFlow\PurchaseContext;
47
use Eccube\Service\PurchaseFlow\PurchaseFlow;
48
use Eccube\Service\TaxRuleService;
49
use Pimple\Container;
50
use Pimple\ServiceProviderInterface;
51
use Silex\Api\EventListenerProviderInterface;
52
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
53
use Symfony\Component\HttpFoundation\ParameterBag;
54
55
class EccubeServiceProvider implements ServiceProviderInterface, EventListenerProviderInterface
0 ignored issues
show
introduced by
Missing class doc comment
Loading history...
56
{
57
    /**
58
     * Registers services on the given app.
59
     *
60
     * This method should only be used to configure services and parameters.
61
     * It should not get services.
62
     *
63
     * @param BaseApplication $app An Application instance
64
     */
65 1071
    public function register(Container $app)
66
    {
67
        $app[BaseInfo::class] = function () use ($app) {
68 1071
            return $app[BaseInfoRepository::class]->get();
69
        };
70
71
        $app['eccube.calculate.context'] = function () use ($app) {
72
                return new \Eccube\Service\Calculator\CalculateContext();
73
        };
74
75
        $app['eccube.calculate.strategies'] = function () use ($app) {
76
            $Collection = new \Eccube\Service\Calculator\CalculateStrategyCollection();
77
            $Collection->setApplication($app);
0 ignored issues
show
Compatibility introduced by
$app of type object<Pimple\Container> is not a sub-type of object<Eccube\Application>. It seems like you assume a child class of the class Pimple\Container to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
78
            //$Collection->setOrder($Order);
79
            // デフォルトのストラテジーをセットしておく
80
            $Collection->add($app['eccube.calculate.strategy.shipping']);
81
            $Collection->add($app['eccube.calculate.strategy.charge']);
82
            $Collection->add($app['eccube.calculate.strategy.tax']);
83
            $Collection->add($app['eccube.calculate.strategy.calculate_delivery_fee']);
84
            $Collection->add($app['eccube.calculate.strategy.calculate_charge']);
85
            $Collection->add($app['eccube.calculate.strategy.calculate_total']);
86
            return $Collection;
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
87
        };
88
        $app['eccube.calculate.strategy.shipping'] = function () use ($app) {
89
                $Strategy = new \Eccube\Service\Calculator\Strategy\ShippingStrategy();
90
                $Strategy->setApplication($app);
0 ignored issues
show
Compatibility introduced by
$app of type object<Pimple\Container> is not a sub-type of object<Eccube\Application>. It seems like you assume a child class of the class Pimple\Container to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
91
                return $Strategy;
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
92
        };
93
        $app['eccube.calculate.strategy.charge'] = function () use ($app) {
94
                $Strategy = new \Eccube\Service\Calculator\Strategy\ChargeStrategy();
95
                $Strategy->setApplication($app);
0 ignored issues
show
Compatibility introduced by
$app of type object<Pimple\Container> is not a sub-type of object<Eccube\Application>. It seems like you assume a child class of the class Pimple\Container to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
96
                return $Strategy;
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
97
        };
98
99
        $app['eccube.calculate.strategy.tax'] = function () use ($app) {
100
                $Strategy = new \Eccube\Service\Calculator\Strategy\TaxStrategy();
101
                $Strategy->setApplication($app);
0 ignored issues
show
Compatibility introduced by
$app of type object<Pimple\Container> is not a sub-type of object<Eccube\Application>. It seems like you assume a child class of the class Pimple\Container to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
102
                return $Strategy;
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
103
        };
104
105
        $app['eccube.calculate.strategy.calculate_delivery_fee'] = function () use ($app) {
106
            $Strategy = new \Eccube\Service\Calculator\Strategy\CalculateDeliveryFeeStrategy();
107
            $Strategy->setApplication($app);
0 ignored issues
show
Compatibility introduced by
$app of type object<Pimple\Container> is not a sub-type of object<Eccube\Application>. It seems like you assume a child class of the class Pimple\Container to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
108
            return $Strategy;
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
109
        };
110
        $app['eccube.calculate.strategy.calculate_charge'] = function () use ($app) {
111
            $Strategy = new \Eccube\Service\Calculator\Strategy\CalculateChargeStrategy();
112
            $Strategy->setApplication($app);
0 ignored issues
show
Compatibility introduced by
$app of type object<Pimple\Container> is not a sub-type of object<Eccube\Application>. It seems like you assume a child class of the class Pimple\Container to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
113
            return $Strategy;
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
114
        };
115
        $app['eccube.calculate.strategy.calculate_total'] = function () use ($app) {
116
            $Strategy = new \Eccube\Service\Calculator\Strategy\CalculateTotalStrategy();
117
            $Strategy->setApplication($app);
0 ignored issues
show
Compatibility introduced by
$app of type object<Pimple\Container> is not a sub-type of object<Eccube\Application>. It seems like you assume a child class of the class Pimple\Container to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
118
            return $Strategy;
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
119
        };
120
121
        $app['payment.method'] = $app->protect(function ($clazz, $form) use ($app) {
122 1
                $PaymentMethod = new $clazz;
0 ignored issues
show
introduced by
Use parentheses when instantiating classes
Loading history...
123 1
                $PaymentMethod->setApplication($app);
124 1
                $PaymentMethod->setFormType($form);
125 1
                return $PaymentMethod;
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
126 1071
        });
127
128
        $app['payment.method.request'] = $app->protect(function ($clazz, $form, $request) use ($app) {
129 2
                $PaymentMethod = new $clazz;
0 ignored issues
show
introduced by
Use parentheses when instantiating classes
Loading history...
130 2
                $PaymentMethod->setApplication($app);
131 2
                $PaymentMethod->setFormType($form);
132 2
                $PaymentMethod->setRequest($request);
133 2
                return $PaymentMethod;
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
134 1071
        });
135
136
        $app['eccube.service.calculate'] = $app->protect(function ($Order, $Customer) use ($app) {
137
            $Service = new \Eccube\Service\CalculateService($Order, $Customer);
138
            $Context = $app['eccube.calculate.context'];
139
            $app['eccube.calculate.strategies']->setOrder($Order);
140
            $Context->setCalculateStrategies($app['eccube.calculate.strategies']);
141
            $Context->setOrder($Order);
142
            $Service->setContext($Context);
143
144
            return $Service;
145 1071
        });
146
147
        $app['eccube.service.payment'] = $app->protect(function ($clazz) use ($app) {
148 3
            $Service = new $clazz($app['request_stack']);
149
150 3
            return $Service;
151 1071
        });
152
153
        $app['paginator'] = $app->protect(function () {
154 29
            $paginator = new \Knp\Component\Pager\Paginator();
155 29
            $paginator->subscribe(new \Eccube\EventListener\PaginatorListener());
156
157 29
            return $paginator;
158 1071
        });
159
160
        $app['request_scope'] = function () {
161 22
            return new ParameterBag();
162
        };
163
        // TODO 使用するか検討
164
        $app['eccube.twig.node.hello'] = $app->protect(function ($node, $compiler) {
165
            $compiler
166
            ->addDebugInfo($node)
167
            ->write("echo 'Helloooooo ' . ")
168
            ->subcompile($node->getNode('expr'))
169
            ->raw(" . '!';\n")
170
            ;
171
172 1071
        });
173
        // TODO 使用するか検討
174
        $app['eccube.twig.node.jiro'] = $app->protect(function ($node, $compiler) {
175
            $compiler
176
            ->addDebugInfo($node)
177
            ->write("echo 'jirooooooo ' . ")
178
            ->subcompile($node->getNode('expr'))
179
            ->raw(" . '!';\n")
180
            ;
181
182 1071
        });
183
184
        // TODO 使用するか検討
185
        $app['eccube.twig.generic_node_names'] = function () use ($app) {
186
            return [
0 ignored issues
show
introduced by
Add a comma after each item in a multi-line array
Loading history...
187 113
                'hello',
188
                'jiro',
189
                'bbb'
190
            ];
191
        };
192
193
        // TODO 使用するか検討
194
        $app['twig_parsers'] = function () use ($app) {
195 113
            $GenericTokenParsers = [];
196 113
            foreach ($app['eccube.twig.generic_node_names'] as $tagName) {
197 113
                $GenericTokenParsers[] = new \Eccube\Twig\Extension\GenericTokenParser($app, $tagName);
198
            }
199 113
            return $GenericTokenParsers;
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
200
        };
201
202
        $app['eccube.twig.block.templates'] = function () {
203
            $templates = new ArrayCollection();
204
            $templates[] = 'render_block.twig';
205
206
            return $templates;
207
        };
208
209 1071
        $app['eccube.entity.event.dispatcher']->addEventListener(new \Acme\Entity\SoldOutEventListener());
210
        $app['eccube.queries'] = function () {
211 1069
            return new \Eccube\Doctrine\Query\Queries();
212
        };
213
214
        $app['eccube.purchase.context'] = $app->protect(function (ItemHolderInterface $origin = null) {
215 17
            return new PurchaseContext($origin);
216 1071
        });
217
218
        $app['eccube.purchase.flow.cart.item_processors'] = function ($app) {
219 24
            $processors = new ArrayCollection();
220 24
            $processors->add(new DisplayStatusValidator());
221 24
            $processors->add(new SaleLimitValidator());
222 24
            $processors->add(new DeliverySettingValidator($app['eccube.repository.delivery']));
223
224 24
            return $processors;
225
        };
226
227
        $app['eccube.purchase.flow.cart.holder_processors'] = function ($app) {
228 24
            $processors = new ArrayCollection();
229 24
            $processors->add(new PaymentProcessor($app[DeliveryRepository::class]));
230 24
            $processors->add(new PaymentTotalLimitValidator($app['config']['max_total_fee']));
231 24
            $processors->add(new DeliveryFeeFreeProcessor($app[BaseInfo::class]));
232 24
            $processors->add(new PaymentTotalNegativeValidator());
233
234 24
            return $processors;
235
        };
236
237
        // example
238
        $app->extend('eccube.purchase.flow.cart.item_processors', function ($processors, $app) {
0 ignored issues
show
Unused Code introduced by
The parameter $app 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...
239
240 24
            $processors->add(new StockValidator());
241
242 24
            return $processors;
243 1071
        });
244
245
        $app['eccube.purchase.flow.cart'] = function ($app) {
246 24
            $flow = new PurchaseFlow();
247 24
            $flow->setItemProcessors($app['eccube.purchase.flow.cart.item_processors']);
248 24
            $flow->setItemHolderProcessors($app['eccube.purchase.flow.cart.holder_processors']);
249
250 24
            return $flow;
251
        };
252
253 View Code Duplication
        $app['eccube.purchase.flow.shopping'] = function () use ($app) {
254 22
            $flow = new PurchaseFlow();
255 22
            $flow->addItemProcessor(new StockValidator());
256 22
            $flow->addItemProcessor(new DisplayStatusValidator());
257 22
            $flow->addItemHolderProcessor(new PaymentTotalLimitValidator($app['config']['max_total_fee']));
258 22
            $flow->addItemHolderProcessor(new DeliveryFeeProcessor($app['orm.em']));
259 22
            $flow->addItemHolderProcessor(new PaymentTotalNegativeValidator());
260 22
            return $flow;
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
261
        };
262
263 8 View Code Duplication
        $app['eccube.purchase.flow.order'] = function () use ($app) {
264 8
            $flow = new PurchaseFlow();
265 8
            $flow->addItemProcessor(new StockValidator());
266 8
            $flow->addItemHolderProcessor(new PaymentTotalLimitValidator($app['config']['max_total_fee']));
267 8
            $flow->addPurchaseProcessor(new UpdateDatePurchaseProcessor($app['config']));
268 8
            $flow->addPurchaseProcessor(new AdminOrderRegisterPurchaseProcessor($app));
0 ignored issues
show
Unused Code introduced by
The call to AdminOrderRegisterPurchaseProcessor::__construct() has too many arguments starting with $app.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
269 8
            return $flow;
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
270
        };
271
    }
272
273 1071
    public function subscribe(Container $app, EventDispatcherInterface $dispatcher)
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
274
    {
275
        // Add event subscriber to TaxRuleEvent
276 1071
        $app['orm.em']->getEventManager()->addEventSubscriber(new \Eccube\Doctrine\EventSubscriber\TaxRuleEventSubscriber($app[TaxRuleService::class]));
277
278 1071
        $dispatcher->addSubscriber(new ForwardOnlyListener($app));
0 ignored issues
show
Compatibility introduced by
$app of type object<Pimple\Container> is not a sub-type of object<Eccube\Application>. It seems like you assume a child class of the class Pimple\Container to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
279 1071
        $dispatcher->addSubscriber(new TransactionListener($app));
0 ignored issues
show
Compatibility introduced by
$app of type object<Pimple\Container> is not a sub-type of object<Eccube\Application>. It seems like you assume a child class of the class Pimple\Container to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
280
    }
281
}
282