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 ( 5c7169...b34131 )
by Mark
08:19 queued 05:45
created

PageController   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 7

Importance

Changes 0
Metric Value
dl 0
loc 58
rs 10
c 0
b 0
f 0
wmc 5
lcom 0
cbo 7

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A redirect() 0 4 1
A index() 0 4 1
A navigationData() 0 4 1
A trackEvents() 0 8 1
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: Mark
5
 * Date: 05/04/2016
6
 * Time: 14:13.
7
 *
8
 * Updated: 20/06/2016 00:56
9
 */
10
11
namespace App\Http\Controllers;
12
13
use App\Model\Page;
14
use App\Events\PageWasVisited;
15
use App\Events\WebsiteWasVisited;
16
use App\Classes\Repositories\MenuRepository;
17
use App\Classes\Repositories\PageRepository;
18
use App\Classes\Library\PageLoader\Frontpage;
19
20
/**
21
 * Class PageController.
22
 *
23
 * The class handles the page that will be sent back to the user.
24
 *
25
 * The FrontPageLoader class does all the work though.
26
 *
27
 * Errors are now handled in the ErrorController class.
28
 */
29
class PageController extends Controller
30
{
31
    /**
32
     * @var Page
33
     */
34
    private $currentPage;
35
36
    /**
37
     * PageController constructor.
38
     * @param PageRepository $pages
39
     */
40
    public function __construct(PageRepository $pages)
41
    {
42
        $this->currentPage = $pages->whereName(currentURI());
0 ignored issues
show
Documentation Bug introduced by
It seems like $pages->whereName(currentURI()) can also be of type array or object<stdClass>. However, the property $currentPage is declared as type object<App\Model\Page>. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
43
    }
44
45
    /**
46
     * Redirects must use a controller to handle the parameter, as they require a specified target.
47
     * @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...
48
     */
49
    public function redirect()
50
    {
51
        return redirect($this->currentPage->redirect->to(), 302);
52
    }
53
54
    /**
55
     * Standard page views are once that use the URL as the designated target.
56
     *
57
     * @return mixed
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use \Illuminate\Http\Response.

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...
58
     * @throws \Exception
59
     * @internal param FrontPageLoader $pageLoader
60
     */
61
    public function index()
62
    {
63
        return (new Frontpage($this->currentPage, $this->navigationData()))->publish();
64
    }
65
66
    /**
67
     * @return mixed
68
     */
69
    private function navigationData()
70
    {
71
        return app(MenuRepository::class)->allParentsWithChildren();
72
    }
73
74
    /**
75
     * @param Page $page
76
     * @return bool
77
     */
78
    private function trackEvents(Page $page)
79
    {
80
        event(new PageWasVisited($page));
81
82
        event(new WebsiteWasVisited(request()));
83
84
        return true;
85
    }
86
}
87