hasKeyPost()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
nc 1
nop 1
dl 0
loc 3
c 1
b 0
f 0
cc 1
ccs 0
cts 1
cp 0
crap 2
rs 10
1
<?php
2
/**
3
 * Get value from GET variable or return default value.
4
 *
5
 * @param string $key     to look for
6
 * @param mixed  $default value to set if key does not exists
7
 *
8
 * @return mixed value from GET or the default value
9
 */
10
function getGet($key, $default = null)
11
{
12
    return isset($_GET[$key])
13
        ? $_GET[$key]
14
        : $default;
15
}
16
17
18
19
/**
20
 * Get value from POST variable or return default value.
21
 *
22
 * @param string $key     to look for
23
 * @param mixed  $default value to set if key does not exists
24
 *
25
 * @return mixed value from POST or the default value
26
 */
27
function getPost($key, $default = null)
28
{
29
    return isset($_POST[$key])
30
        ? $_POST[$key]
31
        : $default;
32
}
33
34
/**
35
 * Check if key is set in POST.
36
 *
37
 * @param mixed $key     to look for
38
 *
39
 * @return boolean true if key is set, otherwise false
40
 */
41
function hasKeyPost($key)
42
{
43
    return array_key_exists($key, $_POST);
44
}
45
46
47
/**
48
 * Create a slug of a string, to be used as url.
49
 *
50
 * @param string $str the string to format as slug.
51
 *
52
 * @return str the formatted slug.
53
 */
54
function slugify($str)
55
{
56
    $str = mb_strtolower(trim($str));
57
    $str = str_replace(['å','ä'], 'a', $str);
58
    $str = str_replace('ö', 'o', $str);
59
    $str = preg_replace('/[^a-z0-9-]/', '-', $str);
60
    $str = trim(preg_replace('/-+/', '-', $str), '-');
61
    return $str;
62
}
63
64
65
/**
66
 * Sanitize value for output in view.
67
 *
68
 * @param string $value to sanitize
69
 *
70
 * @return string beeing sanitized
71
 */
72
function esc($value)
73
{
74
    return htmlentities($value);
75
}
76