Completed
Push — 7.x-1.x ( dff1e0...77c4eb )
by Pol
04:34
created

service_container.module::service_container_modules_enabled()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 4
c 0
b 0
f 0
nc 2
nop 0
dl 0
loc 6
rs 9.4285
1
<?php
2
/**
3
 * @file
4
 * Main module file for the service_container module.
5
 */
6
7
// -----------------------------------------------------------------------
8
// Core Hooks
9
10
/**
11
 * Implements hook_stream_wrappers_alter().
12
 */
13
function service_container_stream_wrappers_alter(&$wrappers) {
0 ignored issues
show
Unused Code introduced by
The parameter $wrappers is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
14
  if (class_exists('ServiceContainer')) {
15
    ServiceContainer::init();
16
  }
17
}
18
19
/**
20
 * Implements hook_modules_enabled().
21
 */
22
function service_container_modules_enabled() {
23
  if (class_exists('ServiceContainer')) {
24
    ServiceContainer::reset();
25
    ServiceContainer::init();
26
  }
27
}
28
29
/**
30
 * Implements hook_module_implements_alter().
31
 */
32
function service_container_module_implements_alter(&$implementations, $hook) {
33
  // Moves our hook_init() implementation to occur first so that we
34
  // can initialize the container.
35
  if ($hook == 'stream_wrappers_alter') {
36
    $group = $implementations['service_container'];
37
    unset($implementations['service_container']);
38
    $implementations = array('service_container' => $group) + $implementations;
39
  }
40
}
41
42
// -----------------------------------------------------------------------
43
// Contrib Hooks
44
45
/**
46
 * Implements hook_ctools_plugin_type().
47
 */
48
function service_container_ctools_plugin_type() {
49
  $items['ServiceProvider'] = array(
0 ignored issues
show
Coding Style Comprehensibility introduced by
$items was never initialized. Although not strictly required by PHP, it is generally a good practice to add $items = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
50
    'cache' => FALSE,
51
  );
52
53
  return $items;
54
}
55
56
/**
57
 * Implements hook_ctools_plugin_directory().
58
 */
59
function service_container_ctools_plugin_directory($owner, $plugin_type) {
60
  if ($owner == 'service_container') {
61
    return 'src/ServiceContainer/' . $plugin_type;
62
  }
63
64
  return NULL;
65
}
66
67
// -----------------------------------------------------------------------
68
// Public API
69