Completed
Pull Request — master (#32)
by Manuel
04:07
created

WelcomeController   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 74
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
lcom 0
cbo 5
dl 0
loc 74
ccs 0
cts 27
cp 0
rs 10
c 1
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A index() 0 7 1
A gettingStarted() 0 10 1
A statistics() 0 14 1
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
    public function __construct()
29
    {
30
        $this->middleware('guest');
31
    }
32
33
    /**
34
     * Show the application welcome screen to the user.
35
     *
36
     * @return Response
37
     */
38
    public function index()
39
    {
40
        dump(config('database'), config('database.connections.sqlite'));
41
        $devices = Device::onHomePage()->get();
42
43
        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...
44
    }
45
46
    /**
47
     * Show the getting started screen to the user.
48
     *
49
     * @param MarkdownParser $markdown
50
     * @param Cache          $cache
51
     * @param Filesystem     $file
52
     *
53
     * @return Response
54
     */
55
    public function gettingStarted(MarkdownParser $markdown, Cache $cache, Filesystem $file)
56
    {
57
        $gettingStarted = $cache->remember('getting-started', 5, function () use ($markdown, $file) {
58
            $gettingStarted = $file->get(base_path('resources/getting-started/readme.md'));
59
60
            return $markdown->parse($gettingStarted);
61
        });
62
63
        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...
64
    }
65
66
    /**
67
     * Show the statistics screen to the user.
68
     *
69
     * @return Response
70
     */
71
    public function statistics(Statistics $statistics)
72
    {
73
        $pokes_total = $statistics->totalPokes();
74
75
        $devices_total = $statistics->totalDevices();
76
77
        $pokes = $statistics->allPokes()->toArray();
78
79
        $network_distribution = $statistics->networkDistribution()->toArray();
80
81
        JavaScript::put(compact('pokes', 'network_distribution'));
82
83
        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...
84
    }
85
}
86