Completed
Push — master ( 7cc2c2...10410a )
by Cesar
11s
created

PaylaterLogModuleFrontController::jsonResponse()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 6
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 10
rs 10
1
<?php
2
/**
3
 * This file is part of the official Paylater module for PrestaShop.
4
 *
5
 * @author    Paga+Tarde <[email protected]>
6
 * @copyright 2019 Paga+Tarde
7
 * @license   proprietary
8
 */
9
10
/**
11
 * Class PaylaterLogModuleFrontController
12
 */
13
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...
14
{
15
    /**
16
     * @var string $message
17
     */
18
    protected $message;
19
20
    /**
21
     * @var bool $error
22
     */
23
    protected $error = false;
24
25
    /**
26
     * Controller index method:
27
     */
28
    public function postProcess()
29
    {
30
        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...
31
            return;
32
        };
33
34
35
        $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...
36
        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...
37
            foreach ($results as $row) {
38
                $this->message[] = json_decode($row['log']);
39
            }
40
        }
41
42
        $this->jsonResponse();
43
    }
44
45
    /**
46
     * Send a jsonResponse
47
     */
48
    public function jsonResponse()
49
    {
50
        $result = json_encode($this->message);
51
52
        header('HTTP/1.1 200 Ok', true, 200);
53
        header('Content-Type: application/json', true);
54
        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...
55
56
        echo $result;
57
        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...
58
    }
59
60
    /**
61
     * @return bool|null
62
     */
63
    public function authorize()
64
    {
65
        $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...
66
67
        if (Tools::getValue('secret', false) == $privateKey) {
68
            return true;
69
        }
70
71
        header('HTTP/1.1 403 Forbidden', true, 403);
72
        header('Content-Type: application/json', true);
73
74
        exit();
75
    }
76
}
77