1 | <?php |
||
12 | trait Logging |
||
13 | { |
||
14 | /** |
||
15 | * @var LoggerInterface |
||
16 | */ |
||
17 | protected $logger; |
||
18 | |||
19 | |||
20 | /** |
||
21 | * Set the logger for logging errors |
||
22 | * |
||
23 | * @param LoggerInterface $logger |
||
24 | */ |
||
25 | 116 | public function setLogger(LoggerInterface $logger) |
|
29 | |||
30 | /** |
||
31 | * Set the logger for logging errors |
||
32 | * |
||
33 | * @return LoggerInterface |
||
34 | */ |
||
35 | 68 | public function getLogger() |
|
43 | |||
44 | |||
45 | /** |
||
46 | * Log an error or exception |
||
47 | * |
||
48 | * @param \Exception|\Error $error |
||
49 | */ |
||
50 | 66 | public function log($error) |
|
63 | |||
64 | /** |
||
65 | * Log an error |
||
66 | * |
||
67 | * @param \Error|\ErrorException $error |
||
68 | */ |
||
69 | 50 | protected function logError($error) |
|
87 | |||
88 | /** |
||
89 | * Log an exception |
||
90 | * |
||
91 | * @param \Exception $exception |
||
92 | */ |
||
93 | 12 | protected function logException(\Exception $exception) |
|
104 | } |
||
105 |
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.