PaymentMethodOrderVisitor   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 3
dl 0
loc 18
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A visitOrder() 0 15 4
1
<?php
2
/*
3
 * WellCommerce Open-Source E-Commerce Platform
4
 * 
5
 * This file is part of the WellCommerce package.
6
 *
7
 * (c) Adam Piotrowski <[email protected]>
8
 * 
9
 * For the full copyright and license information,
10
 * please view the LICENSE file that was distributed with this source code.
11
 */
12
13
namespace WellCommerce\Bundle\OrderBundle\Visitor;
14
15
use WellCommerce\Bundle\OrderBundle\Entity\Order;
16
use WellCommerce\Bundle\OrderBundle\Entity\ShippingMethod;
17
18
/**
19
 * Class PaymentMethodOrderVisitor
20
 *
21
 * @author  Adam Piotrowski <[email protected]>
22
 */
23
final class PaymentMethodOrderVisitor implements OrderVisitorInterface
24
{
25
    public function visitOrder(Order $order)
26
    {
27
        if (!$order->getShippingMethod() instanceof ShippingMethod) {
28
            $order->setPaymentMethod(null);
29
            
30
            return;
31
        }
32
        
33
        $shippingMethod = $order->getShippingMethod();
34
        $paymentMethods = $shippingMethod->getPaymentMethods();
35
        
36
        if (null === $order->getPaymentMethod() || false === $paymentMethods->contains($order->getPaymentMethod())) {
37
            $order->setPaymentMethod($paymentMethods->first());
38
        }
39
    }
40
}
41