1 | <?php |
||||||
2 | |||||||
3 | namespace Larapie\Actions\Concerns; |
||||||
4 | |||||||
5 | use Illuminate\Http\Request; |
||||||
6 | |||||||
7 | trait RunsAsController |
||||||
8 | { |
||||||
9 | protected $request; |
||||||
10 | |||||||
11 | 5 | public function __invoke(Request $request) |
|||||
12 | { |
||||||
13 | 5 | return $this->runAsController($request); |
|||||
14 | } |
||||||
15 | |||||||
16 | 13 | public function runAsController(Request $request) |
|||||
17 | { |
||||||
18 | 13 | $this->runningAs = 'controller'; |
|||||
0 ignored issues
–
show
Bug
Best Practice
introduced
by
![]() |
|||||||
19 | 13 | $this->request = $request; |
|||||
20 | |||||||
21 | 13 | $this->reset($request->user()); |
|||||
0 ignored issues
–
show
It seems like
reset() must be provided by classes using this trait. How about adding it as abstract method to this trait?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||
22 | 13 | $this->fill($this->getAttributesFromRequest($request)); |
|||||
0 ignored issues
–
show
It seems like
fill() must be provided by classes using this trait. How about adding it as abstract method to this trait?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||
23 | |||||||
24 | 13 | $result = $this->run(); |
|||||
0 ignored issues
–
show
It seems like
run() must be provided by classes using this trait. How about adding it as abstract method to this trait?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||
25 | |||||||
26 | 10 | if (method_exists($this, 'response')) { |
|||||
27 | 5 | return $this->response($result, $request); |
|||||
28 | } |
||||||
29 | |||||||
30 | 5 | if (method_exists($this, 'jsonResponse') && $request->wantsJson()) { |
|||||
31 | 1 | return $this->jsonResponse($result, $request); |
|||||
32 | } |
||||||
33 | |||||||
34 | 4 | if (method_exists($this, 'htmlResponse') && ! $request->wantsJson()) { |
|||||
35 | 1 | return $this->htmlResponse($result, $request); |
|||||
36 | } |
||||||
37 | |||||||
38 | 3 | return $result; |
|||||
39 | } |
||||||
40 | |||||||
41 | 13 | public function getAttributesFromRequest(Request $request) |
|||||
42 | { |
||||||
43 | 13 | return array_merge( |
|||||
44 | 13 | $this->getAttributesFromRoute($request), |
|||||
45 | 13 | $request->all() |
|||||
46 | ); |
||||||
47 | } |
||||||
48 | |||||||
49 | 13 | public function getAttributesFromRoute(Request $request) |
|||||
50 | { |
||||||
51 | 13 | $route = $request->route(); |
|||||
52 | |||||||
53 | 13 | return $route ? $route->parametersWithoutNulls() : []; |
|||||
54 | } |
||||||
55 | |||||||
56 | 1 | public function getRequest() |
|||||
57 | { |
||||||
58 | 1 | return $this->request; |
|||||
59 | } |
||||||
60 | } |
||||||
61 |