1 | <?php |
||
16 | class NoCaptchaManager extends Manager implements NoCaptchaManagerContract |
||
17 | { |
||
18 | /* ----------------------------------------------------------------- |
||
19 | | Getters |
||
20 | | ----------------------------------------------------------------- |
||
21 | */ |
||
22 | |||
23 | /** |
||
24 | * Get the default driver name. |
||
25 | * |
||
26 | * @return string |
||
27 | */ |
||
28 | 4 | public function getDefaultDriver(): string |
|
32 | |||
33 | /* ----------------------------------------------------------------- |
||
34 | | Main Methods |
||
35 | | ----------------------------------------------------------------- |
||
36 | */ |
||
37 | |||
38 | /** |
||
39 | * Get the NoCaptcha driver by the given version. |
||
40 | * |
||
41 | * @param string|null $version |
||
42 | * |
||
43 | * @return \Arcanedev\NoCaptcha\NoCaptchaV3|\Arcanedev\NoCaptcha\NoCaptchaV2 |
||
44 | */ |
||
45 | 32 | public function version($version = null): NoCaptchaContract |
|
49 | |||
50 | /** |
||
51 | * Create the v2 captcha. |
||
52 | * |
||
53 | * @return \Arcanedev\NoCaptcha\NoCaptchaV2 |
||
54 | */ |
||
55 | 2 | public function createV2Driver(): NoCaptchaContract |
|
59 | |||
60 | /** |
||
61 | * Create the v3 captcha. |
||
62 | * |
||
63 | * @return \Arcanedev\NoCaptcha\NoCaptchaV3 |
||
64 | */ |
||
65 | 14 | public function createV3Driver(): NoCaptchaContract |
|
69 | |||
70 | /* ----------------------------------------------------------------- |
||
71 | | Other Methods |
||
72 | | ----------------------------------------------------------------- |
||
73 | */ |
||
74 | |||
75 | /** |
||
76 | * Build a driver. |
||
77 | * |
||
78 | * @param string $driver |
||
79 | * |
||
80 | * @return \Arcanedev\NoCaptcha\Contracts\NoCaptcha |
||
81 | */ |
||
82 | 28 | protected function buildDriver(string $driver): NoCaptchaContract |
|
90 | |||
91 | /** |
||
92 | * Get a value from the config file. |
||
93 | * |
||
94 | * @param string $key |
||
95 | * |
||
96 | * @return mixed |
||
97 | */ |
||
98 | 28 | protected function config(string $key = '') |
|
102 | } |
||
103 |
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: