1 | <?php |
||
7 | trait SocketTrait |
||
8 | { |
||
9 | /** |
||
10 | * Socket resource |
||
11 | * |
||
12 | * @var resource|null |
||
13 | */ |
||
14 | private $socket; |
||
15 | |||
16 | /** |
||
17 | * Code of error |
||
18 | * |
||
19 | * @var int |
||
20 | */ |
||
21 | private $socket_err_num; |
||
22 | |||
23 | /** |
||
24 | * Description of socket error |
||
25 | * |
||
26 | * @var string |
||
27 | */ |
||
28 | private $socket_err_str; |
||
29 | |||
30 | /** |
||
31 | * Initiate socket session |
||
32 | * |
||
33 | * @return void |
||
34 | * @throws \RouterOS\Exceptions\ClientException |
||
35 | * @throws \RouterOS\Exceptions\ConfigException |
||
36 | */ |
||
37 | 8 | private function openSocket(): void |
|
72 | |||
73 | /** |
||
74 | * Close socket session |
||
75 | * |
||
76 | * @return bool |
||
77 | */ |
||
78 | private function closeSocket(): bool |
||
82 | |||
83 | /** |
||
84 | * Save socket resource to static variable |
||
85 | * |
||
86 | * @param resource $socket |
||
87 | * |
||
88 | * @return void |
||
89 | */ |
||
90 | 7 | private function setSocket($socket): void |
|
94 | |||
95 | /** |
||
96 | * Return socket resource if is exist |
||
97 | * |
||
98 | * @return resource |
||
99 | */ |
||
100 | 7 | public function getSocket() |
|
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.