| Conditions | 2 |
| Paths | 2 |
| Total Lines | 62 |
| Code Lines | 45 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
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:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 63 | public function createWorkspace(Request $request) |
||
| 64 | { |
||
| 65 | $user_id=$this->getSessionId(); |
||
| 66 | $counter=0; |
||
|
|
|||
| 67 | $data = json_decode($request->getContent(), true); |
||
| 68 | //TODO validate json_decode |
||
| 69 | $title=$data['title']; |
||
| 70 | $description=$data['description']; |
||
| 71 | $environment=$data['environment']; |
||
| 72 | |||
| 73 | $patrol = $data['team']['patrol']; |
||
| 74 | $unit = $data['team']['unit']; |
||
| 75 | $group = $data['team']['group']; |
||
| 76 | |||
| 77 | //save the workspace get id |
||
| 78 | $ws = R::dispense("workspace"); |
||
| 79 | $ws->title=$title; |
||
| 80 | $ws->description=$description; |
||
| 81 | $ws->environment=$environment; |
||
| 82 | $ws->completed=false; |
||
| 83 | $ws->inserttime=date('Y-m-d H:i:s'); |
||
| 84 | $ws->lastupdatetime=date('Y-m-d H:i:s'); |
||
| 85 | $id = R::store($ws); |
||
| 86 | |||
| 87 | //save the team |
||
| 88 | $team = R::dispense("team"); |
||
| 89 | $team->workspace=$id; |
||
| 90 | $team->patrol=$patrol; |
||
| 91 | $team->unit=$unit; |
||
| 92 | $team->group=$group; |
||
| 93 | $team_id = R::store($team); |
||
| 94 | |||
| 95 | //create a phantom part to add badge |
||
| 96 | $part = R::dispense("part"); |
||
| 97 | $part->workspace=$id; |
||
| 98 | $part->user=$user_id; |
||
| 99 | $part->inserttime=date('Y-m-d H:i:s'); |
||
| 100 | $part->lastupdatetime=date('Y-m-d H:i:s'); |
||
| 101 | $part->totalpoint=0; |
||
| 102 | $part_id = R::store($part); |
||
| 103 | |||
| 104 | //add the badge to the project |
||
| 105 | foreach($data['badges'] as $badge_id){ |
||
| 106 | //TODO insert those badge as first hidden post |
||
| 107 | $pb = R::dispense("partbadge"); |
||
| 108 | $pb->badge=$badge_id; |
||
| 109 | $pb->part=$part_id; |
||
| 110 | $pb->inserttime=date('Y-m-d H:i:s'); |
||
| 111 | $tmp = R::store($pb); |
||
| 112 | } |
||
| 113 | |||
| 114 | //add the workspace created to the user as owner |
||
| 115 | $usw = R::dispense("userworkspace"); |
||
| 116 | $usw->user=$user_id; |
||
| 117 | $usw->workspace=$id; |
||
| 118 | $usw->inserttime=date('Y-m-d H:i:s'); |
||
| 119 | R::store($usw); |
||
| 120 | |||
| 121 | $res = ["id" => $id]; |
||
| 122 | $headers = []; |
||
| 123 | return JsonResponse::create($res, 201, $headers)->setSharedMaxAge(300); |
||
| 124 | } |
||
| 125 | |||
| 190 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.