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 laravel-55 (e4caf7)
by José
06:15
created

CampaignController::destroy()   B

Complexity

Conditions 3
Paths 3

Size

Total Lines 32
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 32
rs 8.8571
cc 3
eloc 16
nc 3
nop 1
1
<?php
2
3
namespace DoeSangue\Http\Controllers\API\V1;
4
5
use DoeSangue\Http\Requests\UpdateCampaignRequest;
6
use DoeSangue\Http\Requests\CreateCampaignRequest;
7
use DoeSangue\Http\Controllers\Controller;
8
use Illuminate\Support\Facades\Mail;
9
use DoeSangue\Models\Donor;
10
use DoeSangue\Models\Campaign;
11
use Carbon\Carbon;
12
use Tymon\JWTAuth\Facades\JWTAuth;
13
14
class CampaignController extends Controller
15
{
16
    /**
17
     * Initialize the class
18
     * and set the middleware
19
     */
20
    public function __construct()
21
    {
22
        $this->middleware('jwt.auth', [ 'except' => [ 'index', 'show' ] ]);
23
    }
24
25
    /**
26
     * Get all campaigns
27
     * 20 queries per page
28
     *
29
     * @return void
30
     */
31
    public function index()
32
    {
33
        $campaigns = Campaign::with('comments.commentator')->paginate('12');
0 ignored issues
show
Bug introduced by
The method paginate does only exist in Illuminate\Database\Eloquent\Builder, but not in Illuminate\Database\Eloquent\Model.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
34
35
        return response()->json($campaigns, 200);
36
    }
37
38
    /**
39
     * Get all details of a campaign
40
     *
41
     * @param  integer $id
42
     * @return void
43
     */
44
    public function show($id)
45
    {
46
        $campaign = Campaign::find($id);
47
48
        if (!$campaign) {
49
            return response()->json(
50
                [
51
                    'error_code' => 404,
52
                    'error_message' => 'Campaign not found!'
53
                ], 404
54
            );
55
        }
56
57
        return response()->json(
58
            [
59
            'title' => $campaign->title,
60
            'owner' => [
61
              'first_name' => $campaign->owner->first_name,
62
              'last_name' => $campaign->owner->last_name,
63
              'username' => $campaign->owner->username
64
            ],
65
            'dates' => [
66
            'start_at' => $campaign->created_at->format('Y-m-d h:m:s'),
67
            'finish_at' => $campaign->expires
68
            ]
69
            ], 200
70
        );
71
72
    }
73
74
}
75