Completed
Push — master ( c6b670...d43e8c )
by Peter
04:50
created

Iterator::methods()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 6
nc 2
nop 1
1
<?php
2
3
/**
4
 * This software package is licensed under `AGPL, Commercial` license[s].
5
 *
6
 * @package maslosoft/zamm
7
 * @license AGPL, Commercial
8
 *
9
 * @copyright Copyright (c) Peter Maselkowski <[email protected]>
10
 *
11
 */
12
13
namespace Maslosoft\Zamm;
14
15
use DirectoryIterator;
16
use ReflectionClass;
17
use ReflectionProperty;
18
19
/**
20
 * Iterator
21
 *
22
 * @author Piotr Maselkowski <pmaselkowski at gmail.com>
23
 */
24
class Iterator
25
{
26
27
	/**
28
	 * Iterate over classes in same folder.
29
	 * @param string $class
30
	 * @return string[]
31
	 */
32
	public static function ns($class)
33
	{
34
		$info = new ReflectionClass($class);
35
		$path = dirname($info->getFileName());
36
		$ns = $info->getNamespaceName();
37
		$classNames = [];
38
		foreach (new DirectoryIterator($path) as $fileInfo)
39
		{
40
			$name = $fileInfo->getFilename();
41
42
			// Only files
43
			if (!$fileInfo->isFile())
44
			{
45
				continue;
46
			}
47
48
			// Only php
49
			if (!preg_match('~\.php$~', $name))
50
			{
51
				continue;
52
			}
53
			$classNames[] = sprintf('%s\%s', $ns, basename($name, '.php'));
54
		}
55
		sort($classNames);
56
		return $classNames;
57
	}
58
59
	/**
60
	 * Iterate over *public* class methods
61
	 * @param string $class
62
	 * @return string[]
63
	 */
64
	public static function methods($class)
65
	{
66
		$info = new ReflectionClass($class);
67
68
		$methods = [];
69
		foreach ($info->getMethods(ReflectionProperty::IS_PUBLIC) as $method)
70
		{
71
			$methods[] = $method->name;
72
		}
73
		return $methods;
74
	}
75
76
}
77