Scrutinizer GitHub App not installed

We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.

Install GitHub App

Passed
Branch development (ad65b0)
by José
04:05
created

CampaignController::campaigns()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
3
namespace DoeSangue\Http\Controllers\API;
4
5
use Illuminate\Http\Request;
6
use DoeSangue\Http\Requests\UpdateCampaignRequest;
7
use DoeSangue\Http\Controllers\Controller;
8
use DoeSangue\Models\Campaign;
9
10
class CampaignController extends Controller
11
{
12
    public function __construct()
13
    {
14
        $this->middleware('jwt.auth', ['except' => ['index', 'show']]);
15
    }
16
17
    public function index()
18
    {
19
        $campaigns = Campaign::all();
20
21
        return response()->json(compact('campaigns'));
22
    }
23
24
    public function store(Request $request)
25
    {
26
      $this->validate($request,
27
        [
28
          'title' => 'required|min:60',
29
            'expires' => 'required|date',
30
            'id_user' => 'required|integer',
31
        ]);
32
33
        $campaign = new Campaign();
34
        $campaign->title = $request[ 'title' ];
0 ignored issues
show
Documentation introduced by
The property title does not exist on object<DoeSangue\Models\Campaign>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
35
        $campaign->expires = $request[ 'expires' ];
0 ignored issues
show
Documentation introduced by
The property expires does not exist on object<DoeSangue\Models\Campaign>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
36
        $campaign->id_user = $request['id_user'];
0 ignored issues
show
Documentation introduced by
The property id_user does not exist on object<DoeSangue\Models\Campaign>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
37
        $campaign->save();
38
39
        return response()->json($campaign, 201);
40
    }
41
42
    public function show($id)
43
    {
44
        $campaign = Campaign::findOrFail($id);
45
46
        return response()->json(compact('campaign'));
47
    }
48
49
    public function update(UpdateCampaignRequest $request, $id)
50
    {
51
        $campaign = Campaign::find($id);
52
        $campaign->title = $request[ 'title' ];
53
        $campaign->expires = $request[ 'expires' ];
54
        $campaign->save();
55
56
        return response()->json($campaign);
57
    }
58
59
    public function destroy($id)
60
    {
61
        $campaign = Campaign::find($id);
62
        // Notify error in not found
63
        if (!$campaign) {
64
            return response()->json(
65
                [
66
                  'error_code' => '404',
67
                  'message' => 'Campaign not found!'
68
                ], 404
69
            );
70
        }
71
        $campaign->delete();
72
73
        return response()->json([
74
          'title' => $campaign->title,
75
          'id_user' => $campaign->id_user,
76
          'status' => 'deleted'
77
          ]);
78
    }
79
80
    /**
81
     * Get campaigns by specific donor/user
82
     * @return Response
83
     */
84
    public function campaigns(Donor $id){
85
86
      $donor = Donor::find($id);
87
      $campaigns = Campaigns::where('id_user', $donor->id)->get();
0 ignored issues
show
Unused Code introduced by
$campaigns 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...
88
    }
89
}
90