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

Roles::toArray()   B

Complexity

Conditions 4
Paths 4

Size

Total Lines 24
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 4

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 24
ccs 12
cts 12
cp 1
rs 8.6845
cc 4
eloc 13
nc 4
nop 1
crap 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