Passed
Push — master ( 404d0b...c3da24 )
by Michael
08:28
created

Xwhoops25CorePreload::getLoggerQueries()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 17
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 9
nc 3
nop 0
dl 0
loc 17
rs 9.9666
c 0
b 0
f 0
1
<?php
2
3
use Xmf\Module\Helper\Permission;
0 ignored issues
show
Bug introduced by
The type Xmf\Module\Helper\Permission was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
4
5
6
/**
7
 * @copyright 2019-2021 XOOPS Project (https://xoops.org)
8
 * @license   GNU GPL 2 or later (https://www.gnu.org/licenses/gpl-2.0.html)
9
 * @author    Richard Griffith <[email protected]>
10
 */
11
class Xwhoops25CorePreload extends XoopsPreloadItem
0 ignored issues
show
Bug introduced by
The type XoopsPreloadItem was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
12
{
13
    /**
14
     * eventCoreIncludeCommonAuthSuccess
15
     *
16
     * @return void
17
     */
18
    public static function eventCoreIncludeCommonAuthSuccess()
19
    {
20
        $autoloader = dirname(__DIR__) . '/vendor/autoload.php';
21
        if (!file_exists($autoloader)) {
22
            trigger_error("xwhoops25/vendor/autoload.php not found, was 'composer install' done?");
23
            return;
24
        }
25
        xoops_loadLanguage('logger');
0 ignored issues
show
Bug introduced by
The function xoops_loadLanguage was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

25
        /** @scrutinizer ignore-call */ 
26
        xoops_loadLanguage('logger');
Loading history...
26
        require_once $autoloader;
27
        $permissionHelper = new Permission('xwhoops25');
28
        if ($permissionHelper) {
0 ignored issues
show
introduced by
$permissionHelper is of type Xmf\Module\Helper\Permission, thus it always evaluated to true.
Loading history...
29
            $permissionName = 'use_xwhoops';
30
            $permissionItemId = 0;
31
32
            if ($permissionHelper->checkPermission($permissionName, $permissionItemId, false)) {
33
                $whoops = new \Whoops\Run;
34
                $handler = new \Whoops\Handler\PrettyPageHandler;
35
                $whoops->pushHandler($handler);
36
                $whoops->register();
37
                $handler->addDataTableCallback(
38
                    _LOGGER_QUERIES,
0 ignored issues
show
Bug introduced by
The constant _LOGGER_QUERIES was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
39
                    function () {
40
                        $logger = XoopsLogger::getInstance();
0 ignored issues
show
Bug introduced by
The type XoopsLogger was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
41
                        if (false == $logger->renderingEnabled) {
42
                            return ['XoopsLogger' => 'off'];  // logger is off so data is incomplete
43
                        }
44
                        $queries = [];
45
                        $count=1;
46
                        foreach($logger->queries as $key => $q) {
47
                            $error = (null===$q['errno'] ? '' : $q['errno'].' ') . (null===$q['error'] ? '' : $q['error']);
48
                            $queryTime = isset($q['query_time']) ? sprintf('%0.6f', $q['query_time']) : '';
49
                            $queryKey = (string) $count++ . ' - ' . $queryTime;
50
                            if (null !== $q['errno']) {
51
                                $queryKey = (string) $count .' - Error' ;
52
                            }
53
                            $queries[$queryKey] = htmlentities($q['sql']) . ' ' . $error;
54
                        }
55
                        return ($queries);
56
                    }
57
                );
58
            }
59
        }
60
    }
61
}
62