1 | <?php |
||
5 | trait CanGenerateFile |
||
6 | { |
||
7 | protected $fileContent; |
||
8 | |||
9 | public function call() |
||
14 | |||
15 | /** |
||
16 | * Generate the file and save it according to specified naming. |
||
17 | * |
||
18 | * @return void |
||
19 | */ |
||
20 | protected function generateFile(): void |
||
34 | |||
35 | protected function loadStubFile(string $stubFile): void |
||
43 | |||
44 | /** |
||
45 | * Replace the class namespace in stub file. |
||
46 | * |
||
47 | * @return string |
||
48 | */ |
||
49 | protected function replaceClassNamespace(): void |
||
53 | |||
54 | /** |
||
55 | * Replace the class name in stub file. |
||
56 | * |
||
57 | * @return string |
||
58 | */ |
||
59 | protected function replaceClassName(): void |
||
63 | |||
64 | /** |
||
65 | * Replace the table name in stub file. |
||
66 | * |
||
67 | * @return string |
||
68 | */ |
||
69 | protected function replaceTableName(): void |
||
73 | } |
||
74 |
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.