Completed
Push — master ( 69f82d...a3a3e6 )
by Pol
13:34 queued 11:03
created

MethodPluginManager   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Dependencies 1

Test Coverage

Coverage 94.12%

Importance

Changes 0
Metric Value
wmc 4
cbo 1
dl 0
loc 44
ccs 16
cts 17
cp 0.9412
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getPlugin() 0 9 2
A getPlugins() 0 18 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 12
  public function getPlugins() {
20 12
    $candidates = array_filter(
21 12
      ClassFinder::getClassesInNamespace('drupol\Yaroc\Plugin\Method'),
22 12
      function ($className) {
23 12
        return in_array('drupol\Yaroc\Plugin\MethodPluginInterface', class_implements($className));
24 12
      }
25
    );
26
27 12
    $classes = [];
28 12
    foreach ($candidates as $candidate) {
29 12
      $candidate = new \ReflectionClass($candidate);
30 12
      $candidate = $candidate->newInstance();
31
32 12
      $classes[$candidate::METHOD] = $candidate;
33
    }
34
35 12
    return $classes;
36
  }
37
38
  /**
39
   * Get a specific Method plugin.
40
   *
41
   * @param string $methodName
42
   *
43
   * @return MethodPluginInterface|bool
44
   */
45 12
  public function getPlugin($methodName) {
46 12
    $plugins = $this->getPlugins();
47
48 12
    if (isset($plugins[$methodName])) {
49 12
      return $plugins[$methodName];
50
    }
51
52
    return FALSE;
53
  }
54
55
}
56