Finder::findFromString()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
dl 0
loc 16
ccs 0
cts 14
cp 0
rs 9.7333
c 0
b 0
f 0
cc 3
nc 4
nop 3
crap 12
1
<?php
2
3
namespace PHPSemVerChecker\Finder;
4
5
use Finder\Adapter\SymfonyFinder as BaseFinder;
6
7
class Finder
8
{
9
	/**
10
	 * @param string $path
11
	 * @param array  $includes
12
	 * @param array  $excludes
13
	 * @return array
14
	 */
15
	public function find($path, array $includes, array $excludes = [])
16
	{
17
		$finder = new BaseFinder();
18
		$finder->ignoreDotFiles(true)
19
			->files()
20
			->name('*.php')
21
			->in($path);
22
23
		foreach ($includes as $include) {
24
			$finder->path($include);
25
		}
26
27
		foreach ($excludes as $exclude) {
28
			$finder->notPath($exclude);
29
		}
30
31
		$files = [];
32
		foreach ($finder as $file) {
33
			$files[] = $file->getRealpath();
34
		}
35
36
		return $files;
37
	}
38
39
	/**
40
	 * @param string $path
41
	 * @param string $includes
42
	 * @param string $excludes
43
	 * @return array
44
	 */
45
	public function findFromString($path, $includes, $excludes)
46
	{
47
		if ($includes === '*') {
48
			$includes = [];
49
		} else {
50
			$includes = preg_split('@(?:\s*,\s*|^\s*|\s*$)@', $includes, null, PREG_SPLIT_NO_EMPTY);
51
		}
52
53
		if ($excludes === '*') {
54
			$excludes = [];
55
		} else {
56
			$excludes = preg_split('@(?:\s*,\s*|^\s*|\s*$)@', $excludes, null, PREG_SPLIT_NO_EMPTY);
57
		}
58
59
		return $this->find($path, $includes, $excludes);
60
	}
61
}
62