unit.script.php ➔ searchFiles()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 8
nc 2
nop 2
dl 0
loc 12
rs 9.4285
c 0
b 0
f 0
1
<?php
2
// include wp emulation
3
include('wp-emulator.script.php');
4
5
define('END_TEST', "/^.*\.test\.php$/");
6
7
echo "[+] Starting Unit Tests" . PHP_EOL . PHP_EOL;
8
9
// Search for test files
10
$unitList = searchFiles('.' . DIRECTORY_SEPARATOR, END_TEST);
11
12
// Loop on unitList
13
foreach($unitList as $test)
14
{
15
	echo "[+] Testing -> " . $test . PHP_EOL;
16
	include($test);
17
}
18
19
echo "[+] Unit Tests Finished" . PHP_EOL;
20
21
/* Recursively search files
22
	folder = string => where to search
23
	patter = string => regexp for what to search
24
*/
25
function searchFiles($folder, $pattern)
26
{
27
	$dir = new RecursiveDirectoryIterator($folder);
28
	$ite = new RecursiveIteratorIterator($dir);
29
	$files = new RegexIterator($ite, $pattern, RegexIterator::GET_MATCH);
30
	$fileList = array();
31
	foreach($files as $file)
32
	{
33
		$fileList[] = $file[0];
34
	}
35
	return $fileList;
36
}
37
?>
0 ignored issues
show
Best Practice introduced by
It is not recommended to use PHP's closing tag ?> in files other than templates.

Using a closing tag in PHP files that only contain PHP code is not recommended as you might accidentally add whitespace after the closing tag which would then be output by PHP. This can cause severe problems, for example headers cannot be sent anymore.

A simple precaution is to leave off the closing tag as it is not required, and it also has no negative effects whatsoever.

Loading history...
38