BuyableTrait   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 0
dl 0
loc 54
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getBuyableIdentifier() 0 4 1
A getBuyableDescription() 0 4 1
A getBuyablePrice() 0 4 1
A getExtraFees() 0 4 1
A getOptions() 0 4 1
1
<?php
2
3
namespace Treestoneit\ShoppingCart;
4
5
use Exception;
6
7
trait BuyableTrait
8
{
9
    /**
10
     * Get the identifier of the Buyable item.
11
     *
12
     * @return int|string
13
     */
14
    public function getBuyableIdentifier()
15
    {
16
        return $this->getKey();
0 ignored issues
show
Bug introduced by
It seems like getKey() 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...
17
    }
18
19
    /**
20
     * Get the description or title of the Buyable item.
21
     *
22
     * @return string
23
     * @throws \Exception
24
     */
25
    public function getBuyableDescription()
26
    {
27
        throw new Exception('Buyable description has not been set.');
28
    }
29
30
    /**
31
     * Get the price of the Buyable item.
32
     *
33
     * @return float|null
34
     * @throws \Exception
35
     */
36
    public function getBuyablePrice()
37
    {
38
        throw new Exception('Buyable price has not been set.');
39
    }
40
41
    /**
42
     * Any extra fees not based on product quantity.
43
     *
44
     * @return float|int
45
     */
46
    public function getExtraFees()
47
    {
48
        return 0;
49
    }
50
51
    /**
52
     * An array of options (color, size, etc.) for this buyable item.
53
     *
54
     * @return array
55
     */
56
    public function getOptions(): array
57
    {
58
        return [];
59
    }
60
}
61