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