Completed
Push — master ( 45769d...0479fb )
by mains
02:43
created

get-posts-ajax.php (16 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 20 and the first side effect is on line 2.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
error_reporting(-1);
3
4
include 'php/DatabaseConnect.php';
5
include 'php/Requests/AbstractRequest.php';
6
include 'php/Requests/CreateUser.php';
7
include 'php/AccountData.php';
8
include 'php/Location.php';
9
include 'php/Requests/GetPosts.php';
10
include 'php/Requests/GetKarma.php';
11
include 'php/Requests/UpdateLocation.php';
12
include 'php/Requests/Upvote.php';
13
include 'php/Requests/Downvote.php';
14
include 'php/Requests/GetPostDetails.php';
15
include 'php/Requests/SendJodel.php';
16
17
require_once 'php/Requests/libary/Requests.php';
18
Requests::register_autoloader();
19
20
function getPosts($lastPostId, $url) {
21
	$db = new DatabaseConnect();
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $db. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
22
	if ($db->connect_errno) {
23
		echo 'Sorry, die Verbindung zu unserem superfetten endgeilen 
24
					Server ist hops gegangen. Wegen '. $db -> connect_error;
25
	}
26
	
27
	$result = $db->query("SELECT * FROM accounts WHERE id='1'");
28
	
29
	if ($result->num_rows > 0) {
30
		// output data of each row
31
		while($row = $result->fetch_assoc()) {
32
			$access_token = $row["access_token"];
33
		}
34
	}
35
	else
36
	{
37
		echo "0 results";
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal 0 results does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
38
	}
39
	
40
	$accountCreator = new GetPosts();
41
	$accountCreator->setLastPostID($lastPostId);
42
	$accountCreator->setUrl($url);
43
	$accountCreator->setAccessToken($access_token);
0 ignored issues
show
The variable $access_token does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
44
	$data = $accountCreator->execute();
45
46
	return $data;
47
}
48
	$posts;
49
50 View Code Duplication
	if(isset($_GET['view']))
51
	{
52
		switch ($_GET['view']) {
53
			case 'comment':
54
				$view = 'comment';
55
				break;
56
			
57
			case 'upVote':
58
				$view = 'upVote';
59
				break;
60
61
			default:
62
				$view = 'time';
63
				break;
64
		}
65
	}
66
	else
67
	{
68
		$view = 'time';
69
	}
70
71 View Code Duplication
	if($view=='comment')
72
	{
73
		$url = "/v2/posts/location/discussed/";
74
	}
75
	else
76
	{
77
		if($view=='upVote')
78
		{
79
			$url = "/v2/posts/location/popular/";
80
		}
81
		else
82
		{
83
			$url = "/v2/posts/location/";
84
		}
85
	}
86
87
	if(isset($_GET['lastPostId'])) {
88
	
89
		$lastPostId = htmlspecialchars($_GET['lastPostId']);
90
		
91
		$posts = getPosts($lastPostId, $url)['posts'];
0 ignored issues
show
Equals sign not aligned with surrounding assignments; expected 11 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
92
		$loops = 29;
93
		$showCommentIcon = TRUE;
94
		?>
95
		<div class="nextPosts">
96
		<?php
97 View Code Duplication
		for($i = 0; $i<$loops; $i++) {
98
		
99
			if(isset($posts[$i])) {
100
				$lastPostId = $posts[$i]['post_id'];
101
102
				
103
				$now = new DateTime();
104
				$d = new DateTime($posts[$i]["created_at"]);
0 ignored issues
show
Equals sign not aligned with surrounding assignments; expected 3 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
Coding Style Comprehensibility introduced by
The string literal created_at does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
105
				
106
				
107
				//Time to time difference
108
							$timediff = $now->diff($d);
109
110
							$timediff_inSeconds = (string)$timediff->format('%s');
111
							$timediff_inMinutes = (string)$timediff->format('%i');
112
							$timediff_inHours = (string)$timediff->format('%h');
113
							$timediff_inDays = (string)$timediff->format('%d');
114
							$timediff_inMonth = (string)$timediff->format('%m');
115
							if($timediff_inMonth!=0) {
116
									$timediff = $timediff_inMonth . "m";
117
							}
118
							else
119
							{
120
								if($timediff_inDays!=0)
121
								{
122
									$timediff = $timediff_inDays . "d";
123
								}
124
								else
125
								{
126
									if($timediff_inHours!=0)
127
									{
128
										$timediff = $timediff_inHours . "h";
129
									}
130
									else
131
									{
132
										if($timediff_inMinutes!=0)
133
										{
134
											$timediff = $timediff_inMinutes . "m";
135
										}
136
										else
137
										{
138
											$timediff = $timediff_inSeconds . "s";
139
										}
140
									}
141
								}
142
							}
143
						?>
144
145
				<article id ="postId-<?php echo $posts[$i]["post_id"]; ?>" class="jodel" style="background-color: #<?php echo $posts[$i]["color"];?>;">
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal post_id does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
Coding Style Comprehensibility introduced by
The string literal color does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
This line exceeds maximum limit of 120 characters; contains 139 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
146
					<content>
147
						<?php 
148
						if(isset($posts[$i]["image_url"])) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal image_url does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
149
							echo '<img src="' . $posts[$i]["image_url"] . '">';
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal image_url does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
150
						}
151
						else {
152
							echo str_replace('  ', ' &nbsp;', nl2br(htmlspecialchars($posts[$i]["message"])));
153
						}
154
						?>
155
					</content>
156
					<aside>
157
						<a href="index.php?vote=up&postID=<?php echo $posts[$i]["post_id"];?>">
158
							<i class="fa fa-angle-up fa-3x"></i>
159
						</a>	
160
							<br />
161
						<?php echo $posts[$i]["vote_count"];?><br />
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal vote_count does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
162
						<a href="index.php?vote=down&postID=<?php echo $posts[$i]["post_id"];?>">
163
							<i class="fa fa-angle-down fa-3x"></i>
164
						</a>
165
					</aside>
166
167
					<footer>
168
						<table>
169
							<tr>
170
								<td class="time">
171
									<span data-tooltip="Time">
172
										<i class="fa fa-clock-o"></i>
173
										<?php echo $timediff;?>
174
									</span> 
175
								</td>
176
								<td class="comments">
177
									<?php if($showCommentIcon) {?>
178
									<span data-tooltip="Comments">
179
										<a href="index.php?getPostDetails=true&view=<?php echo $view;?>&postID=<?php echo $posts[$i]["post_id"];?>">
180
											<i class="fa fa-commenting-o"></i>
181
											<?php if(array_key_exists("child_count", $posts[$i])) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal child_count does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
182
														echo $posts[$i]["child_count"];
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal child_count does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
183
													} else echo "0";
184
											?>
185
											</a>
186
									</span>
187
									<?php } ?>
188
								</td>
189
								<td class="distance">
190
									<span data-tooltip="Distance">
191
										<i class="fa fa-map-marker"></i>
192
										<?php echo $posts[$i]["distance"];?> km
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal distance does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
193
									</span>
194
								</td>
195
							</tr>
196
						</table>
197
					</footer>
198
				</article>
199
200
201
202
				<?php 
203
			}
204
		}
205
		?>
206
		</div>
207
		<div class="lastPostId">
208
		<?php echo $lastPostId; ?>
209
		</div>
210
		<?php
211
	}
212