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

AbstractController   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
C saveLog() 0 27 8
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
use PagaMasTarde\ModuleUtils\Model\Log\LogEntry;
11
/**
12
 * Class AbstractController
13
 */
14
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...
15
{
16
    /**
17
     * PMT_CODE
18
     */
19
    const PMT_CODE = 'paylater';
20
21
    /**
22
     * @var array $headers
23
     */
24
    protected $headers;
25
26
    /**
27
     * Configure redirection
28
     *
29
     * @param bool   $error
30
     * @param string $url
31
     * @param array  $parameters
32
     */
33
    public function redirect($url = '', $parameters = array())
34
    {
35
        $parsedUrl = parse_url($url);
36
        $separator = ($parsedUrl['query'] == null) ? '?' : '&';
37
        $redirectUrl = $url. $separator . http_build_query($parameters);
38
        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...
39
    }
40
41
    /**
42
     * Save log in SQL database
43
     *
44
     * @param array $data
45
     * @param null  $exception
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $exception is correct as it would always require null to be passed?
Loading history...
46
     */
47
    public function saveLog($data = array(), $exception = null)
48
    {
49
        try {
50
            $logObj = new LogEntry();
51
            if ($exception !== null) {
0 ignored issues
show
introduced by
The condition $exception !== null is always false.
Loading history...
52
                $logObj->error($exception);
53
            }
54
            if (isset($data['message'])) {
55
                $logObj->setMessage($data['message']);
56
            }
57
            if (isset($data['line'])) {
58
                $logObj->setLine($data['line']);
59
            }
60
            if (isset($data['file'])) {
61
                $logObj->setFile($data['file']);
62
            }
63
            if (isset($data['code'])) {
64
                $logObj->setCode($data['code']);
65
            }
66
            if (isset($data['trace'])) {
67
                $logObj->setTrace($data['trace']);
68
            }
69
70
            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...
71
                'log' => $logObj->toJson()
72
            ));
73
        } catch (\Exception $exception) {
74
            // Do nothing
75
        }
76
    }
77
}
78