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

PromotionTransformer::creditPoint()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 0
cts 4
cp 0
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 1
crap 6
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