Completed
Push — experimental/3.1 ( 24445a...d4772e )
by Yangsin
271:33 queued 265:16
created

PurchaseFlowServiceProvider::register()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 83
Code Lines 53

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 53
nc 1
nop 1
dl 0
loc 83
rs 8.7468
c 0
b 0
f 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
namespace Eccube\ServiceProvider;
4
5
use Doctrine\Common\Collections\ArrayCollection;
6
use Eccube\Entity\BaseInfo;
7
use Eccube\Entity\ItemHolderInterface;
8
use Eccube\Repository\DeliveryRepository;
9
use Eccube\Service\PurchaseFlow\Processor\AdminOrderRegisterPurchaseProcessor;
10
use Eccube\Service\PurchaseFlow\Processor\DeliveryFeeFreeProcessor;
11
use Eccube\Service\PurchaseFlow\Processor\DeliveryFeeProcessor;
12
use Eccube\Service\PurchaseFlow\Processor\DeliverySettingValidator;
13
use Eccube\Service\PurchaseFlow\Processor\DisplayStatusValidator;
14
use Eccube\Service\PurchaseFlow\Processor\PaymentProcessor;
15
use Eccube\Service\PurchaseFlow\Processor\PaymentTotalLimitValidator;
16
use Eccube\Service\PurchaseFlow\Processor\PaymentTotalNegativeValidator;
17
use Eccube\Service\PurchaseFlow\Processor\SaleLimitValidator;
18
use Eccube\Service\PurchaseFlow\Processor\StockValidator;
19
use Eccube\Service\PurchaseFlow\Processor\UpdateDatePurchaseProcessor;
20
use Eccube\Service\PurchaseFlow\PurchaseContext;
21
use Eccube\Service\PurchaseFlow\PurchaseFlow;
22
use Pimple\Container;
23
use Pimple\ServiceProviderInterface;
24
25
class PurchaseFlowServiceProvider implements ServiceProviderInterface
0 ignored issues
show
introduced by
Missing class doc comment
Loading history...
26
{
27
    public function register(Container $app)
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
28
    {
29
        $app['eccube.purchase.context'] = $app->protect(function (ItemHolderInterface $origin = null) {
30
            return new PurchaseContext($origin);
31
        });
32
33
        $app['eccube.purchase.flow.cart.item_processors'] = function (Container $app) {
34
            $processors = new ArrayCollection();
35
            $processors[] = new DisplayStatusValidator();
36
            $processors[] = new SaleLimitValidator();
37
            $processors[] = new DeliverySettingValidator($app[DeliveryRepository::class]);
38
            $processors[] = new StockValidator();
39
40
            return $processors;
41
        };
42
43
        $app['eccube.purchase.flow.cart.holder_processors'] = function (Container $app) {
44
            $processors = new ArrayCollection();
45
            $processors[] = new PaymentProcessor($app[DeliveryRepository::class]);
46
            $processors[] = new PaymentTotalLimitValidator($app['config']['max_total_fee']);
47
            $processors[] = new DeliveryFeeFreeProcessor($app[BaseInfo::class]);
48
            $processors[] = new PaymentTotalNegativeValidator();
49
50
            return $processors;
51
        };
52
53
        $app['eccube.purchase.flow.cart'] = function (Container $app) {
54
            $flow = new PurchaseFlow();
55
            $flow->setItemProcessors($app['eccube.purchase.flow.cart.item_processors']);
56
            $flow->setItemHolderProcessors($app['eccube.purchase.flow.cart.holder_processors']);
57
58
            return $flow;
59
        };
60
61
        $app['eccube.purchase.flow.shopping.item_processors'] = function (Container $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...
62
            $processors = new ArrayCollection();
63
            $processors[] = new StockValidator();
64
            $processors[] = new DisplayStatusValidator();
65
66
            return $processors;
67
        };
68
69
        $app['eccube.purchase.flow.shopping.holder_processors'] = function (Container $app) {
70
            $processors = new ArrayCollection();
71
            $processors[] = new PaymentTotalLimitValidator($app['config']['max_total_fee']);
72
            $processors[] = new DeliveryFeeProcessor($app['orm.em']);
73
            $processors[] = new PaymentTotalNegativeValidator();
74
75
            return $processors;
76
        };
77
78
        $app['eccube.purchase.flow.shopping'] = function (Container $app) {
79
            $flow = new PurchaseFlow();
80
            $flow->setItemProcessors($app['eccube.purchase.flow.shopping.item_processors']);
81
            $flow->setItemHolderProcessors($app['eccube.purchase.flow.shopping.holder_processors']);
82
83
            return $flow;
84
        };
85
86
        $app['eccube.purchase.flow.order.item_processors'] = function (Container $app) {
87
            $processors = new ArrayCollection();
88
            $processors[] = new StockValidator();
89
            $processors[] = new PaymentTotalLimitValidator($app['config']['max_total_fee']);
90
91
            return $processors;
92
        };
93
94
        $app['eccube.purchase.flow.order.holder_processors'] = function (Container $app) {
95
            $processors = new ArrayCollection();
96
            $processors[] = new UpdateDatePurchaseProcessor($app['config']);
97
            $processors[] = 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...
98
99
            return $processors;
100
        };
101
102
        $app['eccube.purchase.flow.order'] = function (Container $app) {
103
            $flow = new PurchaseFlow();
104
            $flow->setItemProcessors($app['eccube.purchase.flow.order.item_processors']);
105
            $flow->setItemHolderProcessors($app['eccube.purchase.flow.order.holder_processors']);
106
107
            return $flow;
108
        };
109
    }
110
}