Completed
Pull Request — master (#42)
by
unknown
03:15
created

General.php ➔ ifSetOr()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 2
eloc 4
c 1
b 0
f 1
nc 2
nop 2
dl 0
loc 7
ccs 3
cts 3
cp 1
crap 2
rs 9.4285
1
<?php
2
3
namespace Funct;
4
5
/**
6
 * Checks if the given key or index exists in the array
7
 *
8
 *
9
 * @param mixed $key
10
 * @param array $array
11
 *
12
 * @return bool
13
 * @author Aurimas Niekis <[email protected]>
14
 */
15
function arrayKeyNotExists($key, array $array)
16
{
17 1
    return false === array_key_exists($key, $array);
18
}
19
20
/**
21
 * Returns true if value is false
22
 *
23
 * @param mixed $value
24
 *
25
 * @return bool
26
 * @author Aurimas Niekis <[email protected]>
27
 */
28
function false($value)
29
{
30 2
    return false === $value;
31
}
32
33
/**
34
 * Returns a first non null value from function arguments
35
 *
36
 * @param mixed $valueA
37
 *
38
 * @return mixed
39
 * @author Aurimas Niekis <[email protected]>
40
 */
41
function firstValue($valueA)
0 ignored issues
show
Unused Code introduced by
The parameter $valueA is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
42
{
43 4
    foreach (func_get_args() as $arg) {
44 4
        if (null !== $arg) {
45 3
            return $arg;
46
        }
47 2
    }
48 1
}
49
50
/**
51
 * Returns a first not empty value from function arguments
52
 *
53
 * @param mixed $valueA
54
 * @param mixed $valueB
55
 *
56
 * @return mixed
57
 * @author Aurimas Niekis <[email protected]>
58
 */
59
function firstValueNotEmpty($valueA, $valueB)
0 ignored issues
show
Unused Code introduced by
The parameter $valueA is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $valueB is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
60
{
61 4
    foreach (func_get_args() as $arg) {
62 4
        if (notEmpty($arg)) {
63 3
            return $arg;
64
        }
65 3
    }
66 1
}
67
68
/**
69
 * Returns true if var is not empty
70
 *
71
 * @param mixed $value
72
 *
73
 * @return bool
74
 * @author Aurimas Niekis <[email protected]>
75
 */
76
function notEmpty($value)
77
{
78 7
    return false === empty($value);
79
}
80
81
/**
82
 * Checks if needle is not in array
83
 *
84
 * @param      $needle
85
 * @param      $haystack
86
 * @param null $strict
87
 *
88
 * @return bool
89
 * @author Aurimas Niekis <[email protected]>
90
 */
91
function notInArray($needle, $haystack, $strict = null)
92
{
93 1
    return false === in_array($needle, $haystack, $strict);
94
}
95
96
/**
97
 * Returns true if var is not null
98
 *
99
 * @param mixed $value
100
 *
101
 * @return bool
102
 * @author Aurimas Niekis <[email protected]>
103
 */
104
function notNull($value)
105
{
106 2
    return null !== $value;
107
}
108
109
/**
110
 * Returns true if value is null
111
 *
112
 * @param mixed $value
113
 *
114
 * @return bool
115
 * @author Aurimas Niekis <[email protected]>
116
 */
117
function null($value)
118
{
119 2
    return null === $value;
120
}
121
122
/**
123
 * Generates temp file on systems temp folder with prefix
124
 *
125
 * @param string $prefix
126
 *
127
 * @return string
128
 * @author Aurimas Niekis <[email protected]>
129
 */
130
function tempFile($prefix = 'php')
131
{
132 2
    return tempnam(sys_get_temp_dir(), $prefix);
133
}
134
135
/**
136
 * Returns true if value is true
137
 *
138
 * @param mixed $value
139
 *
140
 * @return bool
141
 * @author Aurimas Niekis <[email protected]>
142
 */
143
function true($value)
144
{
145 2
    return true === $value;
146
}
147
148
/**
149
 * Returns the first param if isset or the second one or null if it doesn't
150
 * 
151
 * @param mixed $value
152
 * @param mixed $default
153
 * @return mixed
154
 * @author Christophe Jean <[email protected]>
155
 */
156
function ifSetOr(&$value, $default = null)
157
{
158 2
    if (isset($value)) {
159 1
        return $value;
160
    }
161 1
    return $default;
162
}
163