Passed
Push — master ( 91b1a6...82674e )
by Yaro
18:44
created

CommonController::refreshSystemValues()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 29

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 29
rs 9.456
c 0
b 0
f 0
cc 3
nc 4
nop 0
1
<?php
2
3
namespace Yaro\Jarboe\Http\Controllers;
4
5
use Illuminate\Routing\Controller;
6
use Yaro\Jarboe\Helpers\System;
7
use Yaro\Jarboe\Table\CRUD;
8
9
class CommonController extends Controller
10
{
11
    public function resetPanelSettings()
12
    {
13
        setcookie('body_class', null, -1, '/');
14
15
        /** @var CRUD $crud */
16
        $crud = app(CRUD::class);
17
        $crud->preferences()->resetAll();
18
19
        return redirect()->back();
20
    }
21
22
    public function refreshSystemValues()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
23
    {
24
        $system = new System();
25
26
        $swapExplanation = 'NA';
27
        if (!is_null($system->swapTotal())) {
28
            $swapExplanation = $system->readableSize($system->swapUsed()) .' / '. $system->readableSize($system->swapTotal());
29
        }
30
31
        $memoryExplanation = 'NA';
32
        if (!is_null($system->memoryTotal())) {
33
            $memoryExplanation = $system->readableSize($system->memoryUsed()) .' / '. $system->readableSize($system->memoryTotal());
34
        }
35
36
        return response()->json([
0 ignored issues
show
Bug introduced by
The method json does only exist in Illuminate\Contracts\Routing\ResponseFactory, but not in Illuminate\Http\Response.

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...
37
            'swap' => [
38
                'explanation' => $swapExplanation,
39
                'percentage' => $system->swapPercentage(),
40
            ],
41
            'memory' => [
42
                'explanation' => $memoryExplanation,
43
                'percentage' => $system->memoryPercentage(),
44
            ],
45
            'load_average' => [
46
                'explanation' => implode(' ', $system->systemLoadSamples()),
47
                'percentages' => $system->systemLoadSamplesInPercentages(),
48
            ],
49
        ]);
50
    }
51
52
    public function notFoundPage()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
53
    {
54
        return response()->view('jarboe::errors.404')->setStatusCode(404);
0 ignored issues
show
Bug introduced by
The method view does only exist in Illuminate\Contracts\Routing\ResponseFactory, but not in Illuminate\Http\Response.

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...
55
    }
56
}
57