| Conditions | 6 |
| Paths | 30 |
| Total Lines | 70 |
| Code Lines | 35 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 4 | ||
| Bugs | 0 | Features | 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\Tasks; |
||
| 72 | public function run($name, $task, $jid = null, $parameters = array()) { |
||
| 73 | |||
| 74 | try { |
||
| 75 | |||
| 76 | $this->logger->info("Starting new task $task ($name)"); |
||
| 77 | |||
| 78 | $start = microtime(true); |
||
| 79 | |||
| 80 | $thetask = $this->createTask($name, $task, $parameters); |
||
| 81 | |||
| 82 | $this->events->emit( new TaskEvent('start', $thetask) ); |
||
| 83 | |||
| 84 | $pid = $thetask->pid; |
||
|
|
|||
| 85 | |||
| 86 | $wid = $this->worklog->open($pid, $name, $jid, $task, $parameters, $start); |
||
| 87 | |||
| 88 | $status = true; |
||
| 89 | |||
| 90 | $this->events->emit( new TaskStatusEvent('start', $thetask) ); |
||
| 91 | |||
| 92 | try { |
||
| 93 | |||
| 94 | // run task |
||
| 95 | $result = $thetask->run(); |
||
| 96 | |||
| 97 | } catch (TaskException $te) { |
||
| 98 | |||
| 99 | $status = false; |
||
| 100 | |||
| 101 | $result = $te->getMessage(); |
||
| 102 | |||
| 103 | } catch (Exception $e) { |
||
| 104 | |||
| 105 | $status = false; |
||
| 106 | |||
| 107 | $result = $e->getMessage(); |
||
| 108 | |||
| 109 | } |
||
| 110 | |||
| 111 | $this->events->emit( new TaskStatusEvent($status ? 'success' : 'error', $thetask) ); |
||
| 112 | |||
| 113 | $this->events->emit( new TaskStatusEvent('stop', $thetask) ); |
||
| 114 | |||
| 115 | $this->events->emit( new TaskEvent('stop', $thetask) ); |
||
| 116 | |||
| 117 | $end = microtime(true); |
||
| 118 | |||
| 119 | $this->worklog->close($wid, $status, $result, $end); |
||
| 120 | |||
| 121 | $this->logger->notice("Task $name ($task) with pid $pid ends in ".$status ? 'success' : 'error'); |
||
| 122 | |||
| 123 | } catch (Exception $e) { |
||
| 124 | |||
| 125 | throw $e; |
||
| 126 | |||
| 127 | } |
||
| 128 | |||
| 129 | return new Result( |
||
| 130 | array ( |
||
| 131 | $pid, |
||
| 132 | $name, |
||
| 133 | $status, |
||
| 134 | $start, |
||
| 135 | $end, |
||
| 136 | $result, |
||
| 137 | intval($wid) |
||
| 138 | ) |
||
| 139 | ); |
||
| 140 | |||
| 141 | } |
||
| 142 | |||
| 164 |
If you access a property on an interface, you most likely code against a concrete implementation of the interface.
Available Fixes
Adding an additional type check:
Changing the type hint: