| Conditions | 13 |
| Paths | 180 |
| Total Lines | 137 |
| Code Lines | 64 |
| Lines | 0 |
| Ratio | 0 % |
| 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 |
||
| 50 | function jodelToHtml($post) |
||
| 51 | { //ToDO |
||
| 52 | //Replace # with link |
||
| 53 | //preg_replace('~(\#)([^\s!,. /()"\'?]+)~', '<a href="tag/$2">#$2</a>', $text); |
||
| 54 | |||
| 55 | //Time to time difference |
||
| 56 | $now = new DateTime(); |
||
| 57 | $d = new DateTime($post['created_at']); |
||
| 58 | $timediff = $now->diff($d); |
||
| 59 | |||
| 60 | $timediff_inSeconds = (string)$timediff->format('%s'); |
||
| 61 | $timediff_inMinutes = (string)$timediff->format('%i'); |
||
| 62 | $timediff_inHours = (string)$timediff->format('%h'); |
||
| 63 | $timediff_inDays = (string)$timediff->format('%d'); |
||
| 64 | $timediff_inMonth = (string)$timediff->format('%m'); |
||
| 65 | |||
| 66 | if($timediff_inMonth!=0) |
||
| 67 | { |
||
| 68 | $timediff = $timediff_inMonth . "m"; |
||
| 69 | } |
||
| 70 | else |
||
| 71 | { |
||
| 72 | if($timediff_inDays!=0) |
||
| 73 | { |
||
| 74 | $timediff = $timediff_inDays . "d"; |
||
| 75 | } |
||
| 76 | else |
||
| 77 | { |
||
| 78 | if($timediff_inHours!=0) |
||
| 79 | { |
||
| 80 | $timediff = $timediff_inHours . "h"; |
||
| 81 | } |
||
| 82 | else |
||
| 83 | { |
||
| 84 | if($timediff_inMinutes!=0) |
||
| 85 | { |
||
| 86 | $timediff = $timediff_inMinutes . "m"; |
||
| 87 | } |
||
| 88 | else |
||
| 89 | { |
||
| 90 | $timediff = $timediff_inSeconds . "s"; |
||
| 91 | } |
||
| 92 | } |
||
| 93 | } |
||
| 94 | } |
||
| 95 | |||
| 96 | |||
| 97 | ?> |
||
| 98 | <article id ="postId-<?php echo $post['post_id']; ?>" class="jodel" style="background-color: #<?php echo $post['color'];?>;"> |
||
| 99 | <content> |
||
| 100 | <?php |
||
| 101 | if(isset($post['image_url'])) |
||
| 102 | { |
||
| 103 | $regexRest = '/[^\w$ .!?-]+/u'; |
||
| 104 | |||
| 105 | echo '<img src="' . $post['image_url'] . '" alt="' . htmlspecialchars(preg_replace($regexRest, '', $post['message'])) . '">'; |
||
| 106 | } |
||
| 107 | else { |
||
| 108 | echo str_replace(' ', ' ', nl2br(htmlspecialchars($post['message']))); |
||
| 109 | } |
||
| 110 | ?> |
||
| 111 | </content> |
||
| 112 | <aside> |
||
| 113 | <button onclick="vote('<?php echo $post['post_id'];?>', 'up', this)"> |
||
| 114 | <i class="fa fa-angle-up fa-3x"></i> |
||
| 115 | </button> |
||
| 116 | <br><span><?php echo $post["vote_count"];?></span><br> |
||
| 117 | |||
| 118 | <button onclick="vote('<?php echo $post['post_id'];?>', 'down', this)"> |
||
| 119 | <i class="fa fa-angle-down fa-3x"></i> |
||
| 120 | </button> |
||
| 121 | </aside> |
||
| 122 | |||
| 123 | <footer> |
||
| 124 | <span class="wrapper"> |
||
| 125 | |||
| 126 | <span class="time"> |
||
| 127 | <span class="tip" data-tooltip="Time"> |
||
| 128 | <i class="fa fa-clock-o"></i> |
||
| 129 | <?php echo $timediff;?> |
||
| 130 | <span class="tiptext"><?php echo $d->format('Y-m-d H:i:s');?></span> |
||
| 131 | </span> |
||
| 132 | </span> |
||
| 133 | <?php if(!$this->isDetailedView) {?> |
||
| 134 | <span class="comments"> |
||
| 135 | <span data-tooltip="Comments"> |
||
| 136 | <a href="<?php echo $this->changePostId($post['post_id'])->toUrl();?>"> |
||
| 137 | <i class="fa fa-commenting-o"></i> |
||
| 138 | <?php if(array_key_exists("child_count", $post)) |
||
| 139 | { |
||
| 140 | echo $post["child_count"]; |
||
| 141 | } else echo "0"; |
||
| 142 | ?> |
||
| 143 | </a> |
||
| 144 | </span> |
||
| 145 | |||
| 146 | </span> |
||
| 147 | <?php |
||
| 148 | } |
||
| 149 | if($this->rights == 'admin' || $this->rights == 'voter') |
||
| 150 | { |
||
| 151 | ?> |
||
| 152 | <span class="voting"> |
||
| 153 | <a target="_blank" href="admin.php?postId=<?php echo $post['post_id'] ?>"> |
||
| 154 | <i class="fa fa-thumbs-o-up"></i> Vote |
||
| 155 | </a> |
||
| 156 | </span> |
||
| 157 | <?php |
||
| 158 | } |
||
| 159 | ?> |
||
| 160 | <span class="distance"> |
||
| 161 | <?php |
||
| 162 | if($this->isDetailedView) |
||
| 163 | { |
||
| 164 | if(isset($post['user_handle']) && $post['user_handle'] == 'OJ') |
||
| 165 | { |
||
| 166 | ?> |
||
| 167 | <span data-tooltip="Author"> |
||
| 168 | <i class="fa fa-user-o"></i> OJ | |
||
| 169 | </span> |
||
| 170 | <?php |
||
| 171 | } |
||
| 172 | } |
||
| 173 | ?> |
||
| 174 | |||
| 175 | <span class="tip" data-tooltip="Distance"> |
||
| 176 | <i class="fa fa-map-marker"></i> |
||
| 177 | <?php echo $post['distance'];?> km |
||
| 178 | <span class="tiptext"><?php echo $post['location']['name'];?></span> |
||
| 179 | </span> |
||
| 180 | </span> |
||
| 181 | |||
| 182 | </span> |
||
| 183 | </footer> |
||
| 184 | </article> |
||
| 185 | <?php |
||
| 186 | } |
||
| 187 | |||
| 367 |
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.