1 | <?php |
||
11 | trait Response |
||
12 | { |
||
13 | /** |
||
14 | * Make a JSON response. |
||
15 | * |
||
16 | * @param $statusCode |
||
17 | * |
||
18 | * @return IlluminateJsonResponse |
||
19 | */ |
||
20 | protected function makeJsonResponse($statusCode) |
||
21 | { |
||
22 | return new IlluminateJsonResponse( |
||
23 | $this->getErrorBagForStatusCode($statusCode), |
||
24 | $statusCode |
||
25 | ); |
||
26 | } |
||
27 | |||
28 | /** |
||
29 | * Make the status code, to respond accordingly. |
||
30 | * |
||
31 | * @return int |
||
32 | */ |
||
33 | 5 | protected function makeStatusCode() |
|
34 | { |
||
35 | return |
||
36 | 5 | $this->inputHasOneTimePassword() && !$this->checkOTP() |
|
37 | 1 | ? SymfonyResponse::HTTP_UNPROCESSABLE_ENTITY |
|
38 | 5 | : SymfonyResponse::HTTP_OK; |
|
39 | } |
||
40 | |||
41 | /** |
||
42 | * Make a web response. |
||
43 | * |
||
44 | * @param $statusCode |
||
45 | * |
||
46 | * @return \Illuminate\Http\Response |
||
47 | */ |
||
48 | 5 | protected function makeHtmlResponse($statusCode) |
|
49 | { |
||
50 | 5 | $view = $this->getView(); |
|
51 | |||
52 | 5 | if ($statusCode !== SymfonyResponse::HTTP_OK) { |
|
53 | 1 | $view->withErrors($this->getErrorBagForStatusCode($statusCode)); |
|
|
|||
54 | } |
||
55 | |||
56 | 5 | return new IlluminateHtmlResponse($view, $statusCode); |
|
57 | } |
||
58 | |||
59 | /** |
||
60 | * Create a response to request the OTP. |
||
61 | * |
||
62 | * @return \Illuminate\Http\Response|\Illuminate\Http\JsonResponse |
||
63 | */ |
||
64 | 5 | public function makeRequestOneTimePasswordResponse() |
|
65 | { |
||
66 | 5 | event( |
|
67 | 5 | app()->version() < '5.4' |
|
68 | ? new OneTimePasswordRequested53($this->getUser()) |
||
69 | 5 | : new OneTimePasswordRequested($this->getUser()) |
|
70 | ); |
||
71 | |||
72 | 5 | $expectJson = app()->version() < '5.4' |
|
73 | ? $this->getRequest()->wantsJson() |
||
74 | 5 | : $this->getRequest()->expectsJson(); |
|
75 | |||
76 | 5 | return $expectJson |
|
77 | ? $this->makeJsonResponse($this->makeStatusCode()) |
||
78 | 5 | : $this->makeHtmlResponse($this->makeStatusCode()); |
|
79 | } |
||
80 | |||
81 | /** |
||
82 | * Get the OTP view. |
||
83 | * |
||
84 | * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View |
||
85 | */ |
||
86 | 5 | private function getView() |
|
87 | { |
||
88 | 5 | return view($this->config('view')); |
|
89 | } |
||
90 | |||
91 | abstract protected function getErrorBagForStatusCode($statusCode); |
||
92 | |||
93 | abstract protected function inputHasOneTimePassword(); |
||
94 | |||
95 | abstract public function checkOTP(); |
||
96 | |||
97 | abstract protected function getUser(); |
||
98 | |||
99 | abstract public function getRequest(); |
||
100 | |||
101 | abstract protected function config($string, $children = []); |
||
102 | } |
||
103 |
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: