Checkout::selectAddress()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 20
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 14
dl 0
loc 20
rs 9.7998
c 1
b 0
f 0
cc 2
nc 2
nop 0
1
<?php
2
3
namespace Source\Controllers;
4
5
use Source\Models\User;
6
7
class Checkout extends Controller
0 ignored issues
show
Bug introduced by
The type Source\Controllers\Controller 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...
8
{
9
    /** @var mixed */
10
    private $user;
11
12
    public function __construct($router)
13
    {
14
        parent::__construct($router);
15
16
        if (!isset($_SESSION['user'])) {
17
            $_SESSION['returnToCart'] = true;
18
19
            flash("info", "Entre ou crie uma conta antes!");
20
            $this->router->redirect("login.login");
21
        }
22
23
        $req = callAPI('/me/profile', 'POST', null, $_SESSION['user']);
24
25
        if (isset($req['curl_error'])) {
26
            error_log(json_encode($req));
27
            return;
28
        }
29
30
        if ($req['code'] != 200) {
31
            if ((json_decode($req['result']))->message == 'please login first') {
32
                $_SESSION['user'] = '';
33
                return;
34
            }
35
36
            return;
37
        }
38
39
        $this->user = (json_decode($req['result']))->message;
40
    }
41
42
    public function selectAddress(): void
43
    {
44
        if (empty($this->user)) {
45
            $_SESSION['returnToCart'] = true;
46
47
            flash("info", "Entre ou crie uma conta antes!");
48
            $this->router->redirect("login.login");
49
        }
50
51
        $head = $this->seo->optimize(
52
            'RedStore | ' . site('name'),
53
            site('desc'),
54
            $this->router->route('checkout.selectAddress'),
55
            routeImage('Checkout Address')
56
        )->render();
57
58
        echo $this->view->render('theme/checkout/select-address', [
59
            'head' => $head,
60
            'userData' => $this->user,
61
            'mainURL' => BASE_API
62
        ]);
63
    }
64
65
    public function paymentMethod(): void
66
    {
67
        $head = $this->seo->optimize(
68
            'RedStore | ' . site('name'),
69
            site('desc'),
70
            $this->router->route('checkout.selectAddress'),
71
            routeImage('Checkout Address')
72
        )->render();
73
74
        echo $this->view->render('theme/checkout/pagseguro/payment-method', [
75
            'head' => $head,
76
            'userData' => $this->user,
77
            'mainURL' => BASE_API
78
        ]);
79
    }
80
81
    public function boleto(): void
82
    {
83
        $head = $this->seo->optimize(
84
            'RedStore | ' . site('name'),
85
            site('desc'),
86
            $this->router->route('checkout.boleto'),
87
            routeImage('Checkout boleto')
88
        )->render();
89
90
        echo $this->view->render('theme/checkout/pagseguro/methods/boleto', [
91
            'head' => $head,
92
            'userData' => $this->user,
93
            'mainURL' => BASE_API
94
        ]);
95
    }
96
97
    public function credit(): void
98
    {
99
        $head = $this->seo->optimize(
100
            'RedStore | ' . site('name'),
101
            site('desc'),
102
            $this->router->route('checkout.credit'),
103
            routeImage('Checkout credit')
104
        )->render();
105
106
        echo $this->view->render('theme/checkout/pagseguro/methods/credit', [
107
            'head' => $head,
108
            'userData' => $this->user,
109
            'mainURL' => BASE_API
110
        ]);
111
    }
112
113
    public function debit(): void
114
    {
115
        $head = $this->seo->optimize(
116
            'RedStore | ' . site('name'),
117
            site('desc'),
118
            $this->router->route('checkout.debit'),
119
            routeImage('Checkout debit')
120
        )->render();
121
122
        echo $this->view->render('theme/checkout/pagseguro/methods/debit', [
123
            'head' => $head,
124
            'userData' => $this->user,
125
            'mainURL' => BASE_API
126
        ]);
127
    }
128
129
    public function success(): void
130
    {
131
        $head = $this->seo->optimize(
132
            'RedStore | ' . site('name'),
133
            site('desc'),
134
            $this->router->route('checkout.success'),
135
            routeImage('Checkout success')
136
        )->render();
137
138
        $req = callAPI('/product-checkout', 'POST', null, $_SESSION['user']);
0 ignored issues
show
Unused Code introduced by
The assignment to $req is dead and can be removed.
Loading history...
139
140
        echo $this->view->render('theme/checkout/success', [
141
            'head' => $head
142
        ]);
143
    }
144
}
145