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

MethodPluginManager::getPlugins()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 18
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 18
ccs 12
cts 12
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 11
nc 2
nop 0
crap 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