Failed Conditions
Push — experimental/sf ( 099fe7...d58f47 )
by Ryo
110:32 queued 103:08
created

PurchaseFlowPass   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 41
rs 10
c 0
b 0
f 0
ccs 19
cts 19
cp 1
wmc 5
lcom 0
cbo 5

1 Method

Rating   Name   Duplication   Size   Complexity  
A process() 0 32 5
1
<?php
2
3
/*
4
 * This file is part of EC-CUBE
5
 *
6
 * Copyright(c) LOCKON CO.,LTD. All Rights Reserved.
7
 *
8
 * http://www.lockon.co.jp/
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Eccube\DependencyInjection\Compiler;
15
16
use Doctrine\Common\Annotations\AnnotationReader;
17
use Doctrine\Common\Annotations\AnnotationRegistry;
18
use Eccube\Annotation\CartFlow;
19
use Eccube\Annotation\OrderFlow;
20
use Eccube\Annotation\ShoppingFlow;
21
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
22
use Symfony\Component\DependencyInjection\ContainerBuilder;
23
use Symfony\Component\DependencyInjection\Reference;
24
25
class PurchaseFlowPass implements CompilerPassInterface
0 ignored issues
show
introduced by
Missing class doc comment
Loading history...
26
{
27
    const ITEM_PREPROCESSOR_TAG = 'eccube.item.preprocessor';
28
    const ITEM_VALIDATOR_TAG = 'eccube.item.validator';
29
    const ITEM_HOLDER_PREPROCESSOR_TAG = 'eccube.item.holder.preprocessor';
30
    const ITEM_HOLDER_VALIDATOR_TAG = 'eccube.item.holder.validator';
31
    const PURCHASE_PROCESSOR_TAG = 'eccube.purchase.processor';
32
33 9
    public function process(ContainerBuilder $container)
34
    {
35
        $flowDefs = [
36 9
            CartFlow::class => $container->getDefinition('eccube.purchase.flow.cart'),
37 9
            ShoppingFlow::class => $container->getDefinition('eccube.purchase.flow.shopping'),
38 9
            OrderFlow::class => $container->getDefinition('eccube.purchase.flow.order'),
39
        ];
40
41
        $processorTags = [
42 9
            self::ITEM_PREPROCESSOR_TAG => 'addItemPreprocessor',
43 9
            self::ITEM_VALIDATOR_TAG => 'addItemValidator',
44 9
            self::ITEM_HOLDER_PREPROCESSOR_TAG => 'addItemHolderPreprocessor',
45 9
            self::ITEM_HOLDER_VALIDATOR_TAG => 'addItemHolderValidator',
46 9
            self::PURCHASE_PROCESSOR_TAG => 'addPurchaseProcessor',
47
        ];
48
49 9
        AnnotationRegistry::registerAutoloadNamespace('Eccube\Annotation', __DIR__.'/../../../../src');
0 ignored issues
show
Deprecated Code introduced by
The method Doctrine\Common\Annotati...sterAutoloadNamespace() has been deprecated with message: this method is deprecated and will be removed in doctrine/annotations 2.0 autoloading should be deferred to the globally registered autoloader by then. For now, use @example AnnotationRegistry::registerLoader('class_exists')

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
50 9
        $reader = new AnnotationReader();
51
52 9
        foreach ($processorTags as $tag => $methodName) {
53 9
            $ids = $container->findTaggedServiceIds($tag);
54 9
            foreach ($ids as $id => $tags) {
55 9
                $def = $container->getDefinition($id);
56 9
                foreach ($flowDefs as $annotationName => $purchaseFlowDef) {
57 9
                    $anno = $reader->getClassAnnotation(new \ReflectionClass($def->getClass()), $annotationName);
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $anno is correct as $reader->getClassAnnotat...ss()), $annotationName) (which targets Doctrine\Common\Annotati...r::getClassAnnotation()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
58 9
                    if ($anno) {
59 9
                        $purchaseFlowDef->addMethodCall($methodName, [new Reference($id)]);
60
                    }
61
                }
62
            }
63
        }
64
    }
65
}
66