validate_all_present()   A
last analyzed

Complexity

Conditions 6
Paths 4

Size

Total Lines 24
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 13.776

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 11
c 1
b 0
f 0
dl 0
loc 24
ccs 4
cts 10
cp 0.4
rs 9.2222
cc 6
nc 4
nop 0
crap 13.776
1
<?php
2
3
use ElegantMedia\PHPToolkit\Check;
4
5
if (!function_exists('validate_all_present')) {
6
	/**
7
	 * Check all values are !empty
8
	 * Throws an exception if at least one value is empty.
9
	 */
10
	function validate_all_present()
11
	{
12
		$args = func_get_args();
13
14
		if (!Check::allPresent($args)) {
15
			$errorMessage = 'At least one required variable is not present.';
16 15
17
			// show the variable location on the debug mode
18 15
			if (getenv('APP_DEBUG') === 'true') {
19 12
				// show the argument location for easier debugging
20
				$backtrace = debug_backtrace();
21
22 12
				if (isset($backtrace[0])) {
23
					$args = $backtrace[0]['args'];
24
25
					foreach ($args as $i => $iValue) {
26
						if ($iValue === null) {
27
							$errorMessage .= ' Argument ' . ($i + 1) . ' is empty.';
28
						}
29
					}
30
				}
31
			}
32
33
			throw new InvalidArgumentException($errorMessage);
34
		}
35
	}
36
}
37