Passed
Pull Request — master (#23)
by Cesar
02:07
created

PaylaterLogModuleFrontController::postProcess()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 15
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 7
c 1
b 0
f 0
nc 3
nop 0
dl 0
loc 15
rs 10
1
<?php
2
3
/**
4
 * Class PaylaterLogModuleFrontController
5
 */
6
class PaylaterLogModuleFrontController extends ModuleFrontController
0 ignored issues
show
Bug introduced by
The type ModuleFrontController 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...
7
{
8
    /**
9
     * @var string $message
10
     */
11
    protected $message;
12
13
    /**
14
     * @var bool $error
15
     */
16
    protected $error = false;
17
18
    /**
19
     * Controller index method:
20
     */
21
    public function postProcess()
22
    {
23
        if (!$this->authorize()) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->authorize() of type null|true is loosely compared to false; this is ambiguous if the boolean can be false. You might want to explicitly use !== null instead.

If an expression can have both false, and null as possible values. It is generally a good practice to always use strict comparison to clearly distinguish between those two values.

$a = canBeFalseAndNull();

// Instead of
if ( ! $a) { }

// Better use one of the explicit versions:
if ($a !== null) { }
if ($a !== false) { }
if ($a !== null && $a !== false) { }
Loading history...
24
            return;
25
        };
26
27
28
        $sql = 'SELECT * FROM '._DB_PREFIX_.'pmt_logs ORDER BY id desc LIMIT 200';
0 ignored issues
show
Bug introduced by
The constant _DB_PREFIX_ was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
29
        if ($results = Db::getInstance()->ExecuteS($sql)) {
0 ignored issues
show
Bug introduced by
The type Db 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...
30
            foreach ($results as $row) {
31
                $this->message[] = json_decode($row['log']);
32
            }
33
        }
34
35
        $this->jsonResponse();
36
    }
37
38
    /**
39
     * Send a jsonResponse
40
     */
41
    public function jsonResponse()
42
    {
43
        $result = json_encode($this->message);
44
45
        header('HTTP/1.1 200 Ok', true, 200);
46
        header('Content-Type: application/json', true);
47
        header('Content-Length: ' . Tools::strlen($result));
0 ignored issues
show
Bug introduced by
The type Tools 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...
48
49
        echo $result;
50
        exit();
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
51
    }
52
53
    /**
54
     * @return bool|null
55
     */
56
    public function authorize()
57
    {
58
        $privateKey = Configuration::get('pmt_private_key');
0 ignored issues
show
Bug introduced by
The type Configuration 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...
59
60
        if (Tools::getValue('secret', false) == $privateKey) {
61
            return true;
62
        }
63
64
        header('HTTP/1.1 403 Forbidden', true, 403);
65
        header('Content-Type: application/json', true);
66
67
        exit();
68
    }
69
}
70