Conditions | 15 |
Paths | 480 |
Total Lines | 151 |
Code Lines | 82 |
Lines | 16 |
Ratio | 10.6 % |
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 | <table> |
||
127 | <tr> |
||
128 | <td 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 | </td> |
||
135 | <td class="comments"> |
||
136 | <?php if(!$this->isDetailedView) {?> |
||
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 | <?php } ?> |
||
147 | </td> |
||
148 | <td class="distance"> |
||
149 | <?php |
||
150 | if($this->isDetailedView) |
||
151 | { |
||
152 | if(isset($post["parent_creator"]) && $post["parent_creator"] == 1) |
||
153 | { |
||
154 | ?> |
||
155 | <span data-tooltip="Author"> |
||
156 | <i class="fa fa-user-o"></i> OJ | |
||
157 | </span> |
||
158 | <?php |
||
159 | } |
||
160 | else |
||
161 | { |
||
162 | //Is not parent Jodel in detailed View |
||
163 | if(!array_key_exists('child_count', $post) && array_key_exists('parent_creator', $post)) |
||
164 | { |
||
165 | ?> |
||
166 | <span data-tooltip="Author"> |
||
167 | <i class="fa fa-user-o"></i> #<?php echo $post["user_handle"];?> | |
||
168 | </span> |
||
169 | <?php |
||
170 | } |
||
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 | </td> |
||
181 | </tr> |
||
182 | </table> |
||
183 | </footer> |
||
184 | </article> |
||
185 | <?php |
||
186 | } |
||
187 | |||
388 | } |
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.