WelcomeController::statistics()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 1.0109

Importance

Changes 0
Metric Value
dl 0
loc 14
ccs 7
cts 9
cp 0.7778
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 7
nc 1
nop 1
crap 1.0109
1
<?php
2
3
namespace PiFinder\Http\Controllers;
4
5
use JavaScript;
6
use PiFinder\Device;
7
use PiFinder\Services\Statistics;
8
use Illuminate\Filesystem\Filesystem;
9
use PiFinder\Services\MarkdownParser;
10
use Illuminate\Contracts\Cache\Repository as Cache;
11
12
class WelcomeController extends Controller
13
{
14
    /*
15
    |--------------------------------------------------------------------------
16
    | Welcome Controller
17
    |--------------------------------------------------------------------------
18
    |
19
    | This controller renders the "marketing page" for the application and
20
    | is configured to only allow guests. Like most of the other sample
21
    | controllers, you are free to modify or remove it as you desire.
22
    |
23
    */
24
25
    /**
26
     * Create a new controller instance.
27
     */
28 1
    public function __construct()
29
    {
30 1
        $this->middleware('guest');
31 1
    }
32
33
    /**
34
     * Show the application welcome screen to the user.
35
     *
36
     * @return Response
37
     */
38 1
    public function index()
39
    {
40 1
        $devices = Device::onHomePage()->get();
41
42 1
        return view('overview')->with(compact('devices'));
0 ignored issues
show
Bug introduced by
The method with does only exist in Illuminate\View\View, but not in Illuminate\Contracts\View\Factory.

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...
43
    }
44
45
    /**
46
     * Show the getting started screen to the user.
47
     *
48
     * @param MarkdownParser $markdown
49
     * @param Cache          $cache
50
     * @param Filesystem     $file
51
     *
52
     * @return Response
53
     */
54
    public function gettingStarted(MarkdownParser $markdown, Cache $cache, Filesystem $file)
55
    {
56 1
        $gettingStarted = $cache->remember('getting-started', 5, function () use ($markdown, $file) {
57 1
            $gettingStarted = $file->get(base_path('resources/getting-started/readme.md'));
58
59 1
            return $markdown->parse($gettingStarted);
60 1
        });
61
62 1
        return view('getting-started')->with(compact('gettingStarted'));
0 ignored issues
show
Bug introduced by
The method with does only exist in Illuminate\View\View, but not in Illuminate\Contracts\View\Factory.

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...
63
    }
64
65
    /**
66
     * Show the statistics screen to the user.
67
     *
68
     * @return Response
69
     */
70 1
    public function statistics(Statistics $statistics)
71
    {
72 1
        $pokes_total = $statistics->totalPokes();
73
74 1
        $devices_total = $statistics->totalDevices();
75
76 1
        $pokes = $statistics->allPokes()->toArray();
77
78 1
        $network_distribution = $statistics->networkDistribution()->toArray();
79
80 1
        JavaScript::put(compact('pokes', 'network_distribution'));
81
82 1
        return view('statistics')->with(compact('pokes_total', 'devices_total'));
0 ignored issues
show
Bug introduced by
The method with does only exist in Illuminate\View\View, but not in Illuminate\Contracts\View\Factory.

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...
83
    }
84
}
85