Failed Conditions
Pull Request — experimental/3.1 (#2624)
by Kentaro
58:14
created

PurchaseFlowServiceProvider   B

Complexity

Total Complexity 1

Size/Duplication

Total Lines 101
Duplicated Lines 15.84 %

Coupling/Cohesion

Components 0
Dependencies 18

Importance

Changes 2
Bugs 0 Features 0
Metric Value
dl 16
loc 101
rs 7.3333
c 2
b 0
f 0
wmc 1
lcom 0
cbo 18

1 Method

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