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

Frontpage   A
last analyzed

Complexity

Total Complexity 16

Size/Duplication

Total Lines 126
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 126
rs 10
c 0
b 0
f 0
wmc 16

8 Methods

Rating   Name   Duplication   Size   Complexity  
A build() 0 7 1
B publish() 0 13 5
A __construct() 0 5 1
A isDisabledPage() 0 3 1
A canBypassMaintenance() 0 3 1
B makeBlade() 0 11 5
A draft() 0 3 1
A isMaintenanceMode() 0 3 1
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 Illuminate\Http\Response;
13
use Illuminate\Support\Collection;
14
use App\Http\Controllers\ErrorController;
15
use App\Classes\Repositories\MenuRepository;
16
use Illuminate\Contracts\Routing\ResponseFactory;
17
18
/**
19
 * Class Frontpage.
20
 */
21
class Frontpage
22
{
23
    /**
24
     * @var Response
25
     */
26
    private $response;
27
28
    /**
29
     * @var Webpage
30
     */
31
    private $webpage;
32
33
    /**
34
     * @var Page
35
     */
36
    private $model;
37
38
    /**
39
     * Frontpage constructor.
40
     * @param Page $model
41
     * @param Collection $navigationRepository
42
     */
43
    public function __construct(Page $model, Collection $navigationRepository)
44
    {
45
        $this->response = app(ResponseFactory::class);
0 ignored issues
show
Documentation Bug introduced by
It seems like app(Illuminate\Contracts...ResponseFactory::class) of type Illuminate\Contracts\Routing\ResponseFactory is incompatible with the declared type Illuminate\Http\Response of property $response.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
46
47
        $this->webpage = new Webpage($this->model = $model, $navigationRepository);
48
    }
49
50
    /**
51
     * @param string|null $template
52
     * @param bool $override
53
     * @param int $status
54
     * @param bool $errorResponse
55
     * @return Response
56
     */
57
    public function publish(string $template = null, bool $override = true, int $status = 200, bool $errorResponse = false)
58
    {
59
        if (! $errorResponse) {
60
            if ($this->isMaintenanceMode() && ! $this->canBypassMaintenance()) {
61
                return ErrorController::maintenance();
62
            }
63
64
            if ($this->isDisabledPage($this->model)) {
65
                return ErrorController::disabled();
66
            }
67
        }
68
69
        return $this->response->view($this->makeBlade($template, $override), ['webpage' => $this->webpage], $status);
70
    }
71
72
    /**
73
     * A user can disable a webpage from being viewed.
74
     *
75
     * @param Page $page
76
     * @return bool
77
     */
78
    private function isDisabledPage(Page $page)
79
    {
80
        return $page->enabled == false;
0 ignored issues
show
Bug Best Practice introduced by
It seems like you are loosely comparing $page->enabled of type integer to the boolean false. If you are specifically checking for 0, consider using something more explicit like === 0 instead.
Loading history...
81
    }
82
83
    /**
84
     * Check if the website is in maintenance mode
85
     * which is set by the user on the dashboard.
86
     *
87
     * @return bool
88
     */
89
    public function isMaintenanceMode()
90
    {
91
        return settings()->getValue('maintenance_mode');
92
    }
93
94
    /**
95
     * Check if the current logged in user if exists,
96
     * can bypass the maintenance and view it offline.
97
     *
98
     * @return bool
99
     */
100
    public function canBypassMaintenance()
101
    {
102
        return auth()->check() == true;
103
    }
104
105
    /**
106
     * @param string|null $template
107
     * @param bool $override
108
     * @return string
109
     */
110
    private function makeBlade(string $template = null, bool $override = true)
111
    {
112
        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...
113
            $template = currentURI() == 'index' ? 'website::index' : 'website::page';
114
        }
115
116
        if ($override && view()->exists("website::plugin.{$this->model->slug}")) {
117
            $template = "website::plugin.{$this->model->slug}";
118
        }
119
120
        return $template;
121
    }
122
123
    /**
124
     * @param string $title
125
     * @param string $description
126
     * @param string $template
127
     * @param int $response
128
     * @return Response
129
     */
130
    public static function build(string $title, string $description, string $template, int $response)
131
    {
132
        $page = new Page(['seo_title' => $title, 'seo_description' => $description]);
133
134
        $navigation = app(MenuRepository::class)->allParentsWithChildren();
135
136
        return (new self($page, $navigation))->publish("errors::{$template}", false, $response, true);
0 ignored issues
show
Bug introduced by
It seems like $navigation can also be of type array<mixed,App\Classes\...itories\MenuRepository>; however, parameter $navigationRepository of App\Classes\Library\Page...rontpage::__construct() does only seem to accept Illuminate\Support\Collection, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

136
        return (new self($page, /** @scrutinizer ignore-type */ $navigation))->publish("errors::{$template}", false, $response, true);
Loading history...
137
    }
138
139
    /**
140
     * Return a drafted page without response headers.
141
     *
142
     * @return Webpage
143
     */
144
    public function draft()
145
    {
146
        return $this->webpage;
147
    }
148
}
149