Passed
Pull Request — master (#34)
by Raúl
02:07
created

PaylaterLogModuleFrontController   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 22
dl 0
loc 60
rs 10
c 1
b 0
f 0
wmc 8

3 Methods

Rating   Name   Duplication   Size   Complexity  
A PagantisLogModuleFrontController::jsonResponse() 0 10 1
A PagantisLogModuleFrontController::postProcess() 0 13 5
A PagantisLogModuleFrontController::authorize() 0 12 2
1
<?php
2
/**
3
 * This file is part of the official Pagantis module for PrestaShop.
4
 *
5
 * @author    Pagantis <[email protected]>
6
 * @copyright 2019 Pagantis
7
 * @license   proprietary
8
 */
9
10
/**
11
 * Class PagantisLogModuleFrontController
12
 */
13
class PagantisLogModuleFrontController 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
        $sql = 'SELECT * FROM '._DB_PREFIX_.'pagantis_log 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...
35
        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...
36
            foreach ($results as $row) {
37
                $this->message[] = (is_null(json_decode($row['log']))) ? $row['log'] : json_decode($row['log']);
38
            }
39
        }
40
        $this->jsonResponse();
41
    }
42
43
    /**
44
     * Send a jsonResponse
45
     */
46
    public function jsonResponse()
47
    {
48
        $result = json_encode($this->message);
49
50
        header('HTTP/1.1 200 Ok', true, 200);
51
        header('Content-Type: application/json', true);
52
        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...
53
54
        echo $result;
55
        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...
56
    }
57
58
    /**
59
     * @return bool|null
60
     */
61
    public function authorize()
62
    {
63
        $privateKey = Configuration::get('pagantis_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...
64
65
        if (Tools::getValue('secret', false) == $privateKey) {
66
            return true;
67
        }
68
69
        header('HTTP/1.1 403 Forbidden', true, 403);
70
        header('Content-Type: application/json', true);
71
72
        exit();
73
    }
74
}
75