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
Push — development ( aa3faf...1831fb )
by José
04:34
created

CampaignController   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 44
Duplicated Lines 40.91 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 3
dl 18
loc 44
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A index() 0 6 1
A store() 9 9 1
A show() 0 6 1
A update() 9 9 1
A destroy() 0 7 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace DoeSangue\Http\Controllers\API;
4
5
use Illuminate\Http\Request;
6
use DoeSangue\Http\Requests\CreateCampaignRequest;
7
use DoeSangue\Http\Requests\UpdateCampaignRequest;
8
use DoeSangue\Http\Controllers\Controller;
9
use DoeSangue\Models\Campaign;
10
11
class CampaignController extends Controller
12
{
13
    public function index()
14
    {
15
        $campaigns = Campaign::all();
16
17
        return response()->json(compact('campaigns'));
18
    }
19
20 View Code Duplication
    public function store(CreateCampaignRequest $request)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
21
    {
22
        $campaign = new Campaign();
23
        $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...
24
        $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...
25
        $campaign->save();
26
27
        return response()->json(compact('campaign')->with('message', 'Campaign stored sucessfully'));
0 ignored issues
show
Bug introduced by
The method with cannot be called on compact('campaign') (of type array).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
28
    }
29
30
    public function show($id)
31
    {
32
        $campaign = Campaign::findOrFail($id);
33
34
        return response()->json(compact('campaign'));
35
    }
36
37 View Code Duplication
    public function update(UpdateCampaignRequest $request, $id)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
38
    {
39
        $campaign = Campaign::find($id);
40
        $campaign->title = $request['title'];
41
        $campaign->expires = $request['expires'];
42
        $campaign->save();
43
44
        return response()->json($campaign)->with('message', 'Campanha atualizada');
0 ignored issues
show
Bug introduced by
The method with() does not seem to exist on object<Illuminate\Http\JsonResponse>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
45
    }
46
47
    public function destroy($id)
48
    {
49
        $campaign = Campaign::find($id);
50
        $campaign->delete();
51
52
        return response()->json('message', 'Campaign deleted');
53
    }
54
}
55