Conditions | 10 |
Paths | 61 |
Total Lines | 48 |
Code Lines | 29 |
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 |
||
21 | public function run() |
||
22 | { |
||
23 | $pid_to_cron_class = []; |
||
24 | foreach ($this->config_dto->working_classes as $cron_class) { |
||
25 | try { |
||
26 | /** @var $cron CronInterface */ |
||
27 | $cron = new $cron_class; |
||
28 | $lock_fd = $this->tryLock($this->getShortClassName($cron)); |
||
29 | if (!$lock_fd) { |
||
|
|||
30 | continue; |
||
31 | } |
||
32 | |||
33 | $pid = pcntl_fork(); |
||
34 | if ($pid === -1) { |
||
35 | throw new MsgException('could not fork : ' . $cron_class); |
||
36 | } elseif ($pid > 0) { //parent |
||
37 | $pid_to_cron_class[$pid] = $cron_class; |
||
38 | continue; |
||
39 | } |
||
40 | |||
41 | $this->runChildProcess($cron); |
||
42 | |||
43 | fclose($lock_fd); |
||
44 | |||
45 | return; |
||
46 | } catch (\Exception $e) { |
||
47 | SentryHelper::triggerSentryException($e); |
||
48 | } |
||
49 | } |
||
50 | |||
51 | //waiting for children |
||
52 | while (true) { |
||
53 | $pid = pcntl_waitpid(0, $status); |
||
54 | if ($pid === -1) { |
||
55 | break; |
||
56 | } |
||
57 | |||
58 | if (!pcntl_wifexited($status)) { |
||
59 | $message = 'process not normal exit : ' . $pid_to_cron_class[$pid] . ' / ' . $status; |
||
60 | SentryHelper::triggerSentryMessage($message); |
||
61 | } |
||
62 | |||
63 | $first_pid = array_keys($pid_to_cron_class)[0]; |
||
64 | if ($pid === $first_pid) { |
||
65 | $this->notifyCronIsRunning(); |
||
66 | } |
||
67 | } |
||
68 | } |
||
69 | |||
136 |
If an expression can have both
false
, andnull
as possible values. It is generally a good practice to always use strict comparison to clearly distinguish between those two values.