| Conditions | 4 |
| Paths | 8 |
| Total Lines | 55 |
| Code Lines | 36 |
| 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 | <? |
||
| 33 | private function get_piece_data() |
||
| 34 | { |
||
| 35 | Loader::load('collector', 'portfolio/PortfolioCollector'); |
||
| 36 | $portfolio_result = PortfolioCollector::getPieceByURI($this->title_url); |
||
| 37 | |||
| 38 | if($portfolio_result === null) |
||
| 39 | $this->eject(); |
||
| 40 | |||
| 41 | $portfolio_image_result = PortfolioCollector::getImagesForPiece($portfolio_result->id, 2); |
||
| 42 | |||
| 43 | $image_path = "portfolio/{$portfolio_image_result[0]->name}"; |
||
| 44 | $image_path = Loader::getImagePath('image', $image_path); |
||
| 45 | $image_size = getimagesize($image_path); |
||
| 46 | |||
| 47 | $main_image = new stdclass(); |
||
| 48 | $main_image->id = $portfolio_image_result[0]->id; |
||
| 49 | $main_image->link = "/image/portfolio/{$portfolio_image_result[0]->name}"; |
||
| 50 | |||
| 51 | $main_image->width = $image_size[0]; |
||
| 52 | $main_image->height = $image_size[1]; |
||
| 53 | |||
| 54 | foreach($portfolio_image_result as $portfolio_image) |
||
| 55 | { |
||
| 56 | $thumb = $portfolio_image->name; |
||
| 57 | $thumb_array = explode('.', $thumb); |
||
| 58 | $thumb = "{$thumb_array[0]}_clip.{$thumb_array[1]}"; |
||
| 59 | |||
| 60 | $image_path = "portfolio/{$thumb}"; |
||
| 61 | $image_path = Loader::getImagePath('image', $image_path); |
||
| 62 | $image_size = getimagesize($image_path); |
||
| 63 | |||
| 64 | $image_obj = new stdclass(); |
||
| 65 | $image_obj->id = $portfolio_image->id; |
||
| 66 | $image_obj->link = "/image/portfolio/{$thumb}"; |
||
| 67 | |||
| 68 | $image_obj->width = $image_size[0]; |
||
| 69 | $image_obj->height = $image_size[1]; |
||
| 70 | |||
| 71 | $image_array[] = $image_obj; |
||
| 72 | } |
||
| 73 | |||
| 74 | $portfolio_tag_result = PortfolioCollector::getTagsForPiece($portfolio_result->id); |
||
| 75 | |||
| 76 | foreach($portfolio_tag_result as $portfolio_tag) |
||
| 77 | { |
||
| 78 | $tag_array[] = $portfolio_tag->name; |
||
| 79 | } |
||
| 80 | |||
| 81 | return array( |
||
| 82 | 'title' => $portfolio_result->title, |
||
| 83 | 'description' => $portfolio_result->description, |
||
| 84 | 'thumbs' => $image_array, |
||
| 85 | 'image' => $main_image, |
||
| 86 | 'tags' => $tag_array); |
||
| 87 | } |
||
| 88 | |||
| 90 |
Short opening tags are disabled in PHP’s default configuration. In such a case, all content of this file is output verbatim to the browser without being parsed, or executed.
As a precaution to avoid these problems better use the long opening tag
<?php.