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

Completed
Pull Request — development (#48)
by José
04:01
created

CampaignController::store()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 26
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 26
rs 8.8571
cc 1
eloc 13
nc 1
nop 1
1
<?php
2
3
namespace DoeSangue\Http\Controllers\API\V1;
4
5
use DoeSangue\Http\Controllers\Controller;
6
use DoeSangue\Models\Campaign;
7
8
class CampaignController extends Controller
9
{
10
    /**
11
     * Initialize the class
12
     * and set the middleware
13
     */
14 1
    public function __construct()
15
    {
16 1
        $this->middleware('jwt.auth', [ 'except' => [ 'index', 'show' ] ]);
17 1
    }
18
19
    /**
20
     * Get all campaigns
21
     * 20 queries per page
22
     *
23
     * @return \Illuminate\Http\JsonResponse
24
     */
25 1
    public function index()
26
    {
27 1
        $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...
28
29 1
        return response()->json($campaigns, 200);
30
    }
31
32
    /**
33
     * Get all details of a campaign
34
     *
35
     * @param  integer $id
36
     * @return \Illuminate\Http\JsonResponse
37
     */
38
    public function show($id)
39
    {
40
        $campaign = Campaign::find($id);
41
42
        if (!$campaign) {
43
            return response()->json(
44
                [
45
                    'error_code' => 404,
46
                    'error_message' => 'Campaign not found!'
47
                ], 404
48
            );
49
        }
50
51
        return response()->json(
52
            [
53
            'title' => $campaign->title,
54
            'owner' => [
55
              'first_name' => $campaign->owner->first_name,
56
              'last_name' => $campaign->owner->last_name,
57
              'username' => $campaign->owner->username
58
            ],
59
            'dates' => [
60
            'start_at' => $campaign->created_at->format('Y-m-d h:m:s'),
61
            'finish_at' => $campaign->expires
62
            ]
63
            ], 200
64
        );
65
66
    }
67
68
}
69