Completed
Push — master ( 8cd050...5f288c )
by Andreas
22:58
created

componentPass   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 70
Duplicated Lines 0 %

Test Coverage

Coverage 96.67%

Importance

Changes 0
Metric Value
eloc 31
c 0
b 0
f 0
dl 0
loc 70
ccs 29
cts 30
cp 0.9667
rs 10
wmc 12

3 Methods

Rating   Name   Duplication   Size   Complexity  
A add_watches() 0 9 4
A process() 0 30 6
A process_manifest() 0 6 2
1
<?php
2
namespace midcom\bundle\dependencyInjection;
3
4
use Symfony\Component\DependencyInjection\ContainerBuilder;
5
use midcom_core_manifest;
6
use midcom_error;
7
8
class componentPass extends configPass
9
{
10
    /**
11
     * @var array
12
     */
13
    private $watches = [
14
        \MIDCOM_OPERATION_DBA_CREATE => [],
15
        \MIDCOM_OPERATION_DBA_UPDATE => [],
16
        \MIDCOM_OPERATION_DBA_DELETE => [],
17
        \MIDCOM_OPERATION_DBA_IMPORT => []
18
    ];
19
20 1
    public function process(ContainerBuilder $container)
21
    {
22 1
        $paths = [];
23 1
        foreach ($this->config->get('builtin_components', []) as $path) {
24 1
            $paths[] = dirname(MIDCOM_ROOT) . '/' . $path . '/config/manifest.inc';
25
        }
26
27
        // now we look for extra components the user may have registered
28 1
        foreach ($this->config->get('midcom_components', []) as $path) {
29 1
            if (!file_exists($path . '/config/manifest.inc')) {
30
                throw new midcom_error('No manifest found in path ' . $path);
31
            }
32 1
            $paths[] = $path . '/config/manifest.inc';
33
        }
34
35 1
        foreach ($paths as $path) {
36 1
            $manifest = new midcom_core_manifest($path);
37 1
            $components[$manifest->name] = $path;
38 1
            if ($manifest->watches !== null) {
39 1
                $this->add_watches($manifest->name, $manifest->watches);
40
            }
41
42 1
            $this->process_manifest($manifest, $container);
43
        }
44
45 1
        $cl = $container->getDefinition('componentloader');
46 1
        $cl->addArgument($components);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $components seems to be defined by a foreach iteration on line 35. Are you sure the iterator is never empty, otherwise this variable is not defined?
Loading history...
47
48 1
        $watcher = $container->getDefinition('watcher');
49 1
        $watcher->addArgument($this->watches);
50 1
    }
51
52 1
    private function add_watches(string $component, array $watches)
53
    {
54 1
        foreach ($watches as $watch) {
55 1
            foreach (array_keys($this->watches) as $operation_id) {
56
                // Check whether the operations flag list from the component
57
                // contains the operation_id we're checking a watch for.
58 1
                if ($watch['operations'] & $operation_id) {
59 1
                    $this->watches[$operation_id][] = [
60 1
                        $component => $watch['classes']
61
                    ];
62
                }
63
            }
64
        }
65 1
    }
66
67
    /**
68
     * Register manifest data.
69
     *
70
     * All default privileges are made known to ACL, the watches are registered
71
     */
72 1
    private function process_manifest(midcom_core_manifest $manifest, ContainerBuilder $container)
73
    {
74
        // Register Privileges
75 1
        if ($manifest->privileges) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $manifest->privileges of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
76 1
            $acl = $container->getDefinition('auth.acl');
77 1
            $acl->addMethodCall('register_default_privileges', [$manifest->privileges]);
78
        }
79
    }
80
}