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