Completed
Push — master ( 84a128...7da2fe )
by Ronaldo
07:05
created

Relationships::creditPoint()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 1
1
<?php
2
3
namespace WSW\SiftScience\Support\Traits\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\Entities\CreditPoint;
10
use WSW\SiftScience\Entities\Discount;
11
use WSW\SiftScience\Transformers\Entities\AddressTransformer;
12
use WSW\SiftScience\Transformers\Entities\CreditPointTransformer;
13
use WSW\SiftScience\Transformers\Entities\DiscountTransformer;
14
use WSW\SiftScience\Transformers\Entities\ItemTransformer;
15
use WSW\SiftScience\Transformers\Entities\PaymentMethodTransformer;
16
use WSW\SiftScience\Transformers\Entities\PromotionTransformer;
17
18
/**
19
 * Trait Relationships
20
 *
21
 * @package WSW\SiftScience\Support\Traits\Transformers
22
 * @author Ronaldo Matos Rodrigues <[email protected]>
23
 */
24
trait Relationships
25
{
26
    /**
27
     * @param $address|null
28
     *
29
     * @return array|null
30
     */
31
    protected function address($address = null)
32
    {
33
        return (!$address instanceof Address) ? null : $this->loadItem($address, new AddressTransformer());
0 ignored issues
show
Bug introduced by
It seems like loadItem() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
34
    }
35
36
    /**
37
     * @param Discount|null $discount
38
     *
39
     * @return array|null
40
     */
41
    protected function discount($discount = null)
42
    {
43
        return (!$discount instanceof Discount) ? null : $this->loadItem($discount, new DiscountTransformer);
0 ignored issues
show
Bug introduced by
It seems like loadItem() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
44
    }
45
46
    /**
47
     * @param CreditPoint|null $creditPoint
48
     *
49
     * @return array
50
     */
51
    protected function creditPoint($creditPoint = null)
52
    {
53
        return (!$creditPoint instanceof CreditPoint)
54
            ? null
55
            : $this->loadItem($creditPoint, new CreditPointTransformer);
0 ignored issues
show
Bug introduced by
It seems like loadItem() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
56
    }
57
58
    /**
59
     * @param PaymentMethods|null $collection
60
     *
61
     * @return array
62
     */
63
    protected function paymentMethods($collection = null)
64
    {
65
        return (!$collection instanceof  PaymentMethods)
66
            ? null
67
            : $this->loadCollection($collection->getValues(), new PaymentMethodTransformer);
0 ignored issues
show
Bug introduced by
It seems like loadCollection() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
68
    }
69
70
    /**
71
     * @param Items|null $items
72
     *
73
     * @return array
74
     */
75
    protected function items($items)
76
    {
77
        return (!$items instanceof Items)
78
            ? null
79
            : $this->loadCollection($items->getValues(), new ItemTransformer);
0 ignored issues
show
Bug introduced by
It seems like loadCollection() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
80
    }
81
82
    /**
83
     * @param Promotions|null $promotions
84
     *
85
     * @return array|null
86
     */
87
    protected function promotions(Promotions $promotions = null)
88
    {
89
        return (!$promotions instanceof Promotions)
90
            ? null
91
            : $this->loadCollection($promotions->getValues(), new PromotionTransformer);
0 ignored issues
show
Bug introduced by
It seems like loadCollection() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
92
    }
93
}
94