AbstractController   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 25
c 2
b 0
f 0
dl 0
loc 57
rs 10
wmc 8

2 Methods

Rating   Name   Duplication   Size   Complexity  
A saveLog() 0 25 6
A redirect() 0 6 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
use Pagantis\ModuleUtils\Model\Log\LogEntry;
11
12
/**
13
 * Class AbstractController
14
 */
15
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...
16
{
17
    /**
18
     * CODE
19
     */
20
    const CODE = 'pagantis';
21
22
    /**
23
     * @var array $headers
24
     */
25
    protected $headers;
26
27
    /**
28
     * Configure redirection
29
     *
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 \Exception  $exception
46
     */
47
    public function saveLog($data = array(), $exception = null)
48
    {
49
        $response = "";
50
        try {
51
            if (count($data) > 0) {
52
                $response = json_encode($data);
53
            } elseif (!is_null($exception)) {
54
                $logEntry = new LogEntry();
55
                $logEntry->error($exception);
56
                $response = $logEntry->toJson();
57
            }
58
            if (is_null($response)) {
0 ignored issues
show
introduced by
The condition is_null($response) is always false.
Loading history...
59
                if (!is_null($exception)) {
60
                    $response = $exception->getMessage();
61
                } else {
62
                    $response = 'Unable to serialize log.'.
63
                        'data: '. json_encode($data).
64
                        'exception: '. json_encode($exception);
65
                }
66
            }
67
68
            Db::getInstance()->insert('pagantis_log', 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...
69
                'log' => str_replace("'", "\'", $response)
70
            ));
71
        } catch (\Exception $error) {
72
            // Do nothing
73
        }
74
    }
75
}
76