Passed
Pull Request — master (#23)
by Raúl
02:33
created

AbstractController::getHttpStatusCode()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 20
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 17
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 20
rs 9.7
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 AbstractController
12
 */
13
abstract class AbstractController 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
     * PMT_CODE
17
     */
18
    const PMT_CODE = 'paylater';
19
20
    /**
21
     * @var array $headers
22
     */
23
    protected $headers;
24
25
    /**
26
     * Configure redirection
27
     *
28
     * @param bool   $error
29
     * @param string $url
30
     * @param array  $parameters
31
     */
32
    public function redirect($url = '', $parameters = array())
33
    {
34
        $parsedUrl = parse_url($url);
35
        $separator = ($parsedUrl['query'] == null) ? '?' : '&';
36
        $redirectUrl = $url. $separator . http_build_query($parameters);
37
        Tools::redirect($redirectUrl);
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...
38
    }
39
40
    /**
41
     * Return the HttpStatusCode description
42
     *
43
     * @param int $statusCode
44
     * @return string
45
     */
46
    public function getHttpStatusCode($statusCode = 200)
47
    {
48
        $httpStatusCodes = array(
49
            200 => "OK",
50
            201 => "Created",
51
            202 => "Accepted",
52
            400 => "Bad Request",
53
            401 => "Unauthorized",
54
            402 => "Payment Required",
55
            403 => "Forbidden",
56
            404 => "Not Found",
57
            405 => "Method Not Allowed",
58
            406 => "Not Acceptable",
59
            407 => "Proxy Authentication Required",
60
            408 => "Request Timeout",
61
            409 => "Conflict",
62
            429 => "Too Many Requests",
63
            500 => "Internal Server Error",
64
        );
65
        return isset($httpStatusCodes)? $httpStatusCodes[$statusCode] : $httpStatusCodes[200];
66
    }
67
68
    /**
69
     * Save log in SQL database
70
     *
71
     * @param array $data
72
     */
73
    public function saveLog($data = array())
74
    {
75
        try {
76
            $data = array_merge($data, array(
77
                'timestamp' => time(),
78
                'date' => date("Y-m-d H:i:s"),
79
            ));
80
81
            Db::getInstance()->insert('pmt_logs', array(
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...
82
                'log' => json_encode(str_replace('\'', '`', $data)),
83
            ));
84
        } catch (\Exception $exception) {
85
            // Do nothing
86
        }
87
    }
88
}
89