Passed
Push — master ( f5ec54...94ecb9 )
by Fabio
05:41
created

TPermissionsConfigurationBehavior::getPermissionsManager()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * TPermissionsConfigurationBehavior class file.
4
 *
5
 * @author Brad Anderson <[email protected]>
6
 * @link https://github.com/pradosoft/prado
7
 * @license https://github.com/pradosoft/prado/blob/master/LICENSE
8
 */
9
10
namespace Prado\Security\Permissions;
11
12
use Prado\Util\TBehavior;
13
14
/**
15
 * TPermissionsConfigurationBehavior class.
16
 *
17
 * TPermissionsConfigurationBehavior is designed specifically to attach to the
18
 * {@link TPageConfiguration} class objects.  It reads and parses the
19
 * permissions role hierarchy and permissions rules from a page configuration
20
 * file.  Within the config.xml for a page, for example, add the following:
21
 * <code>
22
 * 		<permissions>
23
 *			<role name="pageRole" children="otherRole, permission_name" />
24
 *			<permissionrule name="permission_name" action="allow" roles="manager"/>
25
 *		</permissions>
26
 * </code>
27
 *
28
 * See <@link TPermissionsManager> for information on php configurations.
29
 *
30
 * @author Brad Anderson <[email protected]>
31
 * @since 4.2.0
32
 */
33
class TPermissionsConfigurationBehavior extends TBehavior
34
{
35
	use TPermissionsManagerPropertyTrait;
36
37
	/** @var array|\Prado\Xml\TXmlElement permissions data to parse */
38
	private $_permissions = [];
39
40
	/**
41
	 * Loads the configuration specific for page service. This may be called multiple
42
	 * times.
43
	 * @param array $config config array
44
	 * @param string $configPath base path corresponding to this php element
45
	 * @param string $configPagePath the page path that the config php is associated with. The page path doesn't include the page name.
46
	 * @param \Prado\Util\TCallChain $callchain
47
	 */
48
	public function dyLoadPageConfigurationFromPhp($config, $configPath, $configPagePath, $callchain)
49
	{
50
		// authorization
51
		if (isset($config['permissions']) && is_array($config['permissions'])) {
52
			$this->_permissions[] = $config['permissions'];
53
		}
54
		return $callchain->dyLoadPageConfigurationFromPhp($config, $configPath, $configPagePath);
0 ignored issues
show
Bug introduced by
The method dyLoadPageConfigurationFromPhp() does not exist on Prado\Util\TCallChain. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

54
		return $callchain->/** @scrutinizer ignore-call */ dyLoadPageConfigurationFromPhp($config, $configPath, $configPagePath);
Loading history...
55
	}
56
57
	/**
58
	 * Loads the configuration specific for page service. This may be called multiple
59
	 * times.
60
	 * @param \Prado\Xml\TXmlElement $dom config xml element
61
	 * @param string $configPath base path corresponding to this xml element
62
	 * @param string $configPagePath the page path that the config XML is associated with. The page path doesn't include the page name.
63
	 * @param \Prado\Util\TCallChain $callchain
64
	 */
65
	public function dyLoadPageConfigurationFromXml($dom, $configPath, $configPagePath, $callchain)
66
	{
67
		// authorization
68
		if (($permissionsNode = $dom->getElementByTagName('permissions')) !== null) {
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $permissionsNode is correct as $dom->getElementByTagName('permissions') targeting Prado\Xml\TXmlElement::getElementByTagName() seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
introduced by
The condition $permissionsNode = $dom-...'permissions') !== null is always false.
Loading history...
69
			$this->_permissions[] = $permissionsNode;
70
		}
71
		return $callchain->dyLoadPageConfigurationFromXml($dom, $configPath, $configPagePath);
0 ignored issues
show
Bug introduced by
The method dyLoadPageConfigurationFromXml() does not exist on Prado\Util\TCallChain. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

71
		return $callchain->/** @scrutinizer ignore-call */ dyLoadPageConfigurationFromXml($dom, $configPath, $configPagePath);
Loading history...
72
	}
73
74
	/**
75
	 * Applies the permissions hierarchy and permission rules
76
	 * @param \Prado\Util\TCallChain $callchain
77
	 */
78
	public function dyApplyConfiguration($callchain)
79
	{
80
		$manager = $this->getPermissionsManager();
81
		foreach ($this->_permissions as $permission) {
82
			$manager->loadPermissionsData($permission);
83
		}
84
		return $callchain->dyApplyConfiguration();
0 ignored issues
show
Bug introduced by
The method dyApplyConfiguration() does not exist on Prado\Util\TCallChain. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

84
		return $callchain->/** @scrutinizer ignore-call */ dyApplyConfiguration();
Loading history...
85
	}
86
}
87