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 — master ( 85cdf0...87050d )
by Mark
02:35
created

BackendController::install()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 21
Code Lines 10

Duplication

Lines 18
Ratio 85.71 %

Importance

Changes 0
Metric Value
cc 3
eloc 10
nc 2
nop 1
dl 18
loc 21
rs 9.3142
c 0
b 0
f 0
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: Mark
5
 * Date: 23/05/2016
6
 * Time: 19:32.
7
 */
8
9
namespace App\Plugins\Products;
10
11
use App\Plugins\PluginEngine;
12
use App\Classes\Repositories\PluginRepository;
13
use App\Classes\Interfaces\Installable;
14
use Illuminate\Support\Facades\DB;
15
16
/**
17
 * Class AdminController.
18
 */
19
class BackendController extends PluginEngine
20
{
21
    /**
22
     * @var PluginRepository
23
     */
24
    private $plugins;
25
26
    /**
27
     * BackendController constructor.
28
     * @param PluginRepository $plugins
29
     */
30
    public function __construct(PluginRepository $plugins)
31
    {
32
        $this->plugins = $plugins;
33
    }
34
35
    /**
36
     * Display a list of products available and disable, enable option for super admins.
37
     */
38
    public function index()
39
    {
40
        return $this->make('index')->with('products', $this->plugins->all());
41
    }
42
43
    /**
44
     * Steps required for the application install.
45
     * Usually defined for logging & new sql entries.
46
     *
47
     * @param string $plugin_name
48
     * @return mixed
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use \Illuminate\Http\RedirectResponse.

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
49
     */
50 View Code Duplication
    public function install(string $plugin_name)
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...
Coding Style Naming introduced by
The parameter $plugin_name is not named in camelCase.

This check marks parameter names that have not been written in camelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection string becomes databaseConnectionString.

Loading history...
51
    {
52
        $plugin = $this->plugins->whereName($plugin_name);
53
54
        if ($plugin->enabled == false)
55
        {
56
            \DB::transaction( function () use ($plugin)
57
            {
58
                if ($plugin->handler instanceof Installable)
59
                {
60
                    $plugin->handler->install();
61
                }
62
63
                $plugin->enabled = true;
64
65
                $plugin->save();
0 ignored issues
show
Bug introduced by
The method save does only exist in App\Model\Plugin, but not in stdClass.

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...
66
            }, 5);
67
        }
68
69
        return response()->redirectToRoute('products.index');
70
    }
71
72
    /**
73
     * Steps required for the application uninstall.
74
     * Usually defined for logging & new sql entries.
75
     *
76
     * @param string $plugin_name
77
     * @return mixed
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use \Illuminate\Http\RedirectResponse.

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
78
     */
79 View Code Duplication
    public function uninstall(string $plugin_name)
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...
Coding Style Naming introduced by
The parameter $plugin_name is not named in camelCase.

This check marks parameter names that have not been written in camelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection string becomes databaseConnectionString.

Loading history...
80
    {
81
        $plugin = $this->plugins->whereName($plugin_name);
82
83
        if ($plugin->enabled == true)
84
        {
85
            \DB::transaction( function () use ($plugin)
86
            {
87
                if ($plugin->handler instanceof Installable)
88
                {
89
                    $plugin->handler->uninstall();
90
                }
91
92
                $plugin->enabled = false;
93
94
                $plugin->save();
0 ignored issues
show
Bug introduced by
The method save does only exist in App\Model\Plugin, but not in stdClass.

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...
95
            }, 5);
96
        }
97
98
        return response()->redirectToRoute('products.index');
99
    }
100
}
101