| Conditions | 10 |
| Paths | 30 |
| Total Lines | 42 |
| Code Lines | 27 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 1 |
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 |
||
| 69 | 'class' => $this->eventCollectionClass, |
||
| 70 | ]); |
||
| 71 | } |
||
| 72 | } |
||
| 73 | |||
| 74 | /** |
||
| 75 | * Prepares for sending the response. |
||
| 76 | * @throws InvalidConfigException |
||
| 77 | */ |
||
| 78 | protected function prepare() |
||
| 79 | { |
||
| 80 | $events = $this->eventCollection->getEvents(); |
||
| 81 | if (empty($events)) { |
||
| 82 | throw new InvalidConfigException('At least one event should be added to the poll.'); |
||
| 83 | } |
||
| 84 | foreach ($events as $eventKey => $event) { |
||
| 85 | if (!isset($this->lastStates[$eventKey])) { |
||
| 86 | $this->lastStates[$eventKey] = (int) Yii::$app->getRequest()->getQueryParam($event->getParamName()); |
||
| 87 | } |
||
| 88 | } |
||
| 89 | |||
| 90 | $this->version = '1.1'; |
||
| 91 | $this->getHeaders() |
||
| 92 | ->set('Transfer-Encoding', 'chunked') |
||
| 93 | ->set('Content-Type', 'application/json; charset=UTF-8'); |
||
| 94 | |||
| 95 | Yii::$app->getSession()->close(); |
||
| 96 | } |
||
| 97 | |||
| 98 | /** |
||
| 99 | * Sends the response content to the client. |
||
| 100 | */ |
||
| 101 | protected function sendContent() |
||
| 102 | { |
||
| 103 | $events = $this->eventCollection->getEvents(); |
||
| 104 | $endTime = time() + $this->timeout; |
||
| 105 | $connectionTestTime = time() + 1; |
||
| 106 | $this->clearOutputBuffers(); |
||
| 107 | do { |
||
| 108 | $triggered = []; |
||
| 109 | foreach ($events as $eventKey => $event) { |
||
| 110 | $event->updateState(); |
||
| 111 | if ($event->getState() !== $this->lastStates[$eventKey]) { |
||
| 180 |