Completed
Push — master ( c2cfef...1a5a57 )
by Angus
02:24
created

generic_helper.php ➔ exit_ci()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 2.1481

Importance

Changes 0
Metric Value
cc 2
eloc 5
nc 2
nop 1
dl 0
loc 7
ccs 2
cts 3
cp 0.6667
crap 2.1481
rs 9.4285
c 0
b 0
f 0
1
<?php declare(strict_types=1); defined('BASEPATH') or exit('No direct script access allowed');
2
3
/**
4
 * Checks if view file exists.
5
 * @param string $path Location of view file. Use without /views/ & .php
6
 * @return bool
7
 */
8
function view_exists(string $path) : bool {
9 23
	return file_exists(APPPATH . "/views/{$path}.php");
10
}
11
12
function get_time_class(string $time_string) : string {
13 4
	$time = strtotime($time_string);
14
15 4
	if(is_int($time)) {
16 3
		if($time < TIMEAGO_MONTH) {
17
			//More than a month old.
18 1
			$time_string = "sprite-month";
19 2
		} elseif($time < TIMEAGO_WEEK) {
20
			//More than a week old, but less than a month old.
21 1
			$time_string = "sprite-week";
22 1
		} elseif($time < TIMEAGO_3DAY) {
23
			//More than 3 days old but less than a week old.
24
			$time_string = "sprite-3day";
25
		} else {
26
			//Less than a week old.
27 1
			$time_string = "sprite-day";
28
		}
29
	} else {
30 1
		$time_string = "sprite-error";
31
	}
32 4
	return $time_string;
33
}
34
35
if (!function_exists('http_parse_headers')) { #http://www.php.net/manual/en/function.http-parse-headers.php#112917
36
	function http_parse_headers (string $raw_headers) : array {
37
		$headers = array(); // $headers = [];
38
		foreach (explode("\n", $raw_headers) as $i => $h) {
39
			$h = explode(':', $h, 2);
40
			if (isset($h[1])){
41
				if(!isset($headers[$h[0]])){
42
					$headers[$h[0]] = trim($h[1]);
43
				}else if(is_array($headers[$h[0]])){
44
					$tmp = array_merge($headers[$h[0]],array(trim($h[1])));
45
					$headers[$h[0]] = $tmp;
46
				}else{
47
					$tmp = array_merge(array($headers[$h[0]]),array(trim($h[1])));
48
					$headers[$h[0]] = $tmp;
49
				}
50
			}
51
		}
52
		return $headers;
53
	}
54
}
55
56
function exit_ci($status = NULL) : void {
57 6
	if(ENVIRONMENT !== "testing") {
58
		exit($status);
59
	} else {
60 6
		throw new CIPHPUnitTestExitException("exit() called");
61
	}
62
}
63