Completed
Push — master ( 43937d...c78172 )
by Jacob
04:00
created

Header::start_gzipping()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 5
rs 9.4286
cc 2
eloc 3
nc 2
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 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...
7
	{
8
		$array = array(
9
			'HTTP/1.1 200 OK',
10
			'Cache-Control: no-cache',
11
			'Content-Language: en',
12
			'Content-Type: application/json',
13
			'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...
14
			'Last-Modified: ' . self::get_date(),
15
			'X-Powered-By: jacobemerick.com');
16
		self::send($array);
17
	}
18
19 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...
20
	{
21
		$array = array(
22
			'HTTP/1.1 200 OK',
23
			'Cache-Control: no-cache',
24
			'Content-Language: en',
25
			'Content-Type: text/html',
26
			'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...
27
			'Last-Modified: ' . self::get_date(),
28
			'X-Powered-By: jacobemerick.com');
29
		self::send($array);
30
	}
31
32
	public static function redirect($location, $method = 301)
33
	{
34
		header("Location: {$location}", TRUE, $method);
35
		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...
36
	}
37
38 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...
39
	{
40
		$array = array(
41
			'HTTP/1.1 404 Not Found',
42
			'Cache-Control: no-cache',
43
			'Content-Language: en',
44
			'Content-Type: text/html',
45
			'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...
46
			'Last-Modified: ' . self::get_date(),
47
			'X-Powered-By: jacobemerick.com');
48
		self::send($array);
49
	}
50
51 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...
52
	{
53
		$array = array(
54
			'HTTP/1.1 503 Service Unavailable',
55
			'Cache-Control: no-cache',
56
			'Content-Language: en',
57
			'Content-Type: text/html',
58
			'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...
59
			'Last-Modified: ' . self::get_date(),
60
			'X-Powered-By: jacobemerick.com');
61
		self::send($array);
62
	}
63
64
	private static function send($array, $gzip = true)
65
	{
66
		if($gzip)
67
			self::start_gzipping();
68
		
69
		foreach($array as $row)
70
		{
71
			header($row, TRUE);
72
		}
73
	}
74
75
	private static function get_date($timestamp = false)
76
	{
77
		if($timestamp == 0)
78
			$timestamp = time();
79
		return gmdate('D, d M Y H:i:s \G\M\T', $timestamp);
80
	}
81
82
	private static function start_gzipping()
83
	{
84
		if(!ob_start('ob_gzhandler'))
85
            ob_start();
86
	}
87
88
}
89