| Conditions | 10 |
| Paths | 22 |
| Total Lines | 25 |
| Code Lines | 15 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 13 |
| CRAP Score | 10.2368 |
| 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 |
||
| 33 | 1 | public function __construct(array $data) |
|
| 34 | { |
||
| 35 | |||
| 36 | 1 | $this->total_count = isset($data['total_count']) ? $data['total_count'] : null; |
|
| 37 | 1 | if ($this->total_count === null || !is_numeric($this->total_count)) { |
|
| 38 | throw new TelegramException('total_count is empty!'); |
||
| 39 | } |
||
| 40 | 1 | $this->photos = isset($data['photos']) ? $data['photos'] : null; |
|
| 41 | 1 | if ($this->photos === null || !is_array($data['photos'])) { |
|
| 42 | throw new TelegramException('photos is empty!'); |
||
| 43 | } |
||
| 44 | |||
| 45 | 1 | $photos = []; |
|
| 46 | 1 | foreach ($this->photos as $key => $photo) { |
|
| 47 | 1 | if (is_array($photo)) { |
|
| 48 | 1 | foreach ($photo as $photo_size) { |
|
| 49 | 1 | $photos[$key][] = new PhotoSize($photo_size); |
|
| 50 | } |
||
| 51 | } else { |
||
| 52 | 1 | throw new TelegramException('photo is not an array!'); |
|
| 53 | } |
||
| 54 | } |
||
| 55 | |||
| 56 | 1 | $this->photos = $photos; |
|
| 57 | 1 | } |
|
| 58 | |||
| 79 |