GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Branch master (78924a)
by w3l
18:01 queued 01:54
created

holt45.php (15 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
2
class holt45 {
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
3
	/**
4
	 * Check $_GET
5
	 *
6
	 * @example if(chk_get("s") == "a") instead of if(isset($_GET["s"]) && $_GET["s"] == "a")
7
	 *
8
	 * @param string $key Get-key...
9
	 * @return bool
10
	 */
11
	function chk_get($key) {
0 ignored issues
show
chk_get uses the super-global variable $_GET which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
12
		if (!isset($_GET[$key])) {
13
			return false;
14
		}
15
		return $_GET[$key];
16
	}
17
18
	/**
19
	 * Check $_POST
20
	 *
21
	 * @example if(chk_post("s") == "a") instead of if(isset($_POST["s"]) && $_POST["s"] == "a")
22
	 *
23
	 * @param string $key Post-key...
24
	 * @return bool
25
	 */
26
	function chk_post($key) {
0 ignored issues
show
chk_post uses the super-global variable $_POST which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
27
		if (!isset($_POST[$key])) {
28
			return false;
29
		}
30
		return $_POST[$key];
31
	}
32
33
	/**
34
	 * Check multiple $_GET-keys
35
	 *
36
	 * @example if(chk_get_all(array("a","b"))) instead of if(!empty($_GET["a"]) && !empty($_GET["b"]))
37
	 */
38 View Code Duplication
	function chk_get_all($keys) {
0 ignored issues
show
chk_get_all uses the super-global variable $_GET which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
39
		$s = true;
40
41
		foreach($keys AS $key) {
42
		
43
			if (empty($_GET[$key])) {
44
				$s = false;
45
			}
46
		}
47
		return $s;
48
	}
49
50
	/**
51
	 * Check multiple $_POST-keys
52
	 *
53
	 * @example if(chk_post_all(array("a","b"))) instead of if(!empty($_POST["a"]) && !empty($_POST["b"]))
54
	 */
55 View Code Duplication
	function chk_post_all($keys) {
0 ignored issues
show
chk_post_all uses the super-global variable $_POST which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
56
		$s = true;
57
58
		foreach($keys AS $key) {
59
		
60
			if (empty($_POST[$key])) {
61
				$s = false;
62
			}
63
		}
64
		return $s;
65
	}
66
67
	/**
68
	 * Convert timestamp to HTTP-date (RFC2616)
69
	 *
70
	 * For use in "Last-Modified" headers.
71
	 */
72
	function timestamp_to_http_date($timestamp) {
0 ignored issues
show
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
73
		if($timestamp == NULL) { return NULL; }
74
		return gmdate("D, d M Y H:i:s T", strtotime($timestamp));
75
	}
76
77
	/**
78
	 * Get client ip-address
79
	 *
80
	 * @return string User ip-address
81
	 */
82
	function get_client_ip_address() {
0 ignored issues
show
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
83
84
		if (getenv('HTTP_CLIENT_IP'))
85
			return getenv('HTTP_CLIENT_IP');
86
		else if(getenv('HTTP_X_FORWARDED_FOR'))
87
			return getenv('HTTP_X_FORWARDED_FOR');
88
		else if(getenv('HTTP_X_FORWARDED'))
89
			return getenv('HTTP_X_FORWARDED');
90
		else if(getenv('HTTP_FORWARDED_FOR'))
91
			return getenv('HTTP_FORWARDED_FOR');
92
		else if(getenv('HTTP_FORWARDED'))
93
			return getenv('HTTP_FORWARDED');
94
		else if(getenv('REMOTE_ADDR'))
95
			return getenv('REMOTE_ADDR');
96
		else
97
			return '127.0.0.1'; // Unknown IP
98
	}
99
100
	/**
101
	 * parse url, try to correct errors and return valid url + display-url.
102
	 *
103
	 * @example http:/wwww.example.com/lorum.html => http://www.example.com/lorum.html
104
	 * @example gopher:/ww.example.com => gopher://www.example.com
105
	 * @example http:/www3.example.com/?q=asd&f=#asd =>http://www3.example.com/?q=asd&f=#asd
106
	 * @example asd://.example.com/folder/folder/ =>http://example.com/folder/folder/
107
	 * @example .example.com/ => http://example.com/
108
	 * @example example.com =>http://example.com
109
	 * @example subdomain.example.com => http://subdomain.example.com
110
	 *
111
	 * @param string $url Any somewhat valid url.
112
	 * @return string[] "url" contains an auto-corrected url. "url_display" host.tld or subdomain.host.tld
0 ignored issues
show
Should the return type not be array<string,string>?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
113
	 */
114
	function url_parser($url) {
0 ignored issues
show
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
115
		
116
		// multiple /// messes up parse_url, replace 3 or more with 2
117
		$url = preg_replace('/(\/{2,})/','//',$url);
118
		
119
		$parse_url = parse_url($url);
120
		
121
		if(empty($parse_url["scheme"])) {
122
			$parse_url["scheme"] = "http";
123
		}
124
		if(empty($parse_url["host"]) && !empty($parse_url["path"])) {
125
			// Strip slash from the beginning of path
126
			$parse_url["host"] = ltrim($parse_url["path"], '\/');
127
			$parse_url["path"] = "";
128
		}
129
130
		$url_array = array("url" => "", "url_display" => "");
131
		
132
		// Check if scheme is correct
133
		if(!in_array($parse_url["scheme"], array("http", "https", "gopher"))) {
134
			$url_array["url"] .= 'http'.'://';
135
		} else {
136
			$url_array["url"] .= $parse_url["scheme"].'://';
137
		}
138
		
139
		// Check if the right amount of "www" is set.
140
		$explode_host = explode(".", $parse_url["host"]);
141
		
142
		// Remove empty entries
143
		$explode_host = array_filter($explode_host);
144
		// And reassign indexes
145
		$explode_host = array_values($explode_host);
146
		
147
		// Contains subdomain
148
		if(count($explode_host) > 2) {
149
			// Check if subdomain only contains the letter w(then not any other subdomain).
150
			if(substr_count($explode_host[0], 'w') == strlen($explode_host[0])) {
151
				// Replace with "www" to avoid "ww" or "wwww", etc.
152
				$explode_host[0] = "www";
153
				
154
			}
155
		}
156
157
		$url_array["url"] .= implode(".",$explode_host);
158
		$url_array["url_display"] = trim(implode(".",$explode_host), '\/'); // Removes trailing slash
159
		
160
		if(!empty($parse_url["port"])) {
161
			$url_array["url"] .= ":".$parse_url["port"];
162
		}
163
		if(!empty($parse_url["path"])) {
164
			$url_array["url"] .= $parse_url["path"];
165
		}
166
		if(!empty($parse_url["query"])) {
167
			$url_array["url"] .= '?'.$parse_url["query"];
168
		}
169
		if(!empty($parse_url["fragment"])) {
170
			$url_array["url"] .= '#'.$parse_url["fragment"];
171
		}
172
173
		
174
		return $url_array;
175
	}
176
}