Completed
Push — master ( fb0370...84a128 )
by Ronaldo
03:03
created

CreateOrderTransformer   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 69
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 12

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 12
dl 0
loc 69
ccs 0
cts 26
cp 0
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A transform() 0 21 1
A address() 0 4 1
A paymentMethods() 0 4 1
A items() 0 4 1
A promotions() 0 4 1
1
<?php
2
3
namespace WSW\SiftScience\Transformers;
4
5
use WSW\SiftScience\Collections\Items;
6
use WSW\SiftScience\Collections\PaymentMethods;
7
use WSW\SiftScience\Collections\Promotions;
8
use WSW\SiftScience\Entities\Address;
9
use WSW\SiftScience\Events\CreateOrder;
10
11
/**
12
 * Class CreateOrderTransformer
13
 *
14
 * @package WSW\SiftScience\Transformers
15
 * @author Ronaldo Matos Rodrigues <[email protected]>
16
 */
17
class CreateOrderTransformer extends AbstractTransformer
18
{
19
    /**
20
     * @param CreateOrder $createOrder
21
     *
22
     * @return array
23
     */
24
    public function transform(CreateOrder $createOrder)
25
    {
26
        return array_filter([
27
            '$type' => $createOrder->getType(),
28
            '$api_key' => $createOrder->getApiKey(),
29
            '$user_id' => $createOrder->getUserId(),
30
            '$session_id' => $createOrder->getSession(),
31
            '$order_id' => $createOrder->getOrder(),
32
            '$user_email' => $createOrder->getUserEmail()->getEmail(),
33
            '$amount' => $createOrder->getAmount()->getMicros(),
34
            '$currency_code' => $createOrder->getAmount()->getCurrency()->getCode(),
35
            '$billing_address' => $this->address($createOrder->getBillingAddress()),
36
            '$payment_methods' => $this->paymentMethods($createOrder->getPaymentMethods()),
37
            '$shipping_address' => $this->address($createOrder->getShippingAddress()),
38
            '$expedited_shipping' => $createOrder->isExpeditedShipping(),
39
            '$shipping_method' => $createOrder->getShippingMethod(),
40
            '$items' => $this->items($createOrder->getItems()),
41
            '$seller_user_id' => $createOrder->getSellerUserId(),
42
            '$promotions' => $this->promotions($createOrder->getPromotions())
43
        ]);
44
    }
45
46
    /**
47
     * @param Address $address
48
     *
49
     * @return array
50
     */
51
    protected function address(Address $address)
52
    {
53
        return $this->loadItem($address, new AddressTransformer());
54
    }
55
56
    /**
57
     * @param PaymentMethods $collection
58
     *
59
     * @return array
60
     */
61
    protected function paymentMethods(PaymentMethods $collection)
62
    {
63
        return $this->loadCollection($collection->getValues(), new PaymentMethodTransformer);
64
    }
65
66
    /**
67
     * @param Items $items
68
     *
69
     * @return array
70
     */
71
    protected function items(Items $items)
72
    {
73
        return $this->loadCollection($items->getValues(), new ItemTransformer);
74
    }
75
76
    /**
77
     * @param Promotions $promotions
78
     *
79
     * @return array
80
     */
81
    protected function promotions(Promotions $promotions)
82
    {
83
        return $this->loadCollection($promotions->getValues(), new PromotionTransformer);
84
    }
85
}
86