| Conditions | 1 |
| Paths | 1 |
| Total Lines | 52 |
| Code Lines | 42 |
| Lines | 0 |
| Ratio | 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 |
||
| 110 | public function getWeatherAlert(Point $point): WeatherAlert |
||
| 111 | { |
||
| 112 | $dto = $this->client->ostrzezenia_pogodowe( |
||
| 113 | $point->y(), |
||
| 114 | $point->x(), |
||
| 115 | $this->apiKey |
||
| 116 | ); |
||
| 117 | return (new WeatherAlert()) |
||
| 118 | ->withAlert( |
||
| 119 | 'frost', |
||
| 120 | new Alert( |
||
| 121 | $dto->mroz, |
||
| 122 | $dto->mroz_od_dnia, |
||
| 123 | $dto->mroz_do_dnia |
||
| 124 | ) |
||
| 125 | )->withAlert( |
||
| 126 | 'heat', |
||
| 127 | new Alert( |
||
| 128 | $dto->upal, |
||
| 129 | $dto->upal_od_dnia, |
||
| 130 | $dto->upal_do_dnia |
||
| 131 | ) |
||
| 132 | )->withAlert( |
||
| 133 | 'wind', |
||
| 134 | new Alert( |
||
| 135 | $dto->wiatr, |
||
| 136 | $dto->wiatr_od_dnia, |
||
| 137 | $dto->wiatr_do_dnia |
||
| 138 | ) |
||
| 139 | )->withAlert( |
||
| 140 | 'storm', |
||
| 141 | new Alert( |
||
| 142 | $dto->burza, |
||
| 143 | $dto->burza_od_dnia, |
||
| 144 | $dto->burza_do_dnia |
||
| 145 | ) |
||
| 146 | )->withAlert( |
||
| 147 | 'tornado', |
||
| 148 | new Alert( |
||
| 149 | $dto->traba, |
||
| 150 | $dto->traba_od_dnia, |
||
| 151 | $dto->traba_do_dnia |
||
| 152 | ) |
||
| 153 | )->withAlert( |
||
| 154 | 'precipitation', |
||
| 155 | new Alert( |
||
| 156 | $dto->opad, |
||
| 157 | $dto->opad_od_dnia, |
||
| 158 | $dto->opad_do_dnia |
||
| 159 | ) |
||
| 160 | ); |
||
| 161 | } |
||
| 162 | } |
||
| 163 |