Completed
Push — master ( 3d9a46...2e4cf2 )
by Peter
06:36
created

Roles   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
c 0
b 0
f 0
lcom 1
cbo 1
dl 0
loc 50
ccs 17
cts 17
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 2
B toArray() 0 24 4
1
<?php
2
3
namespace Maslosoft\Mangan\Model\Command;
4
5
/**
6
 * Roles helper model
7
 *
8
 * @author Piotr Maselkowski <pmaselkowski at gmail.com>
9
 */
10
class Roles extends DbCommandModel
11
{
12
13
	public $read = false;
14
	public $readWrite = false;
15
	public $dbAdmin = false;
16
	public $dbOwner = false;
17
	public $userAdmin = false;
18
	public $dbName = '';
19
20
	/**
21
	 *
22
	 * @param string $dbName Database for which roles will be applied
23
	 * @param array $roles
24
	 */
25 1
	public function __construct($dbName = '', $roles = [])
26
	{
27 1
		$this->dbName = $dbName;
28 1
		foreach ($roles as $name)
29
		{
30 1
			$this->$name = true;
31
		}
32 1
	}
33
34 1
	public function toArray($except = [])
35
	{
36 1
		$parent = parent::toArray(['dbName']);
37 1
		$result = [];
38 1
		foreach ($parent as $name => $value)
39
		{
40 1
			if (!$value)
41
			{
42 1
				continue;
43
			}
44 1
			if (!empty($this->dbName))
45
			{
46 1
				$result[] = [
47 1
					'role' => $name,
48 1
					'db' => $this->dbName
49
				];
50
			}
51
			else
52
			{
53 1
				$result[] = $name;
54
			}
55
		}
56 1
		return $result;
57
	}
58
59
}
60