| Conditions | 8 |
| Paths | 8 |
| Total Lines | 67 |
| Code Lines | 43 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| 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 |
||
| 129 | * @return bool |
||
| 130 | */ |
||
| 131 | public function hasError() |
||
| 132 | { |
||
| 133 | return $this->container->hasError(); |
||
| 134 | } |
||
| 135 | |||
| 136 | /** |
||
| 137 | * @return \Ackintosh\Snidel\Error |
||
| 138 | */ |
||
| 139 | public function getError() |
||
| 140 | { |
||
| 141 | return $this->container->getError(); |
||
| 142 | } |
||
| 143 | |||
| 144 | /** |
||
| 145 | * gets results |
||
| 146 | * |
||
| 147 | * @param string $tag |
||
| 148 | * @return \Ackintosh\Snidel\Result\Collection |
||
| 149 | * @throws \InvalidArgumentException |
||
| 150 | */ |
||
| 151 | public function get($tag = null) |
||
| 152 | { |
||
| 153 | if (!$this->joined) { |
||
| 154 | $this->wait(); |
||
| 155 | } |
||
| 156 | if ($tag !== null && !$this->container->hasTag($tag)) { |
||
| 157 | throw new \InvalidArgumentException('unknown tag: ' . $tag); |
||
| 158 | } |
||
| 159 | |||
| 160 | return $this->container->getCollection($tag); |
||
| 161 | } |
||
| 162 | |||
| 163 | public function setReceivedSignal($sig) |
||
| 164 | { |
||
| 165 | $this->receivedSignal = $sig; |
||
| 166 | } |
||
| 167 | /** |
||
| 168 | * delete shared memory |
||
| 169 | * |
||
| 170 | * @return void |
||
| 171 | * @throws \Ackintosh\Snidel\Exception\SharedMemoryControlException |
||
| 172 | */ |
||
| 173 | private function deleteAllData() |
||
| 174 | { |
||
| 175 | $dataRepository = new DataRepository(); |
||
| 176 | try { |
||
| 177 | $dataRepository->deleteAll(); |
||
| 178 | } catch (SharedMemoryControlException $e) { |
||
| 179 | throw $e; |
||
| 180 | } |
||
| 181 | } |
||
| 182 | |||
| 183 | public function __destruct() |
||
| 184 | { |
||
| 185 | if ($this->ownerPid === getmypid()) { |
||
| 186 | if ($this->container->existsMaster()) { |
||
| 187 | $this->log->info('shutdown master process.'); |
||
| 188 | $this->container->sendSignalToMaster(); |
||
| 189 | } |
||
| 190 | |||
| 191 | unset($this->container); |
||
| 192 | } |
||
| 193 | |||
| 194 | if ($this->exceptionHasOccured) { |
||
| 195 | $this->log->info('destruct processes are started.(exception has occured)'); |
||
| 196 | $this->log->info('--> deleting all shared memory.'); |
||
| 211 |
An exit expression should only be used in rare cases. For example, if you write a short command line script.
In most cases however, using an
exitexpression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.