Conditions | 4 |
Paths | 5 |
Total Lines | 56 |
Code Lines | 30 |
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 namespace Comodojo\Extender\Workers; |
||
57 | public function loop() { |
||
58 | |||
59 | if ( $this->wakeup_time > time() ) { |
||
60 | // $this->logger->debug('Still in sleep time, next planned wakeup is '.date('r', $this->wakeup_time)); |
||
61 | return; |
||
62 | } |
||
63 | |||
64 | $schedule_manager = new ScheduleManager( |
||
65 | $this->getConfiguration(), |
||
66 | $this->getLogger(), |
||
67 | $this->getEvents() |
||
68 | ); |
||
69 | |||
70 | $jobs = $schedule_manager->getAll(true); |
||
71 | unset($schedule_manager); |
||
72 | |||
73 | $results = []; |
||
74 | |||
75 | // if ( empty($jobs) ) { |
||
76 | // |
||
77 | // $this->logger->debug('Nothing to do right now, sleeping... zzZZzZzZzz'); |
||
78 | // |
||
79 | // } else { |
||
80 | |||
81 | if ( !empty($jobs) ) { |
||
82 | |||
83 | $this->logger->debug(count($jobs)." jobs will be executed"); |
||
84 | $requests = $this->jobsToRequests($jobs); |
||
85 | |||
86 | $task_manager = new TaskManager( |
||
87 | $this->locker, |
||
88 | $this->getConfiguration(), |
||
89 | $this->getLogger(), |
||
90 | $this->getTasksTable(), |
||
91 | $this->getEvents() |
||
92 | ); |
||
93 | $results = $task_manager->addBulk($requests)->run(); |
||
94 | unset($task_manager); |
||
95 | |||
96 | } |
||
97 | |||
98 | $schedule_updater = new ScheduleUpdater( |
||
99 | $this->getConfiguration(), |
||
100 | $this->getLogger(), |
||
101 | $this->getEvents() |
||
102 | ); |
||
103 | |||
104 | $wut = $schedule_updater->updateFromResults($results); |
||
105 | unset($schedule_updater); |
||
106 | |||
107 | $this->wakeup_time = $wut; |
||
108 | if ( $this->wakeup_time !== 0 ) { |
||
109 | $this->logger->debug('Sleep time! Next planned wakeup is at '.date('r', $this->wakeup_time)); |
||
110 | } |
||
111 | |||
112 | $this->locker->lock([]); |
||
113 | |||
129 |