Completed
Push — master ( d64a29...6f20dd )
by Pol
02:49
created

MethodPluginManager   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Dependencies 1

Test Coverage

Coverage 93.75%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
cbo 1
dl 0
loc 47
ccs 15
cts 16
cp 0.9375
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getPlugins() 0 17 2
A getPlugin() 0 10 2
1
<?php
2
3
namespace drupol\Yaroc\Plugin;
4
5
use drupol\Yaroc\Utilities\ClassFinder;
6
7
/**
8
 * Class MethodPluginManager.
9
 *
10
 * @package drupol\Yaroc\Plugin
11
 */
12
class MethodPluginManager {
13
14
  /**
15
   * Get the Method plugins.
16
   *
17
   * @return array
18
   */
19 13
  public function getPlugins() {
20 13
    $candidates = array_filter(
21 13
      ClassFinder::getClassesInNamespace('drupol\Yaroc\Plugin\Method'),
22 13
      function ($className) {
23 13
        return in_array('drupol\Yaroc\Plugin\MethodPluginInterface', class_implements($className));
24 13
      }
25
    );
26
27 13
    $classes = [];
28 13
    foreach ($candidates as $candidate) {
29 13
      $candidate = new \ReflectionClass($candidate);
30
31 13
      $classes[$candidate->getConstant('METHOD')] = $candidate;
32
    }
33
34 13
    return $classes;
35
  }
36
37
  /**
38
   * Get a specific Method plugin.
39
   *
40
   * @param string $methodName
41
   *   The method name to call.
42
   * @param array $params
43
   *   The params of the plugin.
44
   *
45
   * @return MethodPluginInterface|bool
46
   */
47 13
  public function getPlugin($methodName, array $params = array()) {
48 13
    $plugins = $this->getPlugins();
49
50 13
    if (isset($plugins[$methodName])) {
51
      /** @var \drupol\Yaroc\Plugin\MethodPluginInterface $plugin */
52 13
      return $plugins[$methodName]->newInstance()->setParameters($params);
53
    }
54
55
    return FALSE;
56
  }
57
58
}
59