Match   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 0
dl 0
loc 36
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A create() 0 9 3
A formatNamespace() 0 8 2
1
<?php
2
3
namespace Psecio\Invoke;
4
5
class Match
6
{
7
	/**
8
	 * Create a new match instance
9
	 *
10
	 * @param string $type Match type to create (Ex: "user.hasGroup")
11
	 * @param array $config Configuration items
12
	 * @param boolean $negate Reverse the check
13
	 * @throws \InvalidArgumentException If the match type provided is invalid
14
	 * @return \Psecio\Invoke\Match instance
15
	 */
16
	public static function create($type, $config, $negate = false)
17
	{
18
		$typeNs = self::formatNamespace($type);
19
		if (!class_exists($typeNs) === true) {
20
			throw new \InvalidArgumentException('Invalid match type: '.$type);
21
		}
22
		$config = (!is_array($config)) ? array($config) : $config;
23
		return new $typeNs($config, $negate);
24
	}
25
26
	/**
27
	 * Format the namespace for the Match type given
28
	 *
29
	 * @param string $type Match type (ex: "user.hasGroup")
30
	 * @return string Namespaced version of the class for given group
31
	 */
32
	public static function formatNamespace($type)
33
	{
34
		$typeNs = "\\Psecio\\Invoke\\Match";
35
		foreach (explode('.', $type) as $part) {
36
			$typeNs	.= "\\".ucwords($part);
37
		}
38
		return $typeNs;
39
	}
40
}