Conditions | 9 |
Paths | 18 |
Total Lines | 55 |
Code Lines | 33 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
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 |
||
18 | public function actionIndex($queueName = 'app') |
||
19 | { |
||
20 | $queue = Yii::$app->queue->get()->queue($queueName); |
||
21 | while (true) { |
||
22 | try { |
||
23 | $job = $queue->pull(1000); |
||
24 | if (is_null($job)) { |
||
25 | // There's nothing presently in the queue, so don't do anything |
||
26 | if (YII_DEBUG) { |
||
27 | Yii::info("There aren't any jobs in the queue. Waiting for additional jobs..."); |
||
28 | } |
||
29 | continue; |
||
30 | } |
||
31 | } catch (\Disque\Queue\JobNotAvailableException $e) { |
||
|
|||
32 | if (YII_DEBUG) { |
||
33 | Yii::info("[" . date('Y-m-d H:i:s') . "] A scheduled job is available, but we should wait before running it."); |
||
34 | } |
||
35 | continue; |
||
36 | } |
||
37 | |||
38 | $body = $job->getBody(); |
||
39 | if (!isset($body['class'])) { |
||
40 | Yii::error("An error occured when trying to run an event with the following payload:" . print_r($body, true)); |
||
41 | continue; |
||
42 | } |
||
43 | |||
44 | try { |
||
45 | $class = $body['class']; |
||
46 | unset($body['class']); |
||
47 | |||
48 | $event = new $class($body, $queue, $job); |
||
49 | $reflect = new ReflectionClass($event); |
||
50 | $eventName = $reflect->getShortName(); |
||
51 | |||
52 | // Bind an event handler |
||
53 | $this->on($eventName, function ($event) { |
||
54 | $event->run(); |
||
55 | // The event should be handled in some way, if it isn't, called the global event handler and mark it as processed |
||
56 | if (!$event->handled) { |
||
57 | $event->handled(); |
||
58 | } |
||
59 | }); |
||
60 | |||
61 | // Trigger the event |
||
62 | $this->trigger($eventName, $event); |
||
63 | |||
64 | // Unbind the event handler |
||
65 | $this->off($eventName); |
||
66 | } catch (\Exception $e) { |
||
67 | Yii::error("Event $class failed encountered an error: " . $e->getMessage()); |
||
68 | $queue->processed($job); |
||
69 | continue; |
||
70 | } |
||
71 | } |
||
72 | } |
||
73 | } |
Scrutinizer analyzes your
composer.json
/composer.lock
file if available to determine the classes, and functions that are defined by your dependencies.It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.