1 | <?php |
||
24 | class Builder extends Command |
||
25 | { |
||
26 | /** |
||
27 | * Contains the default app structure. |
||
28 | * |
||
29 | * @var string[] |
||
30 | */ |
||
31 | protected $structure = [ |
||
32 | 'app'.DIRECTORY_SEPARATOR, |
||
33 | 'bootstrap'.DIRECTORY_SEPARATOR, |
||
34 | 'vendor'.DIRECTORY_SEPARATOR, |
||
35 | 'config'.DIRECTORY_SEPARATOR, |
||
36 | 'composer.json', |
||
37 | 'builder-stub', |
||
38 | '.env', |
||
39 | ]; |
||
40 | |||
41 | /** |
||
42 | * Holds the stub name. |
||
43 | * |
||
44 | * @var string |
||
45 | */ |
||
46 | protected $stub = 'builder-stub'; |
||
47 | |||
48 | /** |
||
49 | * {@inheritdoc} |
||
50 | */ |
||
51 | protected $signature = 'app:build {name=application : The build name}'; |
||
52 | |||
53 | /** |
||
54 | * {@inheritdoc} |
||
55 | */ |
||
56 | protected $description = 'Perform an application build'; |
||
57 | |||
58 | /** |
||
59 | * Holds the configuration on is original state. |
||
60 | * |
||
61 | * @var string |
||
62 | */ |
||
63 | protected static $config; |
||
64 | |||
65 | /** |
||
66 | * {@inheritdoc} |
||
67 | */ |
||
68 | 1 | public function handle(): void |
|
81 | |||
82 | /** |
||
83 | * Builds the application into a single file. |
||
84 | * |
||
85 | * @param string $name The file name. |
||
86 | * |
||
87 | * @return $this |
||
88 | */ |
||
89 | 1 | protected function build(string $name): Builder |
|
107 | |||
108 | /** |
||
109 | * @param string $name |
||
110 | * |
||
111 | * @return $this |
||
112 | */ |
||
113 | 1 | protected function compile(string $name): Builder |
|
142 | |||
143 | /** |
||
144 | * Gets a new instance of the compiler. |
||
145 | * |
||
146 | * @param string $name |
||
147 | * |
||
148 | * @return \Phar |
||
149 | */ |
||
150 | 1 | protected function getCompiler(string $name): \Phar |
|
162 | |||
163 | /** |
||
164 | * @return $this |
||
165 | */ |
||
166 | 1 | protected function makeBuildsFolder(): Builder |
|
174 | |||
175 | /** |
||
176 | * Sets the executable mode on the single application file. |
||
177 | * |
||
178 | * @param string $name |
||
179 | * |
||
180 | * @return $this |
||
181 | */ |
||
182 | 1 | protected function setPermissions($name): Builder |
|
188 | |||
189 | /** |
||
190 | * @return $this |
||
191 | */ |
||
192 | 1 | protected function prepare(): Builder |
|
219 | |||
220 | /** |
||
221 | * @return $this |
||
222 | */ |
||
223 | 1 | protected function clear(): Builder |
|
237 | |||
238 | /** |
||
239 | * Makes sure that the `clear` is performed even |
||
240 | * if the command fails. |
||
241 | * |
||
242 | * @return void |
||
243 | */ |
||
244 | 18 | public function __destruct() |
|
251 | } |
||
252 |
Let’s take a look at an example:
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the interface: