Completed
Push — master ( 7e42fe...9ab714 )
by Jacob
04:00
created

Header::send503()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 10

Duplication

Lines 12
Ratio 100 %
Metric Value
dl 12
loc 12
rs 9.4286
cc 1
eloc 10
nc 1
nop 0
1
<?
0 ignored issues
show
Security Best Practice introduced by
It is not recommend to use PHP's short opening tag <?, better use <?php, or <?= in case of outputting.

Short opening tags are disabled in PHP’s default configuration. In such a case, all content of this file is output verbatim to the browser without being parsed, or executed.

As a precaution to avoid these problems better use the long opening tag <?php.

Loading history...
2
3
final class Header
4
{
5
6
	private static $CACHE_EXPIRATION = 315360000;
7
	private static $CACHE_MODIFICATION = 604800;
0 ignored issues
show
Unused Code introduced by
The property $CACHE_MODIFICATION is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
8
	private static $SITEMAP_EXPIRATION = 604800;
9
	private static $RSS_EXPIRATION = 604800;
10
11 View Code Duplication
	public static function sendGIF($timestamp)
0 ignored issues
show
Duplication introduced by
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...
12
	{
13
		$array = array(
14
			'HTTP/1.1 200 OK',
15
			'Cache-Control: max-age=' . self::$CACHE_EXPIRATION . ', must-revalidate',
16
			'Content-Language: en',
17
			'Content-Type: image/gif',
18
			'Expires: ' . self::get_date(time() + self::$CACHE_EXPIRATION),
0 ignored issues
show
Documentation introduced by
time() + self::$CACHE_EXPIRATION is of type integer, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
19
			'Last-Modified: ' . self::get_date($timestamp),
20
			'X-Powered-By: jacobemerick.com');
21
		self::send($array);
22
	}
23
24 View Code Duplication
	public static function sendJPG($timestamp)
0 ignored issues
show
Duplication introduced by
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...
25
	{
26
		$array = array(
27
			'HTTP/1.1 200 OK',
28
			'Cache-Control: max-age=' . self::$CACHE_EXPIRATION . ', must-revalidate',
29
			'Content-Language: en',
30
			'Content-Type: image/jpeg',
31
			'Expires: ' . self::get_date(time() + self::$CACHE_EXPIRATION),
0 ignored issues
show
Documentation introduced by
time() + self::$CACHE_EXPIRATION is of type integer, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
32
			'Last-Modified: ' . self::get_date($timestamp),
33
			'X-Powered-By: jacobemerick.com');
34
		self::send($array);
35
	}
36
37 View Code Duplication
	public static function sendPNG($timestamp)
0 ignored issues
show
Duplication introduced by
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...
38
	{
39
		$array = array(
40
			'HTTP/1.1 200 OK',
41
			'Cache-Control: max-age=' . self::$CACHE_EXPIRATION . ', must-revalidate',
42
			'Content-Language: en',
43
			'Content-Type: image/png',
44
			'Expires: ' . self::get_date(time() + self::$CACHE_EXPIRATION),
0 ignored issues
show
Documentation introduced by
time() + self::$CACHE_EXPIRATION is of type integer, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
45
			'Last-Modified: ' . self::get_date($timestamp),
46
			'X-Powered-By: jacobemerick.com');
47
		self::send($array);
48
	}
49
50 View Code Duplication
	public static function sendJSON()
0 ignored issues
show
Duplication introduced by
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...
51
	{
52
		$array = array(
53
			'HTTP/1.1 200 OK',
54
			'Cache-Control: no-cache',
55
			'Content-Language: en',
56
			'Content-Type: application/json',
57
			'Expires: ' . self::get_date(time() - 1),
0 ignored issues
show
Documentation introduced by
time() - 1 is of type integer, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
58
			'Last-Modified: ' . self::get_date(),
59
			'X-Powered-By: jacobemerick.com');
60
		self::send($array);
61
	}
62
63 View Code Duplication
	public static function sendSitemap()
0 ignored issues
show
Duplication introduced by
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...
64
	{
65
		$array = array(
66
			'HTTP/1.1 200 OK',
67
			'Cache-Control: max-age=' . self::$SITEMAP_EXPIRATION . ', must-revalidate',
68
			'Content-Language: en',
69
			'Content-Type: text/xml',
70
			'Expires: ' . self::get_date(time() + self::$SITEMAP_EXPIRATION),
0 ignored issues
show
Documentation introduced by
time() + self::$SITEMAP_EXPIRATION is of type integer, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
71
			'Last-Modified: ' . self::get_date(),
72
			'X-Powered-By: jacobemerick.com');
73
		self::send($array);
74
	}
75
76 View Code Duplication
	public static function sendRSS()
0 ignored issues
show
Duplication introduced by
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...
77
	{
78
		$array = array(
79
			'HTTP/1.1 200 OK',
80
			'Cache-Control: max-age=' . self::$RSS_EXPIRATION . ', must-revalidate',
81
			'Content-Language: en',
82
			'Content-Type: application/rss+xml',
83
			'Expires: ' . self::get_date(time() + self::$RSS_EXPIRATION),
0 ignored issues
show
Documentation introduced by
time() + self::$RSS_EXPIRATION is of type integer, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
84
			'Last-Modified: ' . self::get_date(),
85
			'X-Powered-By: jacobemerick.com');
86
		self::send($array);
87
	}
88
89 View Code Duplication
	public static function sendHTML()
0 ignored issues
show
Duplication introduced by
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...
90
	{
91
		$array = array(
92
			'HTTP/1.1 200 OK',
93
			'Cache-Control: no-cache',
94
			'Content-Language: en',
95
			'Content-Type: text/html',
96
			'Expires: ' . self::get_date(time() - 1),
0 ignored issues
show
Documentation introduced by
time() - 1 is of type integer, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
97
			'Last-Modified: ' . self::get_date(),
98
			'X-Powered-By: jacobemerick.com');
99
		self::send($array);
100
	}
101
102
	public static function redirect($location, $method = 301)
103
	{
104
		header("Location: {$location}", TRUE, $method);
105
		exit();
0 ignored issues
show
Coding Style Compatibility introduced by
The method redirect() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
106
	}
107
108 View Code Duplication
	public static function send404()
0 ignored issues
show
Duplication introduced by
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...
109
	{
110
		$array = array(
111
			'HTTP/1.1 404 Not Found',
112
			'Cache-Control: no-cache',
113
			'Content-Language: en',
114
			'Content-Type: text/html',
115
			'Expires: ' . self::get_date(time() - 1),
0 ignored issues
show
Documentation introduced by
time() - 1 is of type integer, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
116
			'Last-Modified: ' . self::get_date(),
117
			'X-Powered-By: jacobemerick.com');
118
		self::send($array);
119
	}
120
121 View Code Duplication
	public static function send503()
0 ignored issues
show
Duplication introduced by
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...
122
	{
123
		$array = array(
124
			'HTTP/1.1 503 Service Unavailable',
125
			'Cache-Control: no-cache',
126
			'Content-Language: en',
127
			'Content-Type: text/html',
128
			'Expires: ' . self::get_date(time() - 1),
0 ignored issues
show
Documentation introduced by
time() - 1 is of type integer, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
129
			'Last-Modified: ' . self::get_date(),
130
			'X-Powered-By: jacobemerick.com');
131
		self::send($array);
132
	}
133
134
	private static function send($array, $gzip = true)
135
	{
136
		if($gzip)
137
			self::start_gzipping();
138
		
139
		foreach($array as $row)
140
		{
141
			header($row, TRUE);
142
		}
143
	}
144
145
	private static function get_date($timestamp = false)
146
	{
147
		if($timestamp == 0)
148
			$timestamp = time();
149
		return gmdate('D, d M Y H:i:s \G\M\T', $timestamp);
150
	}
151
152
	private static function start_gzipping()
153
	{
154
		if(!ob_start('ob_gzhandler'))
155
            ob_start();
156
	}
157
158
}
159