Loader::includeAllFilesFromDirRecursive()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
c 1
b 0
f 0
dl 0
loc 11
ccs 5
cts 5
cp 1
rs 10
cc 4
nc 4
nop 1
crap 4
1
<?php
2
3
namespace ElegantMedia\PHPToolkit;
4
5
class Loader
6
{
7
	/**
8
	 * Include all PHP files from a directory.
9
	 *
10
	 * @param $dirPath
11
	 */
12
	public static function includeAllFilesFromDir($dirPath): void
13
	{
14
		$includedFiles = get_included_files();
15 3
16
		foreach (glob($dirPath . '/*.php') as $filename) {
17 3
			if (!in_array($filename, $includedFiles, true)) {
18
				include_once $filename;
19 3
			}
20 3
		}
21 3
	}
22
23
	/**
24 3
	 * Include all PHP files from a directory, recursively.
25
	 *
26
	 * @param $dirPath
27
	 */
28
	public static function includeAllFilesFromDirRecursive($dirPath): void
29
	{
30
		// include files from current dir
31
		self::includeAllFilesFromDir($dirPath);
32 3
33
		$filtered = [];
34
		foreach (new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($dirPath)) as $file) {
35 3
			if (!in_array($file->getPathname(), get_included_files(), true)) {
36 3
				if ($file->getExtension() === 'php') {
37 3
					$filtered[] = $file;
38 3
					include_once $file->getPathname();
39 3
				}
40 3
			}
41
		}
42
	}
43
}
44