Completed
Push — 7.x-1.x ( 2f9e3c...1070be )
by Frédéric G.
01:36
created

ForceRemoved   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 57
rs 10
c 0
b 0
f 0
wmc 8
lcom 0
cbo 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A create() 0 3 1
A getExtensions() 0 15 1
A filterMissing() 0 4 1
B stripInfo() 0 23 4
A find() 0 5 1
1
<?php
2
3
namespace Drupal\qa\Plugin\Qa\Control;
4
5
class ForceRemoved {
6
7
  public static function create() {
8
    return new static();
9
  }
10
11
  protected function getExtensions() {
12
    $result = db_select('system', 's' )->fields('s', [
13
      'filename',
14
      'name',
15
      'type',
16
      'status',
17
      'bootstrap',
18
      'schema_version',
19
      'weight',
20
      'info',
21
    ])->execute();
22
23
    $extensions = iterator_to_array($result);
24
    return $extensions;
25
  }
26
27
  protected function filterMissing($extension) {
28
    $path = $extension->filename;
29
    return !file_exists($path);
30
  }
31
32
  protected function stripInfo(\stdClass $extension) {
33
    switch ($extension->schema_version) {
34
      case 0:
35
        $state = 'disabled';
36
        break;
37
      case -1:
38
        $state = 'uninstalled';
39
        break;
40
      default:
41
        $state = "enabled:{$extension->schema_version}";
42
        break;
43
    }
44
    $info = unserialize($extension->info);
45
46
    $item = [
47
      'name' => $extension->name,
48
      'type' => $extension->type,
49
      'state' => $state,
50
      'dependencies' => isset($info['dependencies']) ? $info['dependencies'] : [],
51
    ];
52
53
    return $item;
54
  }
55
56
  public function find() {
57
    $missing = array_filter($this->getExtensions(), [$this, 'filterMissing']);
58
    $items = array_map([$this, 'stripInfo'], $missing);
59
    return json_encode($items, JSON_PRETTY_PRINT);
60
  }
61
}