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

PromotionTransformer   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 4
dl 0
loc 48
ccs 0
cts 17
cp 0
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A transform() 0 12 1
A discount() 0 8 2
A creditPoint() 0 8 2
1
<?php
2
3
namespace WSW\SiftScience\Transformers;
4
5
use WSW\SiftScience\Entities\CreditPoint;
6
use WSW\SiftScience\Entities\Discount;
7
use WSW\SiftScience\Entities\Promotion;
8
9
/**
10
 * Class PromotionTransformer
11
 *
12
 * @package WSW\SiftScience\Transformers
13
 * @author Ronaldo Matos Rodrigues <[email protected]>
14
 */
15
class PromotionTransformer extends AbstractTransformer
16
{
17
    /**
18
     * @param Promotion $promotion
19
     *
20
     * @return array
21
     */
22
    public function transform(Promotion $promotion)
23
    {
24
        return array_filter([
25
            '$promotion_id' => $promotion->getId(),
26
            '$status' => $promotion->getStatus(),
27
            '$failure_reason' => $promotion->getFailureReason(),
28
            '$description' => $promotion->getDescription(),
29
            '$referrer_user_id' => $promotion->getReferrerUserId(),
30
            '$discount' => $this->discount($promotion->getDiscount()),
31
            '$credit_point' => $this->creditPoint($promotion->getCreditPoint())
32
        ]);
33
    }
34
35
    /**
36
     * @param Discount $discount
37
     *
38
     * @return array
39
     */
40
    protected function discount($discount)
41
    {
42
        if (!$discount instanceof Discount) {
43
            return null;
44
        }
45
46
        return $this->loadItem($discount, new DiscountTransformer);
47
    }
48
49
    /**
50
     * @param CreditPoint $creditPoint
51
     *
52
     * @return array
53
     */
54
    protected function creditPoint($creditPoint)
55
    {
56
        if (!$creditPoint instanceof CreditPoint) {
57
            return null;
58
        }
59
60
        return $this->loadItem($creditPoint, new CreditPointTransformer);
61
    }
62
}
63