| Conditions | 16 |
| Paths | 960 |
| Total Lines | 164 |
| Code Lines | 88 |
| Lines | 16 |
| Ratio | 9.76 % |
| 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 |
||
| 36 | function jodelToHtml($post) |
||
| 37 | { //ToDO |
||
| 38 | //Replace # with link |
||
| 39 | //preg_replace('~(\#)([^\s!,. /()"\'?]+)~', '<a href="tag/$2">#$2</a>', $text); |
||
| 40 | |||
| 41 | //Time to time difference |
||
| 42 | $now = new DateTime(); |
||
| 43 | $d = new DateTime($post['created_at']); |
||
| 44 | $timediff = $now->diff($d); |
||
| 45 | |||
| 46 | $timediff_inSeconds = (string)$timediff->format('%s'); |
||
| 47 | $timediff_inMinutes = (string)$timediff->format('%i'); |
||
| 48 | $timediff_inHours = (string)$timediff->format('%h'); |
||
| 49 | $timediff_inDays = (string)$timediff->format('%d'); |
||
| 50 | $timediff_inMonth = (string)$timediff->format('%m'); |
||
| 51 | |||
| 52 | if($timediff_inMonth!=0) |
||
| 53 | { |
||
| 54 | $timediff = $timediff_inMonth . "m"; |
||
| 55 | } |
||
| 56 | else |
||
| 57 | { |
||
| 58 | if($timediff_inDays!=0) |
||
| 59 | { |
||
| 60 | $timediff = $timediff_inDays . "d"; |
||
| 61 | } |
||
| 62 | else |
||
| 63 | { |
||
| 64 | if($timediff_inHours!=0) |
||
| 65 | { |
||
| 66 | $timediff = $timediff_inHours . "h"; |
||
| 67 | } |
||
| 68 | else |
||
| 69 | { |
||
| 70 | if($timediff_inMinutes!=0) |
||
| 71 | { |
||
| 72 | $timediff = $timediff_inMinutes . "m"; |
||
| 73 | } |
||
| 74 | else |
||
| 75 | { |
||
| 76 | $timediff = $timediff_inSeconds . "s"; |
||
| 77 | } |
||
| 78 | } |
||
| 79 | } |
||
| 80 | } |
||
| 81 | |||
| 82 | |||
| 83 | ?> |
||
| 84 | <article id ="postId-<?php echo $post['post_id']; ?>" class="jodel" style="background-color: #<?php echo $post['color'];?>;"> |
||
| 85 | <content> |
||
| 86 | <?php |
||
| 87 | if(isset($post['image_url'])) |
||
| 88 | { |
||
| 89 | $regexRest = '/[^\w$ .!?-]+/u'; |
||
| 90 | |||
| 91 | echo '<img src="' . $post['image_url'] . '" alt="' . htmlspecialchars(preg_replace($regexRest, '', $post['message'])) . '">'; |
||
| 92 | } |
||
| 93 | else { |
||
| 94 | echo str_replace(' ', ' ', nl2br(htmlspecialchars($post['message']))); |
||
| 95 | } |
||
| 96 | ?> |
||
| 97 | </content> |
||
| 98 | <aside> |
||
| 99 | <?php |
||
| 100 | View Code Duplication | if($this->isDetailedView) |
|
| 101 | {?> |
||
| 102 | <a href="index.php?vote=up&getPostDetails=true&postId=<?php echo $post['post_id'];?>&postId_parent=<?php echo htmlspecialchars($_GET['postId']);?>" rel="nofollow"> |
||
| 103 | <?php } |
||
| 104 | else |
||
| 105 | {?> |
||
| 106 | <a href="index.php?vote=up&postId=<?php echo $post['post_id'];?>" rel="nofollow"> |
||
| 107 | <?php } ?> |
||
| 108 | <i class="fa fa-angle-up fa-3x"></i> |
||
| 109 | </a> |
||
| 110 | <br /> |
||
| 111 | <?php echo $post["vote_count"];?><br /> |
||
| 112 | <?php |
||
| 113 | View Code Duplication | if($this->isDetailedView) |
|
| 114 | {?> |
||
| 115 | <a href="index.php?vote=down&getPostDetails=true&postId=<?php echo $post['post_id'];?>&postId_parent=<?php echo htmlspecialchars($_GET['postId']);?>" rel="nofollow"> |
||
| 116 | <?php } |
||
| 117 | else |
||
| 118 | {?> |
||
| 119 | <a href="index.php?vote=down&postId=<?php echo $post['post_id'];?>" rel="nofollow"> |
||
| 120 | <?php } ?> |
||
| 121 | <i class="fa fa-angle-down fa-3x"></i> |
||
| 122 | </a> |
||
| 123 | </aside> |
||
| 124 | |||
| 125 | <footer> |
||
| 126 | <span class="wrapper"> |
||
| 127 | |||
| 128 | <span class="time"> |
||
| 129 | <span class="tip" data-tooltip="Time"> |
||
| 130 | <i class="fa fa-clock-o"></i> |
||
| 131 | <?php echo $timediff;?> |
||
| 132 | <span class="tiptext"><?php echo $d->format('Y-m-d H:i:s');?></span> |
||
| 133 | </span> |
||
| 134 | </span> |
||
| 135 | <?php if(!$this->isDetailedView) {?> |
||
| 136 | <span class="comments"> |
||
| 137 | <span data-tooltip="Comments"> |
||
| 138 | <a href="<?php echo $this->changePostId($post['post_id'])->toUrl();?>"> |
||
| 139 | <i class="fa fa-commenting-o"></i> |
||
| 140 | <?php if(array_key_exists("child_count", $post)) { |
||
| 141 | echo $post["child_count"]; |
||
| 142 | } else echo "0"; |
||
| 143 | ?> |
||
| 144 | </a> |
||
| 145 | </span> |
||
| 146 | |||
| 147 | </span> |
||
| 148 | <?php |
||
| 149 | } |
||
| 150 | if (isUserAdmin()) |
||
| 151 | { |
||
| 152 | ?> |
||
| 153 | <span class="voting"> |
||
| 154 | <a target="_blank" href="admin.php?postId=<?php echo $post['post_id'] ?>"> |
||
| 155 | <i class="fa fa-thumbs-o-up"></i> Vote |
||
| 156 | </a> |
||
| 157 | </span> |
||
| 158 | <?php |
||
| 159 | } |
||
| 160 | ?> |
||
| 161 | <span class="distance"> |
||
| 162 | <?php |
||
| 163 | if($this->isDetailedView) |
||
| 164 | { |
||
| 165 | if(isset($post["parent_creator"]) && $post["parent_creator"] == 1) |
||
| 166 | { |
||
| 167 | ?> |
||
| 168 | <span data-tooltip="Author"> |
||
| 169 | <i class="fa fa-user-o"></i> OJ | |
||
| 170 | </span> |
||
| 171 | <?php |
||
| 172 | } |
||
| 173 | else |
||
| 174 | { |
||
| 175 | //Is not parent Jodel in detailed View |
||
| 176 | if(!array_key_exists('child_count', $post) && array_key_exists('parent_creator', $post)) |
||
| 177 | { |
||
| 178 | ?> |
||
| 179 | <span data-tooltip="Author"> |
||
| 180 | <i class="fa fa-user-o"></i> #<?php echo $post["user_handle"];?> | |
||
| 181 | </span> |
||
| 182 | <?php |
||
| 183 | } |
||
| 184 | } |
||
| 185 | } |
||
| 186 | ?> |
||
| 187 | |||
| 188 | <span class="tip" data-tooltip="Distance"> |
||
| 189 | <i class="fa fa-map-marker"></i> |
||
| 190 | <?php echo $post['distance'];?> km |
||
| 191 | <span class="tiptext"><?php echo $post['location']['name'];?></span> |
||
| 192 | </span> |
||
| 193 | </span> |
||
| 194 | |||
| 195 | </span> |
||
| 196 | </footer> |
||
| 197 | </article> |
||
| 198 | <?php |
||
| 199 | } |
||
| 200 | |||
| 368 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.