GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( a88122...7169be )
by Danger
02:19
created

WorkspaceController::createWorkspace()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 62
Code Lines 45

Duplication

Lines 8
Ratio 12.9 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 8
loc 62
rs 9.4743
cc 2
eloc 45
nc 2
nop 1

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace BitPrepared\Bundle\D1b0Workspace\Controller\V1;
4
5
use Symfony\Component\HttpFoundation\Request;
6
use Symfony\Component\HttpFoundation\JsonResponse;
7
use Silex\Application;
8
use Silex\Api\ControllerProviderInterface;
9
use RedBeanPHP\Facade as R;
10
11
class WorkspaceController implements ControllerProviderInterface
12
{
13
14
    public $POINT_FOR_USING_A_CONQUERED_BADGE = 200;
15
    public $POINT_FOR_USING_A_BADGE = 100;
16
    public $POINT_DEFAULT = 50;
17
18
    private $app;
19
20
    public function connect(Application $app)
21
    {
22
        $this->app = $app;
23
        $factory = $app['controllers_factory'];
24
        # il mount point e' precedente e non serve prima
25
        $this->app['db'];
26
        R::fancyDebug(TRUE);
27
        $factory->get('/', array($this, 'getWorkspaceList'));
28
        $factory->post('/', array($this, 'createWorkspace'));
29
        $factory->get('/{id}', array($this, 'getWorkspace'));
30
        $factory->get('/{id}/share', array($this, 'share'));
31
        $factory->post('/{id}/join', array($this, 'join'));
32
        $factory->post('/{id}/part', array($this, 'postPart'));
33
        $factory->get('/{id}/part/{part_id}', array($this, 'getPart'));
34
        $factory->put('/{id}/part/{part_id}', array($this, 'putPart'));
35
        $factory->post('/{id}/part/{part_id}/checkin', array($this, 'checkin'));
36
        $factory->delete('/{id}/part/{part_id}/checkin', array($this, 'deleteCheckin'));
37
        return $factory;
38
    }
39
    public function getSessionId() {
40
        $user_id = $this->app['session']->get('user')['id'];
41
        return $user_id;
42
    }
43
    public function getWorkspaceList(Request $request)
44
    {
45
        $user_id = $this->getSessionId();
46
        $workspaces = R::getAll("SELECT ws.id,
47
                                          ws.title,
48
                                          ws.description,
49
                                          ws.environment,
50
                                          ws.completed
51
                                          FROM userworkspace AS uws
52
                                          LEFT JOIN workspace AS ws
53
                                          ON uws.workspace = ws.id
54
                                          WHERE uws.user = ?",[$user_id]);
55
        $list = [];
56
        foreach ($workspaces as $ws) {
57
            array_push($list, [
58
                "id"=>$ws['id'],
59
                "title"=>$ws['title'],
60
                "description"=>$ws['description'],
61
                "environment"=>$ws['environment'],
62
                "point"=>0, //TODO fare una view con i point già calcolati per il ws
63
                "completed"=>$ws['completed'],
64
            ]);
65
        }
66
        $headers = [];
67
        return JsonResponse::create($list, 200, $headers)->setSharedMaxAge(300);
68
69
    }
70
    public function createWorkspace(Request $request)
71
    {
72
        $user_id = $this->getSessionId();
73
        $counter = 0;
0 ignored issues
show
Unused Code introduced by
$counter is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
74
        $data = json_decode($request->getContent(), true);
75
        //TODO validate json_decode
76
        $title = $data['title'];
77
        $description = $data['description'];
78
        $environment = $data['environment'];
79
80
        $patrol = $data['team']['patrol'];
81
        $unit = $data['team']['unit'];
82
        $group = $data['team']['group'];
83
84
        //save the workspace get id
85
        $ws = R::dispense("workspace");
86
            $ws->title = $title;
87
            $ws->description = $description;
88
            $ws->environment = $environment;
89
            $ws->completed = false;
90
            $ws->inserttime = date('Y-m-d H:i:s');
91
            $ws->lastupdatetime = date('Y-m-d H:i:s');
92
        $id = R::store($ws);
93
94
        //save the team
95
        $team = R::dispense("team");
96
            $team->workspace = $id;
97
            $team->patrol = $patrol;
98
            $team->unit = $unit;
99
            $team->group = $group;
100
        $team_id = R::store($team);
0 ignored issues
show
Unused Code introduced by
$team_id is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
101
102
        //create a phantom part to add badge
103
        $part = R::dispense("part");
104
            $part->workspace = $id;
105
            $part->user = $user_id;
106
            $part->inserttime = date('Y-m-d H:i:s');
107
            $part->lastupdatetime = date('Y-m-d H:i:s');
108
            $part->totalpoint = 0;
109
        $part_id = R::store($part);
110
111
        //add the badge to the project
112 View Code Duplication
        foreach ($data['badges'] as $badge_id) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
113
            //TODO insert those badge as first hidden post
114
            $pb = R::dispense("partbadge");
115
                $pb->badge = $badge_id;
116
                $pb->part = $part_id;
117
                $pb->inserttime = date('Y-m-d H:i:s');
118
            $tmp = R::store($pb);
0 ignored issues
show
Unused Code introduced by
$tmp is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
119
        }
120
121
        //add the workspace created to the user as owner
122
        $usw = R::dispense("userworkspace");
123
            $usw->user = $user_id;
124
            $usw->workspace = $id;
125
            $usw->inserttime = date('Y-m-d H:i:s');
126
        R::store($usw);
127
128
        $res = ["id" => $id];
129
        $headers = [];
130
        return JsonResponse::create($res, 201, $headers)->setSharedMaxAge(300);
131
    }
132
133
    public function getWorkspace($id, Request $request) {
134
        $user_id = $this->getSessionId();
0 ignored issues
show
Unused Code introduced by
$user_id is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
135
        //TODO controllare che l'utente abbia diritto a vedere questo workspace
136
137
        $workspace = R::findOne("workspace", "id = ?", [$id]);
138
        $part = R::findAll("part", "workspace = ?", [$id]);
139
140
        $badges = R::findAll("workspacebadge", "workspace = ?", [$id]);
141
142
        $l_part = [];
143
        foreach ($part as $p) {
144
            array_push($l_part, intval($p['id']));
145
        }
146
        $l_badges = [];
147
        foreach ($badges as $b) {
148
            array_push($l_badges, intval($b['badge']));
149
        }
150
151
        $res = [
152
            'id'=> $workspace['id'],
153
            'title'=> $workspace['title'],
154
            'description'=> $workspace['description'],
155
            'environment'=> $workspace['environment'],
156
            'environment'=> $workspace['environment'],
157
            'completed'=> $workspace['completed'],
158
            'parts'=>$l_part,
159
            'badges'=>$l_badges
160
        ];
161
        $headers = [];
162
        return JsonResponse::create($res, 201, $headers)->setSharedMaxAge(300);
163
    }
164
165
    public function share($id, Request $request) {
166
        $generatedKey = hash("sha256", (mt_rand(10000, 99999).time().$id));
167
        //TODO verificare documentazione realtiva sulla reale entropia generata da questo sistema
168
        $user_id = $this->getSessionId();
169
        $share = R::dispense("share");
170
            $share->user = $user_id;
171
            $share->workspace = $id;
172
            $share->key = $generatedKey;
173
            $share->inserttime = date('Y-m-d H:i:s');
174
        $share_id = R::store($share);
175
176
        $date = new \DateTime();
177
        date_add($date, date_interval_create_from_date_string('15 minutes'));
178
179
        $res = [
180
            "id"=>$share_id,
181
            "key"=>$generatedKey,
182
            "expire"=>$date->format('Y-m-d H:i:s')
183
        ];
184
185
        $headers = [];
186
        return JsonResponse::create($res, 200, $headers)->setSharedMaxAge(300);
187
    }
188
189
    public function join($id, Request $request) {
190
191
192
        $headers = [];
193
        $response = JsonResponse::create(["message"=>"No key found"], 400, $headers)->setSharedMaxAge(300);
194
195
        //TODO verificare documentazione realtiva sulla reale entropia generata da questo sistema
196
        $user_id = $this->getSessionId();
197
        $data = json_decode($request->getContent(), true);
198
199
        $key = $data['key'];
200
201
        $share = R::findOne("share","key = ?",[$key]);
202
        echo $share->inserttime;
203
        if($share !== NULL){
204
            $date = new \DateTime();
205
            date_sub($date, date_interval_create_from_date_string('15 minutes'));
206
207
            $wp_id=$share['workspace'];
208
209
            $dateOld = new \DateTime($share->inserttime);
210
            if($dateOld > $date){
211
                $usw = R::dispense("userworkspace");
212
                    $usw->user = $user_id;
213
                    $usw->workspace = $wp_id;
214
                    $usw->inserttime = date('Y-m-d H:i:s');
215
                R::store($usw);
216
                $headers = [];
217
                $response = JsonResponse::create(["id"=>$wp_id], 200, $headers)->setSharedMaxAge(300);
218
219 View Code Duplication
            }else{
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
220
                $headers = [];
221
                $response = JsonResponse::create(["message"=>"Key no more valid"], 498, $headers)->setSharedMaxAge(300);
222
            }
223
        }
224
225
        return $response;
226
    }
227
228
    public function postPart($id, Request $request) {
229
        $user_id = $this->getSessionId();
230
231
        $data = json_decode($request->getContent(), true);
232
233
        $part = R::dispense("part");
234
            $part->workspace = $id;
235
            $part->user = $user_id;
236
            $part->inserttime = date('Y-m-d H:i:s');
237
            $part->lastupdatetime = date('Y-m-d H:i:s');
238
            $part->totalpoint = 0;
239
        $part_id = R::store($part);
240
241
        foreach($data['part'] as $r){ //TODO va fixato nelle api
242
            $resource = R::dispense("resource");
243
                $resource->part = $part_id;
244
                $resource->inserttime = date('Y-m-d H:i:s');
245
                $resource->updatetime = date('Y-m-d H:i:s');
246
                $resource->type = $r->type;
247
                $resource->ref = $r->ref;
248
                $resource->hash = $r->hash;
249
                $resource->totalpoint = 0;
250
            $resource_id = R::store($resource);
0 ignored issues
show
Unused Code introduced by
$resource_id is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
251
        }
252
253 View Code Duplication
        foreach($data['badges'] as $badge_id){ //TODO va fixato nelle api
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
254
            $pb = R::dispense("partbadge");
255
                $pb->badge = $badge_id;
256
                $pb->part = $part_id;
257
                $pb->inserttime = date('Y-m-d H:i:s');
258
            $tmp = R::store($pb);
0 ignored issues
show
Unused Code introduced by
$tmp is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
259
        }
260
261
        $res = ["id"=>$part_id];
262
        $headers = [];
263
        return JsonResponse::create($res, 201, $headers)->setSharedMaxAge(300);
264
    }
265
266
    public function getPart($id,$part_id, Request $request) {
267
        $user_id = $this->getSessionId();
0 ignored issues
show
Unused Code introduced by
$user_id is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
268
269
        $data = json_decode($request->getContent(), true);
0 ignored issues
show
Unused Code introduced by
$data is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
270
271
        $part = R::findOne("part","id = ?",[$part_id]);
272
273
        $resource = R::findAll("resource","part = ?",[$part_id]);
274
275
        $partecipants = R::findAll("cero","part = ?",[$part_id]);
276
277
        $badges = R::findAll("partbadge","part = ?",[$part_id]);
278
279
        $res= [
280
            "id"=>$part->id,
281
            "creation"=>$part->inserttime,
282
            "points"=>$part->points,
283
            "checked"=>$part->checked,
284
            "badges"=>[],
285
            "part"=>[],
286
            "partecipants"=>[]
287
        ];
288
289
        foreach($badges as $b){
290
            array_push($res['badges'],$b->id);
291
        }
292
        foreach($resource as $r){
293
            array_push($res['part'],[
294
                "type"=>$r->type,
295
                "hash"=>$r->hash,
296
                "ref"=>$r->ref
297
            ]);
298
        }
299
        foreach($partecipants as $p){
300
            array_push($res['partecipants'],$p->user);//TODO forse va usato l'id del c'ero e non l'id dell'utente
301
        }
302
303
        $headers = [];
304
        return JsonResponse::create($res, 201, $headers)->setSharedMaxAge(300);
305
    }
306
307
    private function getPositionInArray($array,$id){
0 ignored issues
show
Unused Code introduced by
This method is not used, and could be removed.
Loading history...
308
        $count =0;
309
        foreach($array as $a){
310
            if($a->id === $id){
311
                return $count;
312
            }
313
            $count = $count + 1;
314
        }
315
        return -1;
316
    }
317
318
    public function putPart($id,$part_id, Request $request) {
319
        $user_id = $this->getSessionId();
320
321
        $data = json_decode($request->getContent(), true);
322
323
        $part = R::load("part",$part_id);
324
            $part->workspace = $id;
325
            $part->user = $user_id;
326
            $part->lastupdatetime = date('Y-m-d H:i:s');
327
            $part->totalpoint = 0;
328
        $part_id = R::store($part);
329
330
        $delete_res=R::findAll("resource","WHERE part = ?",[$part_id]);
331
332
        foreach($data['part'] as $r){ //TODO va fixato nelle api
333
            $resource = R::findOne("resource","WHERE hash =?",[$r->hash]);//TODO BISOGNA FARE IL DIFF TRA QUELLE PRESENTI E QUELLE NON PRESENTI
334
                $resource->part = $part_id;
335
                $resource->updatetime = date('Y-m-d H:i:s');
336
                $resource->type = $r->type;
337
                $resource->ref = $r->ref;
338
                $resource->hash = $r->hash;
339
                $resource->totalpoint = 0;
340
            $resource_id = R::store($resource);
341
            $rem_id=getPositionInArray($delete_res,$resource_id);
342
            if($rem_id != 0)
343
                array_splice($delete_res,$rem_id,1); //RIMUOVO GLI ELEMENTI CHE HO MODIFICATO
344
        }
345
346
        foreach($delete_res as $d){
347
            //RIMUOVO REALMENTE DAL DB LE COSE CHE HO LASCIATO FUORI DALLA PUT (PRESENTI NEL DB MA NON NELLA NUOVA VERSIONE ODIO LE PUT)
348
            $resource = R::load("resource",[$d->id]);
349
            $resource->deleted=true;
350
            R::store($resource);
351
        }
352
353
        $delete_badge=R::findAll("partbadge","WHERE part = ?",[$part_id]);
354
355
        foreach($data['badges'] as $badge_id){
356
            $pb = R::load("partbadge",$badge_id);
357
                $pb->badge = $badge_id;
358
                $pb->part = $part_id;
359
            $tmp = R::store($pb);
360
            $rem_id=getPositionInArray($delete_badge,$tmp);
361
            if($rem_id != 0)
362
                array_splice($delete_badge,$rem_id,1); //RIMUOVO GLI ELEMENTI CHE HO MODIFICATO
363
        }
364
365
        foreach($delete_badge as $d){
366
            //RIMUOVO REALMENTE DAL DB LE COSE CHE HO LASCIATO FUORI DALLA PUT (PRESENTI NEL DB MA NON NELLA NUOVA VERSIONE ODIO LE PUT)
367
            $badge = R::load("partbadge",[$d->id]);
368
            $badge->deleted=true;
369
            R::store($badge);
370
        }
371
372
        $res = ["id"=>$part_id];
373
        $headers = [];
374
        return JsonResponse::create($res, 201, $headers)->setSharedMaxAge(300);
375
    }
376
377
    private function getPoint($badge_id,$badges){
378
        foreach($badges as $b){
379
            if($b->id === $badge_id){
380
                if($b->completed === True){
381
                    echo "CASO 1;<BR />";
382
                    return $this->$POINT_FOR_USING_A_CONQUERED_BADGE;
0 ignored issues
show
Bug introduced by
The variable $POINT_FOR_USING_A_CONQUERED_BADGE does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
383
                }else{
384
                    echo "CASO 2;<BR />";
385
                    return $this->POINT_FOR_USING_A_BADGE;
386
                }
387
            }
388
        }
389
        echo "CASO 3;<BR />";
390
        return $this->POINT_DEFAULT;
391
    }
392
    public function checkin($id,$part_id, Request $request) {
393
        $user_id = $this->getSessionId();
394
395
        $badges = R::findAll("partbadge","part = ?",[$part_id]);
396
        $u_badges = R::findAll("userbadge","user = ?",[$user_id]);
397
398
        $point_earned = 0;
399
        foreach($badges as $b){ //SE CI SONO DEI BADGE
400
            $point = $this->getPoint($b->id,$u_badges);
401
            if($point != $this->POINT_DEFAULT){ //SE SEI IN CAMMINO PER QUEI BADGE O SE LI POSSIEDI GIÀ
402
                echo "PUNTI:".$point;
403
                $point_earned = $point_earned + $point;
404
                $pb = R::dispense("cero");
405
                    $pb->user = $user_id;
406
                    $pb->part = $part_id;
407
                    $pb->badge = $b->id;
408
                    $pb->inserttime = date('Y-m-d H:i:s');
409
                    $pb->points = $point;
410
                $tmp = R::store($pb);
0 ignored issues
show
Unused Code introduced by
$tmp is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
411
412 View Code Duplication
                if($point === $this->POINT_FOR_USING_A_BADGE){ //SE SEI IN CAMMINO MA NON LI HAI ANCORA RAGGIUNTI
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
413
                    $ubc = R::dispense("userbadgeclove");
414
                        $ubc->user = $user_id;
415
                        $ubc->badge = $b->id;
416
                        $ubc->part = $part_id;
417
                        $ubc->inserttime = date('Y-m-d H:i:s');
418
                    $tmp = R::store($ubc);
0 ignored issues
show
Unused Code introduced by
$tmp is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
419
                }
420
            }
421
        }
422
423 View Code Duplication
        if($point_earned <= 0){ //SE NON CI SONO BADGE O SE TU NON SEI IN CAMMINO PER NESSUNO DI LORO
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
424
            $pb = R::dispense("cero");
425
                $pb->user = $user_id;
426
                $pb->part = $part_id;
427
                $pb->inserttime = date('Y-m-d H:i:s');
428
                $pb->points = $this->POINT_DEFAULT;
429
            $tmp = R::store($pb);
0 ignored issues
show
Unused Code introduced by
$tmp is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
430
        }
431
        $res = ["points"=>$point_earned];
432
        $headers = [];
433
        return JsonResponse::create($res, 201, $headers)->setSharedMaxAge(300);
434
435
    }
436
437
    public function deleteCheckin($id,$part_id, Request $request) {
438
        $user_id = $this->getSessionId();
439
440
        $u_badges = R::findAll("userbadge","user = ? AND part = ?",[$user_id,$part_id]);
441
        R::trashAll($u_badges);
442
443
        $cero = R::findAll("cero","user = ? AND part = ?",[$user_id,$part_id]);
444
        R::trashAll($cero);
445
446
        $response = new Response();
447
        $response->headers->set('Content-Type', 'text/html');
448
        $response->setStatusCode(Response::HTTP_NO_CONTENT);
449
        $response->setSharedMaxAge(300);
450
        return $response;
451
452
    }
453
}
454