Conditions | 14 |
Paths | 12 |
Total Lines | 46 |
Code Lines | 25 |
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 |
||
58 | public function list() |
||
59 | { |
||
60 | exec('crontab -l',$list); |
||
61 | |||
62 | $this->table->setHeaders(['no','minute','hour','day','month','week','schedule','description']); |
||
63 | |||
64 | |||
65 | foreach ($list as $key=>$item){ |
||
66 | |||
67 | if(preg_match('@.*php api schedule run '.strtolower($this->projectName()).'.*@is',$item,$result)){ |
||
68 | if(isset($result[0])){ |
||
69 | |||
70 | $cron = []; |
||
71 | |||
72 | if(preg_match('@(.*)\scd@',$result[0],$cron)){ |
||
73 | $cron = (isset($cron[1])) ? explode(' ',$cron[1]) : ''; |
||
74 | |||
75 | } |
||
76 | |||
77 | $scheduleName = ''; |
||
78 | |||
79 | if(preg_match('@schedule\:(.*?)\s@',$result[0],$scheduler)){ |
||
80 | $scheduleName = (isset($scheduler[1])) ? $scheduler[1] : ''; |
||
81 | |||
82 | $schedulerInstance = $this->scheduleInstance(ucfirst($scheduleName)); |
||
83 | $description = ClosureDispatcher::bind($schedulerInstance)->call(function(){ |
||
84 | return $this->description; |
||
85 | }); |
||
86 | |||
87 | } |
||
88 | |||
89 | $this->table->addRow([ |
||
90 | $key+1, |
||
91 | isset($cron[0]) ? $cron[0] : '', |
||
92 | isset($cron[1]) ? $cron[1] : '', |
||
93 | isset($cron[2]) ? $cron[2] : '', |
||
94 | isset($cron[3]) ? $cron[3] : '', |
||
95 | isset($cron[4]) ? $cron[4] : '', |
||
96 | $scheduleName, |
||
97 | isset($description) ? $description : '', |
||
98 | ]); |
||
99 | } |
||
100 | } |
||
101 | } |
||
102 | |||
103 | echo $this->table->getTable(); |
||
104 | } |
||
191 |