Completed
Push — 8.x-1.x ( c8b5ba...4aaba9 )
by Frédéric G.
01:42
created

ForceRemoved::filterMissing()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

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