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

Frontpage::build()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 4
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: Marky
5
 * Date: 31/12/2017
6
 * Time: 00:12.
7
 */
8
9
namespace App\Classes\Library\PageLoader;
10
11
use App\Model\Page;
12
use App\Model\Role;
13
use Illuminate\Http\Response;
14
use Illuminate\Support\Collection;
15
use App\Http\Controllers\ErrorController;
16
use App\Classes\Repositories\MenuRepository;
17
use Illuminate\Contracts\Routing\ResponseFactory;
18
19
class Frontpage
20
{
21
    /**
22
     * @var Response
23
     */
24
    private $response;
25
26
    /**
27
     * @var Webpage
28
     */
29
    public $webpage;
30
31
    /**
32
     * @var Page
33
     */
34
    private $model;
35
36
    /**
37
     * Frontpage constructor.
38
     * @param Page $model
39
     * @param Collection $navigationRepository
40
     */
41
    public function __construct(Page $model, Collection $navigationRepository)
42
    {
43
        $this->response = app(ResponseFactory::class);
44
45
        $this->webpage = new Webpage($this->model = $model, $navigationRepository);
46
    }
47
48
    /**
49
     * @param string|null $template
50
     * @param bool $override
51
     * @param int $status
52
     * @return Response
53
     */
54
    public function publish(string $template = null, bool $override = true, int $status = 200, bool $errorResponse = false)
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 123 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
55
    {
56
        if (!$errorResponse)
57
        {
58
            if ($this->isMaintenanceMode()) {
59
                return ErrorController::maintenance();
60
            }
61
62
            if ($this->isDisabledPage($this->model)) {
63
                return ErrorController::disabled();
64
            }
65
        }
66
67
        return $this->response->view($this->makeBlade($template, $override), ['webpage' => $this->webpage], $status);
68
    }
69
70
    /**
71
     * A user can disable a webpage from being viewed.
72
     *
73
     * @param Page $page
74
     * @return bool
75
     */
76
    private function isDisabledPage(Page $page)
77
    {
78
        return $page->enabled == false;
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
79
    }
80
81
    /**
82
     * Check if the website is in maintenance mode
83
     * which is set by the user on the dashboard.
84
     *
85
     * @return bool
86
     */
87
    public function isMaintenanceMode()
88
    {
89
        return settings()->getValue('maintenance_mode');
90
    }
91
92
    /**
93
     * Check if the current logged in user if exists,
94
     * can bypass the maintenance and view it offline.
95
     *
96
     * @return bool
97
     */
98
    public function canBypassMaintenance()
99
    {
100
        return auth()->check() == true && account()->hasRole(Role::ADMINISTRATOR);
0 ignored issues
show
Bug introduced by
The method check does only exist in Illuminate\Contracts\Auth\Guard, but not in Illuminate\Contracts\Auth\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...
Bug introduced by
The method hasRole does only exist in App\Model\Account, but not in Illuminate\Contracts\Auth\Authenticatable.

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...
101
    }
102
103
    /**
104
     * @param string|null $template
105
     * @param bool $override
106
     * @return string
107
     */
108
    private function makeBlade(string $template = null, bool $override = true)
109
    {
110
        if ($template == null) {
0 ignored issues
show
Bug introduced by
It seems like you are loosely comparing $template of type null|string against null; this is ambiguous if the string can be empty. Consider using a strict comparison === instead.
Loading history...
111
            return currentURI() == 'index' ? 'website::index' : 'website::page';
112
        }
113
114
        if ($override && view()->exists("website::plugins.{$this->model->slug}")) {
0 ignored issues
show
Bug introduced by
The method exists does only exist in Illuminate\Contracts\View\Factory, but not in Illuminate\View\View.

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...
115
            $template = "website::plugins.{$this->model->slug}";
116
        }
117
118
        return $template;
119
    }
120
121
    /**
122
     * @param string $title
123
     * @param string $description
124
     * @param string $template
125
     * @param int $response
126
     * @return Response
127
     */
128
    public static function build(string $title, string $description, string $template, int $response)
129
    {
130
        $page = new Page(['seo_title' => $title, 'seo_description' => $description]);
131
132
        $navigation = app(MenuRepository::class)->allParentsWithChildren();
133
134
        return (new self($page, $navigation))->publish("errors::{$template}", false, $response, true);
135
    }
136
}
137