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

ForceRemoved::find()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 0
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
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
}