1 | <?php |
||
19 | trait Transactionable |
||
20 | { |
||
21 | /** |
||
22 | * Create a new entity with the given attributes. |
||
23 | * |
||
24 | * @param array $attributes |
||
25 | * |
||
26 | * @throws \Exception |
||
27 | * |
||
28 | * @return array |
||
29 | */ |
||
30 | public function create(array $attributes = []) |
||
46 | |||
47 | /** |
||
48 | * Update an entity with the given attributes. |
||
49 | * |
||
50 | * @param mixed $id |
||
51 | * @param array $attributes |
||
52 | * |
||
53 | * @throws \Exception |
||
54 | * |
||
55 | * @return array |
||
56 | */ |
||
57 | public function update($id, array $attributes = []) |
||
73 | |||
74 | /** |
||
75 | * Delete an entity with the given id. |
||
76 | * |
||
77 | * @param mixed $id |
||
78 | * |
||
79 | * @throws \Exception |
||
80 | * |
||
81 | * @return array |
||
82 | */ |
||
83 | public function delete($id) |
||
98 | |||
99 | /** |
||
100 | * Start a new database transaction. |
||
101 | * |
||
102 | * @return void |
||
103 | * @throws Exception |
||
104 | */ |
||
105 | public function beginTransaction() |
||
109 | |||
110 | /** |
||
111 | * Commit the active database transaction. |
||
112 | * |
||
113 | * @return void |
||
114 | */ |
||
115 | public function commit() |
||
119 | |||
120 | |||
121 | /** |
||
122 | * Rollback the active database transaction. |
||
123 | * |
||
124 | * @return void |
||
125 | */ |
||
126 | public function rollBack() |
||
130 | } |
||
131 |
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.