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