1 | <?php namespace Arcanedev\Units\Traits; |
||
11 | trait Calculatable |
||
12 | { |
||
13 | /* ------------------------------------------------------------------------------------------------ |
||
14 | | Main Functions |
||
15 | | ------------------------------------------------------------------------------------------------ |
||
16 | */ |
||
17 | /** |
||
18 | * Add the unit instance. |
||
19 | * |
||
20 | * @param \Arcanedev\Units\Contracts\UnitMeasure $unit |
||
21 | * |
||
22 | * @return \Arcanedev\Units\Contracts\UnitMeasure |
||
23 | */ |
||
24 | public function add(UnitMeasure $unit) |
||
32 | |||
33 | /** |
||
34 | * Sub the unit instance. |
||
35 | * |
||
36 | * @param \Arcanedev\Units\Contracts\UnitMeasure $unit |
||
37 | * |
||
38 | * @return \Arcanedev\Units\Contracts\UnitMeasure |
||
39 | */ |
||
40 | public function sub(UnitMeasure $unit) |
||
48 | |||
49 | /** |
||
50 | * Multiply unit by the given number. |
||
51 | * |
||
52 | * @param float|int $number |
||
53 | * |
||
54 | * @return \Arcanedev\Units\Contracts\UnitMeasure |
||
55 | */ |
||
56 | public function multiply($number) |
||
62 | |||
63 | /** |
||
64 | * Divide unit by the given number. |
||
65 | * |
||
66 | * @param float|int $number |
||
67 | * |
||
68 | * @return \Arcanedev\Units\Contracts\Weight |
||
69 | */ |
||
70 | public function divide($number) |
||
76 | |||
77 | /** |
||
78 | * Calculate the value. |
||
79 | * |
||
80 | * @param float|int $a |
||
81 | * @param string $operator |
||
82 | * @param float|int $b |
||
83 | * |
||
84 | * @return float|int |
||
85 | */ |
||
86 | protected static function calculate($a, $operator, $b) |
||
101 | } |
||
102 |
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
The trait
Idable
provides a methodequalsId
that in turn relies on the methodgetId()
. 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.