Conditions | 13 |
Paths | 240 |
Total Lines | 149 |
Code Lines | 70 |
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 |
||
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 | <button onclick="vote('<?php echo $post['post_id'];?>', 'up', this)"> |
||
100 | <i class="fa fa-angle-up fa-3x"></i> |
||
101 | </button> |
||
102 | <br><span><?php echo $post["vote_count"];?></span><br> |
||
103 | |||
104 | <button onclick="vote('<?php echo $post['post_id'];?>', 'down', this)"> |
||
105 | <i class="fa fa-angle-down fa-3x"></i> |
||
106 | </button> |
||
107 | </aside> |
||
108 | |||
109 | <footer> |
||
110 | <span class="wrapper"> |
||
111 | |||
112 | <span class="time"> |
||
113 | <span class="tip" data-tooltip="Time"> |
||
114 | <i class="fa fa-clock-o"></i> |
||
115 | <?php echo $timediff;?> |
||
116 | <span class="tiptext"><?php echo $d->format('Y-m-d H:i:s');?></span> |
||
117 | </span> |
||
118 | </span> |
||
119 | <?php if(!$this->isDetailedView) {?> |
||
120 | <span class="comments"> |
||
121 | <span data-tooltip="Comments"> |
||
122 | <a href="<?php echo $this->changePostId($post['post_id'])->toUrl();?>"> |
||
123 | <i class="fa fa-commenting-o"></i> |
||
124 | <?php if(array_key_exists("child_count", $post)) |
||
125 | { |
||
126 | echo $post["child_count"]; |
||
127 | } else echo "0"; |
||
128 | ?> |
||
129 | </a> |
||
130 | </span> |
||
131 | |||
132 | </span> |
||
133 | <?php |
||
134 | } |
||
135 | if (isUserAdmin()) |
||
136 | { |
||
137 | ?> |
||
138 | <span class="voting"> |
||
139 | <a target="_blank" href="admin.php?postId=<?php echo $post['post_id'] ?>"> |
||
140 | <i class="fa fa-thumbs-o-up"></i> Vote |
||
141 | </a> |
||
142 | </span> |
||
143 | <?php |
||
144 | } |
||
145 | ?> |
||
146 | <span class="distance"> |
||
147 | <?php |
||
148 | if($this->isDetailedView) |
||
149 | { |
||
150 | if(isset($post['user_handle']) && $post['user_handle'] == 'OJ') |
||
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)) |
||
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 | </span> |
||
179 | |||
180 | </span> |
||
181 | </footer> |
||
182 | </article> |
||
183 | <?php |
||
184 | } |
||
185 | |||
360 |
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.