Completed
Pull Request — dev (#235)
by Alies
07:44
created

PaymentController::getRoles()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace App\Http\Controllers\Backend;
4
5
use App\Models\User;
6
use Illuminate\Http\Request;
7
use App\Utils\RequestSearchQuery;
8
use App\Http\Requests\StorePaymentRequest;
0 ignored issues
show
Bug introduced by
The type App\Http\Requests\StorePaymentRequest 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...
9
use App\Http\Requests\UpdatePaymentRequest;
0 ignored issues
show
Bug introduced by
The type App\Http\Requests\UpdatePaymentRequest 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...
10
//use App\Repositories\Contracts\RoleRepository;
11
use App\Repositories\Contracts\UserRepository;
12
13
class PaymentController extends BackendController
14
{
15
    /**
16
     * @var PaymentRepository
0 ignored issues
show
Bug introduced by
The type App\Http\Controllers\Backend\PaymentRepository 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...
17
     */
18
    protected $payments;
19
20
    /**
21
     * Create a new controller instance.
22
     *
23
     * @param PaymentRepository                             $payments
24
     */
25
    public function __construct(UserRepository $payments)
26
    {
27
        $this->payments = $payments;
0 ignored issues
show
Documentation Bug introduced by
It seems like $payments of type App\Repositories\Contracts\UserRepository is incompatible with the declared type App\Http\Controllers\Backend\PaymentRepository of property $payments.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
28
    }
29
30
    public function getActivePaymentCounter()
31
    {
32
        //return $this->payments->query()->whereActive(true)->count();
33
        return 1;
34
    }
35
36
    /**
37
     * Show the application dashboard.
38
     *
39
     * @param Request $request
40
     *
41
     * @throws \Exception
42
     *
43
     * @return \Illuminate\Contracts\Pagination\LengthAwarePaginator|\Symfony\Component\HttpFoundation\BinaryFileResponse
44
     */
45
    public function search(Request $request)
46
    {
47
        var_dump($request);
0 ignored issues
show
Security Debugging Code introduced by
var_dump($request) looks like debug code. Are you sure you do not want to remove it?
Loading history...
48
        $requestSearchQuery = new RequestSearchQuery($request, $this->users->query(), [
0 ignored issues
show
Bug Best Practice introduced by
The property users does not exist on App\Http\Controllers\Backend\PaymentController. Did you maybe forget to declare it?
Loading history...
49
            'name',
50
            'email',
51
        ]);
52
53
        if ($request->get('exportData')) {
54
            return $requestSearchQuery->export([
55
                'name',
56
                'email',
57
                'active',
58
                'last_access_at',
59
                'created_at',
60
                'updated_at',
61
            ],
62
                [
63
                    __('validation.attributes.name'),
64
                    __('validation.attributes.email'),
65
                    __('validation.attributes.active'),
66
                    __('labels.last_access_at'),
67
                    __('labels.created_at'),
68
                    __('labels.updated_at'),
69
                ],
70
                'payments');
71
        }
72
73
        // return $requestSearchQuery->result([
74
        //     'id',
75
        //     'name',
76
        //     'email',
77
        //     'active',
78
        //     'last_access_at',
79
        //     'created_at',
80
        //     'updated_at',
81
        // ]);
82
        return "";
0 ignored issues
show
Bug Best Practice introduced by
The expression return '' returns the type string which is incompatible with the documented return type Illuminate\Contracts\Pag...tion\BinaryFileResponse.
Loading history...
83
    }
84
85
    /**
86
     * @param Payment $payment
87
     *
88
     * @return Payment
89
     */
90
    public function show(Payment $payment)
91
    {
92
        if (! $payment->can_edit) {
93
            // Only Super admin can access himself
94
            abort(403);
95
        }
96
97
        return $payment;
98
    }
99
100
    /**
101
     * @param StorePaymentRequest $request
102
     *
103
     * @return mixed
104
     */
105
    public function store(StorePaymentRequest $request)
106
    {
107
        $this->authorize('create payments');
108
109
        $this->payments->store($request->input());
110
111
        return $this->redirectResponse($request, __('alerts.backend.payments.created'));
112
    }
113
114
    /**
115
     * @param Payment              $payment
116
     * @param UpdatePaymentRequest $request
117
     *
118
     * @throws \Illuminate\Database\Eloquent\MassAssignmentException
119
     *
120
     * @return mixed
121
     */
122
    public function update(Payment $payment, UpdatePaymentRequest $request)
123
    {
124
        $this->authorize('edit payments');
125
126
        $this->payments->update($payment, $request->input());
127
128
        return $this->redirectResponse($request, __('alerts.backend.payments.updated'));
129
    }
130
131
    /**
132
     * @param Payment    $payment
133
     * @param Request $request
134
     *
135
     * @return mixed
136
     */
137
    public function destroy(Payment $payment, Request $request)
138
    {
139
        $this->authorize('delete payments');
140
141
        $this->payments->destroy($payment);
142
143
        return $this->redirectResponse($request, __('alerts.backend.payments.deleted'));
144
    }
145
146
    /**
147
     * @param Payment $payment
148
     *
149
     * @return mixed
150
     */
151
    public function impersonate(Payment $payment)
152
    {
153
        $this->authorize('impersonate payments');
154
155
        return $this->payments->impersonate($payment);
156
    }
157
158
    /**
159
     * @param \Illuminate\Http\Request $request
160
     *
161
     * @return \Illuminate\Http\JsonResponse|\Illuminate\Http\RedirectResponse
162
     */
163
    public function batchAction(Request $request)
164
    {
165
        $action = $request->get('action');
166
        $ids = $request->get('ids');
167
168
        switch ($action) {
169
            case 'destroy':
170
                $this->authorize('delete payments');
171
172
                $this->payments->batchDestroy($ids);
173
174
                return $this->redirectResponse($request, __('alerts.backend.payments.bulk_destroyed'));
175
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
176
            case 'enable':
177
                $this->authorize('edit payments');
178
179
                $this->payments->batchEnable($ids);
180
181
                return $this->redirectResponse($request, __('alerts.backend.payments.bulk_enabled'));
182
                break;
183
            case 'disable':
184
                $this->authorize('edit payments');
185
186
                $this->payments->batchDisable($ids);
187
188
                return $this->redirectResponse($request, __('alerts.backend.payments.bulk_disabled'));
189
                break;
190
        }
191
192
        return $this->redirectResponse($request, __('alerts.backend.actions.invalid'), 'error');
193
    }
194
195
    public function activeToggle(Payment $payment)
196
    {
197
        $this->authorize('edit payments');
198
        $payment->update(['active' => ! $payment->active]);
199
    }
200
}
201