Completed
Push — master ( 44b14d...d54457 )
by Peter
05:23
created

Roles   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 94.12%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 2
A toArray() 0 24 4
1
<?php
2
3
/**
4
 * This software package is licensed under AGPL or Commercial license.
5
 *
6
 * @package maslosoft/mangan
7
 * @licence AGPL or Commercial
8
 * @copyright Copyright (c) Piotr Masełkowski <[email protected]>
9
 * @copyright Copyright (c) Maslosoft
10
 * @copyright Copyright (c) Others as mentioned in code
11
 * @link https://maslosoft.com/mangan/
12
 */
13
14
namespace Maslosoft\Mangan\Model\Command;
15
16
/**
17
 * Roles helper model
18
 *
19
 * @author Piotr Maselkowski <pmaselkowski at gmail.com>
20
 */
21
class Roles extends DbCommandModel
22
{
23
24
	public $read = false;
25
	public $readWrite = false;
26
	public $dbAdmin = false;
27
	public $dbOwner = false;
28
	public $userAdmin = false;
29
	public $dbName = '';
30
31
	/**
32
	 *
33
	 * @param string $dbName Database for which roles will be applied
34
	 * @param array $roles
35
	 */
36 1
	public function __construct($dbName = '', $roles = [])
37
	{
38 1
		$this->dbName = $dbName;
39 1
		foreach ($roles as $name)
40
		{
41 1
			$this->$name = true;
42
		}
43 1
	}
44
45 1
	public function toArray($except = [])
46
	{
47 1
		$parent = parent::toArray(['dbName']);
48 1
		$result = [];
49 1
		foreach ($parent as $name => $value)
50
		{
51 1
			if (!$value)
52
			{
53 1
				continue;
54
			}
55 1
			if (!empty($this->dbName))
56
			{
57 1
				$result[] = [
58 1
					'role' => $name,
59 1
					'db' => $this->dbName
60
				];
61
			}
62
			else
63
			{
64
				$result[] = $name;
65
			}
66
		}
67 1
		return $result;
68
	}
69
70
}
71