Completed
Push — master ( ac571e...b4d025 )
by Peter
02:07
created

Iterator::ns()   B

Complexity

Conditions 4
Paths 4

Size

Total Lines 26
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 26
rs 8.5806
cc 4
eloc 14
nc 4
nop 1
1
<?php
2
3
/*
4
 * To change this license header, choose License Headers in Project Properties.
5
 * To change this template file, choose Tools | Templates
6
 * and open the template in the editor.
7
 */
8
9
namespace Maslosoft\Zamm;
10
11
/**
12
 * Iterator
13
 *
14
 * @author Piotr Maselkowski <pmaselkowski at gmail.com>
15
 */
16
class Iterator
17
{
18
19
	/**
20
	 * Iterate over classes in same folder.
21
	 * @param string $class
22
	 */
23
	public static function ns($class)
24
	{
25
		$info = new \ReflectionClass($class);
26
		$path = dirname($info->getFileName());
27
		$ns = $info->getNamespaceName();
28
		$classNames = [];
29
		foreach (new \DirectoryIterator($path) as $fileInfo)
30
		{
31
			$name = $fileInfo->getFilename();
32
33
			// Only files
34
			if (!$fileInfo->isFile())
35
			{
36
				continue;
37
			}
38
39
			// Only php
40
			if (!preg_match('~\.php$~', $name))
41
			{
42
				continue;
43
			}
44
			$classNames[] = sprintf('%s\%s', $ns, basename($name, '.php'));
45
		}
46
		sort($classNames);
47
		return $classNames;
48
	}
49
50
}
51