Conditions | 8 |
Paths | 4 |
Total Lines | 53 |
Code Lines | 35 |
Lines | 0 |
Ratio | 0 % |
Changes | 16 | ||
Bugs | 1 | Features | 1 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
70 | public function handle() |
||
71 | { |
||
72 | $config = app('Illuminate\Contracts\Config\Repository'); |
||
73 | $client = app(Client::class); |
||
74 | |||
75 | $logging = $config->get('captain_hook.log.active'); |
||
76 | $transformer = $this->resolveTransformer($config->get('captain_hook.transformer')); |
||
77 | |||
78 | foreach ($this->webhooks as $webhook) { |
||
79 | |||
80 | if ($logging) { |
||
81 | if ($config->get('captain_hook.log.storage_quantity') != -1 && |
||
82 | $webhook->logs()->count() >= $config->get('captain_hook.log.storage_quantity')) { |
||
83 | $webhook->logs()->orderBy('updated_at', 'desc')->first()->delete(); |
||
84 | } |
||
85 | $log = new WebhookLog([ |
||
86 | 'webhook_id' => $webhook[ 'id' ], |
||
87 | 'url' => $webhook[ 'url' ], |
||
88 | ]); |
||
89 | $middleware = Middleware::tap(function (RequestInterface $request, $options) use ($log) { |
||
90 | $log->payload_format = isset($request->getHeader('Content-Type')[0]) ? $request->getHeader('Content-Type')[0] : null; |
||
91 | $log->payload = $request->getBody()->getContents(); |
||
92 | }, function ($request, $options, PromiseInterface $response) use ($log) { |
||
93 | $response->then(function (ResponseInterface $response) use ($log) { |
||
94 | $log->status = $response->getStatusCode(); |
||
95 | $log->response = $response->getBody()->getContents(); |
||
96 | $log->response_format = $log->payload_format = isset($response->getHeader('Content-Type')[0]) ? $response->getHeader('Content-Type')[0] : null; |
||
97 | |||
98 | $log->save(); |
||
99 | |||
100 | // Retry this job if the webhook response didn't give us a HTTP 200 OK |
||
101 | if ($response->getStatusCode() != 200) { |
||
102 | $this->release(30); |
||
103 | } |
||
104 | }); |
||
105 | }); |
||
106 | |||
107 | $client->post($webhook[ 'url' ], [ |
||
108 | 'exceptions' => false, |
||
109 | 'body' => $transformer($this->eventData, $webhook), |
||
110 | 'verify' => false, |
||
111 | 'handler' => $middleware($client->getConfig('handler')), |
||
112 | ]); |
||
113 | } else { |
||
114 | $client->post($webhook[ 'url' ], [ |
||
115 | 'exceptions' => false, |
||
116 | 'body' => $transformer($this->eventData, $webhook), |
||
117 | 'verify' => false, |
||
118 | 'timeout' => 10, |
||
119 | ]); |
||
120 | } |
||
121 | } |
||
122 | } |
||
123 | } |
||
124 |
This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.