Completed
Push — trunk ( d79498...d7aafa )
by SuperNova.WS
04:22
created

PageAdminModules   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 63
ccs 0
cts 40
cp 0
rs 10
c 0
b 0
f 0
wmc 9

2 Methods

Rating   Name   Duplication   Size   Complexity  
B viewStatic() 0 31 3
B sortBy() 0 15 6
1
<?php
2
/**
3
 * Created by Gorlum 05.03.2018 12:57
4
 */
5
6
namespace Pages\Deprecated;
7
8
use Modules\sn_module;
9
use SN;
10
11
class PageAdminModules extends PageDeprecated {
12
  const SORT_BY_PACKAGE = 0;
13
  const SORT_BY_ACTIVITY = 1;
14
15
  private static $sorting = [
16
    self::SORT_BY_PACKAGE  => ['PACKAGE', 'NAME', '!ACTIVE', '!INSTALLED',],
17
    self::SORT_BY_ACTIVITY => ['!ACTIVE', '!INSTALLED', 'PACKAGE', 'NAME',],
18
  ];
19
20
  private static $sortFields = [];
21
22
  /**
23
   * @param sn_module $a
24
   * @param sn_module $b
25
   */
26
  private static function sortBy($a, $b) {
27
    $result = 0;
28
    foreach (static::$sortFields as $fieldName) {
0 ignored issues
show
Bug introduced by
Since $sortFields is declared private, accessing it with static will lead to errors in possible sub-classes; you can either use self, or increase the visibility of $sortFields to at least protected.
Loading history...
29
      if (strpos($fieldName, '!') !== false) {
30
        $fieldName = substr($fieldName, 1);
31
        $c = $a;
32
        $a = $b;
33
        $b = $c;
34
      }
35
      if ($result = $a[$fieldName] > $b[$fieldName] ? 1 : ($a[$fieldName] < $b[$fieldName] ? -1 : 0)) {
36
        break;
37
      }
38
    }
39
40
    return $result;
41
  }
42
43
  public static function viewStatic($template = null) {
0 ignored issues
show
Unused Code introduced by
The parameter $template is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

43
  public static function viewStatic(/** @scrutinizer ignore-unused */ $template = null) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
44
    define('IN_ADMIN', true);
45
46
    lng_include('admin');
47
48
    $modules = SN::$gc->modules->getModulesInGroup([], false);
49
50
    $render = [];
51
    foreach ($modules as $module) {
52
      $render[] = [
53
        'PACKAGE'   => $module->manifest['package'],
54
        'NAME'      => $module->manifest['name'],
55
        'VERSION'   => $module->manifest['version'],
56
        'ACTIVE'    => $module->isActive(),
57
        'INSTALLED' => $module->isInstalled(),
58
      ];
59
    }
60
61
    $sortBy = sys_get_param_int('SORT_BY', self::SORT_BY_ACTIVITY);
62
    array_key_exists($sortBy, static::$sorting) ?: ($sortBy = self::SORT_BY_ACTIVITY);
0 ignored issues
show
Bug introduced by
Since $sorting is declared private, accessing it with static will lead to errors in possible sub-classes; you can either use self, or increase the visibility of $sorting to at least protected.
Loading history...
63
    static::$sortFields = static::$sorting[$sortBy];
0 ignored issues
show
Bug introduced by
Since $sortFields is declared private, accessing it with static will lead to errors in possible sub-classes; you can either use self, or increase the visibility of $sortFields to at least protected.
Loading history...
64
    usort($render, [static::class, 'sortBy']);
65
66
    $template = gettemplate('admin/admin_modules');
67
    $template->assign_recursive([
68
      '.'         => ['modules' => $render],
69
      'SORT_BY'   => $sortBy,
70
      'PAGE_NAME' => SN::$lang['menu_admin_modules'],
71
    ]);
72
73
    display($template, SN::$lang['menu_admin_modules']);
74
  }
75
76
}
77