ModuleJoint   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 24
dl 0
loc 68
rs 10
c 0
b 0
f 0
wmc 7

4 Methods

Rating   Name   Duplication   Size   Complexity  
A list() 0 10 1
A moduleJoints() 0 8 2
A collect() 0 13 3
A register() 0 3 1
1
<?php 
2
3
namespace Epesi\Core\System\Modules;
4
5
use Illuminate\Support\Collection;
6
7
abstract class ModuleJoint
8
{
9
	use Concerns\HasLinks;
10
	use Concerns\HasAccessControl;
11
	use Concerns\HasPackageManifest;
12
13
	/**
14
	 * List of runtime registered joints
15
	 * Can be used for tesing purposes
16
	 * 
17
	 * @var array
18
	 */
19
	protected static $registry = [];
20
	
21
	/**
22
	 * 	Make all joints which are applicable to static class and user has access to
23
	 *
24
	 * @return 	Collection
25
	 */
26
	final public static function collect()
27
	{
28
		$ret = collect();
29
		foreach (self::list() as $class) {
30
			/** @var ModuleJoint $joint */
31
			$joint = new $class();
32
33
			if ($joint->access()) {
34
				$ret->add($joint);
35
			}
36
		}
37
		
38
		return $ret;
39
	}
40
		
41
	/**
42
	 * List all registered joints which are subclasses of static
43
	 */
44
	final public static function list()
45
	{
46
		$joints = collect(config('epesi.joints'))
47
			->merge(self::packageManifest()->joints())
48
			->merge(self::moduleJoints())
49
			->merge(self::$registry)
50
			->unique();
51
			
52
		return $joints->filter(function($class) {
53
			return is_a($class, static::class, true);
54
		});
55
	}
56
	
57
	/**
58
	 * Collect all joints declared in the modules and return array
59
	 *
60
	 * @return array
61
	 */
62
	final public static function moduleJoints()
63
	{
64
		$ret = collect();
65
		foreach (ModuleManager::getInstalled() as $module) {
66
			$ret = $ret->merge($module::joints());
67
		}
68
69
		return $ret->all();
70
	}
71
	
72
	final public static function register($class)
73
	{
74
		self::$registry[] = $class;
75
	}
76
}