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

CampaignController::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\StoreCampaignRequest;
0 ignored issues
show
Bug introduced by
The type App\Http\Requests\StoreCampaignRequest 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\UpdateCampaignRequest;
0 ignored issues
show
Bug introduced by
The type App\Http\Requests\UpdateCampaignRequest 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\UserRepository;
11
12
class CampaignController extends BackendController
13
{
14
    /**
15
     * @var CampaignRepository
0 ignored issues
show
Bug introduced by
The type App\Http\Controllers\Backend\CampaignRepository 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
    protected $campaigns;
18
19
    /**
20
     * Create a new controller instance.
21
     *
22
     * @param CampaignRepository                             $campaigns
23
     */
24
    public function __construct(UserRepository $campaigns)
25
    {
26
        $this->campaigns = $campaigns;
0 ignored issues
show
Documentation Bug introduced by
It seems like $campaigns of type App\Repositories\Contracts\UserRepository is incompatible with the declared type App\Http\Controllers\Backend\CampaignRepository of property $campaigns.

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...
27
    }
28
29
    public function getActiveCampaignCounter()
30
    {
31
        //return $this->campaigns->query()->whereActive(true)->count();
32
        return 1;
33
    }
34
35
    /**
36
     * Show the application dashboard.
37
     *
38
     * @param Request $request
39
     *
40
     * @throws \Exception
41
     *
42
     * @return \Illuminate\Contracts\Pagination\LengthAwarePaginator|\Symfony\Component\HttpFoundation\BinaryFileResponse
43
     */
44
    public function search(Request $request)
45
    {
46
        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...
47
        $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\CampaignController. Did you maybe forget to declare it?
Loading history...
48
            'name',
49
            'email',
50
        ]);
51
52
        if ($request->get('exportData')) {
53
            return $requestSearchQuery->export([
54
                'name',
55
                'email',
56
                'active',
57
                'last_access_at',
58
                'created_at',
59
                'updated_at',
60
            ],
61
                [
62
                    __('validation.attributes.name'),
63
                    __('validation.attributes.email'),
64
                    __('validation.attributes.active'),
65
                    __('labels.last_access_at'),
66
                    __('labels.created_at'),
67
                    __('labels.updated_at'),
68
                ],
69
                'campaigns');
70
        }
71
72
        // return $requestSearchQuery->result([
73
        //     'id',
74
        //     'name',
75
        //     'email',
76
        //     'active',
77
        //     'last_access_at',
78
        //     'created_at',
79
        //     'updated_at',
80
        // ]);
81
        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...
82
    }
83
84
    /**
85
     * @param Campaign $campaign
86
     *
87
     * @return Campaign
88
     */
89
    public function show(Campaign $campaign)
90
    {
91
        if (! $campaign->can_edit) {
92
            // Only Super admin can access himself
93
            abort(403);
94
        }
95
96
        return $campaign;
97
    }
98
99
    /**
100
     * @param StoreCampaignRequest $request
101
     *
102
     * @return mixed
103
     */
104
    public function store(StoreCampaignRequest $request)
105
    {
106
        $this->authorize('create campaigns');
107
108
        $this->campaigns->store($request->input());
109
110
        return $this->redirectResponse($request, __('alerts.backend.campaigns.created'));
111
    }
112
113
    /**
114
     * @param Campaign              $campaign
115
     * @param UpdateCampaignRequest $request
116
     *
117
     * @throws \Illuminate\Database\Eloquent\MassAssignmentException
118
     *
119
     * @return mixed
120
     */
121
    public function update(Campaign $campaign, UpdateCampaignRequest $request)
122
    {
123
        $this->authorize('edit campaigns');
124
125
        $this->campaigns->update($campaign, $request->input());
126
127
        return $this->redirectResponse($request, __('alerts.backend.campaigns.updated'));
128
    }
129
130
    /**
131
     * @param Campaign    $campaign
132
     * @param Request $request
133
     *
134
     * @return mixed
135
     */
136
    public function destroy(Campaign $campaign, Request $request)
137
    {
138
        $this->authorize('delete campaigns');
139
140
        $this->campaigns->destroy($campaign);
141
142
        return $this->redirectResponse($request, __('alerts.backend.campaigns.deleted'));
143
    }
144
145
    /**
146
     * @param Campaign $campaign
147
     *
148
     * @return mixed
149
     */
150
    public function impersonate(Campaign $campaign)
151
    {
152
        $this->authorize('impersonate campaigns');
153
154
        return $this->campaigns->impersonate($campaign);
155
    }
156
157
    /**
158
     * @param \Illuminate\Http\Request $request
159
     *
160
     * @return \Illuminate\Http\JsonResponse|\Illuminate\Http\RedirectResponse
161
     */
162
    public function batchAction(Request $request)
163
    {
164
        $action = $request->get('action');
165
        $ids = $request->get('ids');
166
167
        switch ($action) {
168
            case 'destroy':
169
                $this->authorize('delete campaigns');
170
171
                $this->campaigns->batchDestroy($ids);
172
173
                return $this->redirectResponse($request, __('alerts.backend.campaigns.bulk_destroyed'));
174
                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...
175
            case 'enable':
176
                $this->authorize('edit campaigns');
177
178
                $this->campaigns->batchEnable($ids);
179
180
                return $this->redirectResponse($request, __('alerts.backend.campaigns.bulk_enabled'));
181
                break;
182
            case 'disable':
183
                $this->authorize('edit campaigns');
184
185
                $this->campaigns->batchDisable($ids);
186
187
                return $this->redirectResponse($request, __('alerts.backend.campaigns.bulk_disabled'));
188
                break;
189
        }
190
191
        return $this->redirectResponse($request, __('alerts.backend.actions.invalid'), 'error');
192
    }
193
194
    public function activeToggle(Campaign $campaign)
195
    {
196
        $this->authorize('edit campaigns');
197
        $campaign->update(['active' => ! $campaign->active]);
198
    }
199
}
200