Completed
Branch user-caps-n-site-permissions (6f6d8f)
by
unknown
41:20 queued 31:50
created

Capabilities   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 31
rs 10
c 0
b 0
f 0
wmc 4
lcom 0
cbo 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A initialize() 0 12 3
1
<?php
2
3
namespace EventEspresso\core\domain\entities\routing\data_nodes\core;
4
5
use EventEspresso\core\services\json\JsonDataNode;
6
use EventEspresso\core\services\json\JsonDataNodeValidator;
7
8
class Capabilities extends JsonDataNode
9
{
10
    const NODE_NAME = 'capabilities';
11
12
13
    /**
14
     * @param JsonDataNodeValidator $validator
15
     */
16
    public function __construct(JsonDataNodeValidator $validator)
17
    {
18
        parent::__construct($validator);
19
        $this->setNodeName(Capabilities::NODE_NAME);
20
    }
21
22
23
    /**
24
     * @inheritDoc
25
     */
26
    public function initialize()
27
    {
28
        $current_user      = wp_get_current_user();
29
        $capabilities      = [];
30
        $role_capabilities = $current_user->get_role_caps();
31
        foreach ($role_capabilities as $capability => $you_can_do_it) {
32
            if ($you_can_do_it) {
33
                $capabilities[] = $capability;
34
            }
35
        }
36
        $this->setDataArray($capabilities);
37
    }
38
}
39