Passed
Push — master ( d6dfb3...20cccf )
by Maurício
07:13
created

PluginsController::setPlugins()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 19
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 19
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 0
1
<?php
2
/* vim: set expandtab sw=4 ts=4 sts=4: */
3
4
/**
5
 * Holds the PhpMyAdmin\Controllers\Server\PluginsController
6
 *
7
 * @package PhpMyAdmin\Controllers
8
 */
9
declare(strict_types=1);
10
11
namespace PhpMyAdmin\Controllers\Server;
12
13
use PhpMyAdmin\Controllers\Controller;
14
15
/**
16
 * Handles viewing server plugin details
17
 *
18
 * @package PhpMyAdmin\Controllers
19
 */
20
class PluginsController extends Controller
21
{
22
    /**
23
     * @var array plugin details
24
     */
25
    private $plugins;
26
27
    /**
28
     * Constructs PluginsController
29
     *
30
     * @param \PhpMyAdmin\Response          $response Response object
31
     * @param \PhpMyAdmin\DatabaseInterface $dbi      DatabaseInterface object
32
     */
33
    public function __construct($response, $dbi)
34
    {
35
        parent::__construct($response, $dbi);
36
        $this->setPlugins();
37
    }
38
39
    /**
40
     * Index action
41
     *
42
     * @return string
43
     */
44
    public function index(): string
45
    {
46
        include ROOT_PATH . 'libraries/server_common.inc.php';
47
48
        $header = $this->response->getHeader();
49
        $scripts = $header->getScripts();
50
        $scripts->addFile('vendor/jquery/jquery.tablesorter.js');
51
        $scripts->addFile('server_plugins.js');
52
53
        $pluginsTypeClean = [];
54
        foreach (array_keys($this->plugins) as $pluginType) {
55
            $pluginsTypeClean[$pluginType] = preg_replace(
56
                '/[^a-z]/',
57
                '',
58
                mb_strtolower($pluginType)
59
            );
60
        }
61
        return $this->template->render('server/plugins/index', [
62
            'plugins' => $this->plugins,
63
            'plugins_type_clean' => $pluginsTypeClean,
64
        ]);
65
    }
66
67
    /**
68
     * Sets details about server plugins
69
     *
70
     * @return void
71
     */
72
    private function setPlugins(): void
73
    {
74
        $sql = "SELECT plugin_name,
75
                       plugin_type,
76
                       (plugin_status = 'ACTIVE') AS is_active,
77
                       plugin_type_version,
78
                       plugin_author,
79
                       plugin_description,
80
                       plugin_license
81
                FROM information_schema.plugins
82
                ORDER BY plugin_type, plugin_name";
83
84
        $res = $this->dbi->query($sql);
85
        $this->plugins = [];
86
        while ($row = $this->dbi->fetchAssoc($res)) {
0 ignored issues
show
Bug introduced by
It seems like $res can also be of type false; however, parameter $result of PhpMyAdmin\DatabaseInterface::fetchAssoc() does only seem to accept object, maybe add an additional type check? ( Ignorable by Annotation )

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

86
        while ($row = $this->dbi->fetchAssoc(/** @scrutinizer ignore-type */ $res)) {
Loading history...
87
            $this->plugins[$row['plugin_type']][] = $row;
88
        }
89
        $this->dbi->freeResult($res);
0 ignored issues
show
Bug introduced by
It seems like $res can also be of type false; however, parameter $result of PhpMyAdmin\DatabaseInterface::freeResult() does only seem to accept object, maybe add an additional type check? ( Ignorable by Annotation )

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

89
        $this->dbi->freeResult(/** @scrutinizer ignore-type */ $res);
Loading history...
90
        ksort($this->plugins);
91
    }
92
}
93