1 | <?php |
||
13 | class OauthController extends Controller |
||
14 | { |
||
15 | protected $socialite; |
||
16 | protected $auth; |
||
17 | |||
18 | public function __construct(Socialite $socialite, Guard $auth) |
||
23 | |||
24 | public function authenticate(Request $request, $provider) |
||
28 | |||
29 | public function execute($request, $provider) |
||
40 | |||
41 | /** |
||
42 | * Find a user by username or create a new user |
||
43 | * @param |
||
44 | * @return |
||
45 | */ |
||
46 | public function findByProviderIdOrCreate($userData, $provider) |
||
69 | |||
70 | private function isUsernameExists($username = null) |
||
76 | |||
77 | private function isEmailExists($email = null) |
||
83 | |||
84 | /** |
||
85 | * Check if the user's info needs updating |
||
86 | * @param |
||
87 | * @return |
||
88 | */ |
||
89 | public function checkIfUserNeedsUpdating($userData, $user) |
||
110 | |||
111 | /** |
||
112 | * Redirect the user to the Social Media Account authentication page |
||
113 | * @param $provider |
||
114 | * @return \Symfony\Component\HttpFoundation\RedirectResponse |
||
115 | */ |
||
116 | private function getAuthorizationFirst($provider) |
||
120 | |||
121 | /** |
||
122 | * Get Data from Social Media Account |
||
123 | * @param string $provider |
||
124 | * @return collection |
||
125 | */ |
||
126 | private function getSocialUser($provider) |
||
130 | |||
131 | } |
||
132 | |||
133 |
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: