GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

Issues (389)

Branch: master

src/Admin.php (3 issues)

1
<?php
2
3
namespace SleepingOwl\Admin;
4
5
use Closure;
6
use Collective\Html\HtmlServiceProvider;
7
use Illuminate\Config\Repository as ConfigRepository;
8
use Illuminate\Contracts\Foundation\Application;
9
use Illuminate\Contracts\Support\Renderable;
10
use Illuminate\Filesystem\Filesystem;
11
use Illuminate\Foundation\ProviderRepository;
12
use SleepingOwl\Admin\Configuration\ProvidesScriptVariables;
13
use SleepingOwl\Admin\Contracts\AdminInterface;
14
use SleepingOwl\Admin\Contracts\Initializable;
15
use SleepingOwl\Admin\Contracts\ModelConfigurationInterface;
16
use SleepingOwl\Admin\Contracts\Navigation\NavigationInterface;
17
use SleepingOwl\Admin\Contracts\Template\MetaInterface;
18
use SleepingOwl\Admin\Contracts\Template\TemplateInterface;
19
use SleepingOwl\Admin\Http\Controllers\AdminController;
20
use SleepingOwl\Admin\Model\ModelCollection;
21
use SleepingOwl\Admin\Model\ModelConfiguration;
22
use SleepingOwl\Admin\Providers\AdminServiceProvider;
23
use SleepingOwl\Admin\Providers\AliasesServiceProvider;
24
use SleepingOwl\Admin\Providers\BreadcrumbsServiceProvider;
25
26
/**
27
 * Class Admin.
28
 * @property-read \Illuminate\Foundation\Application $app
29
 */
30
class Admin implements AdminInterface
31
{
32
    use ProvidesScriptVariables;
33
34
    /**
35
     * @var ModelConfigurationInterface[]|ModelCollection
36
     */
37
    protected $models;
38
39
    /**
40
     * @var TemplateInterface
41
     */
42
    protected $template;
43
44
    /**
45
     * @var Application
46
     */
47
    protected $app;
48
49
    /**
50
     * @var ConfigRepository
51
     */
52
    protected $config;
53
54
    /**
55
     * @var array
56
     */
57 285
    protected $missedSections = [];
58
59 285
    /**
60 285
     * Admin constructor.
61 285
     *
62 285
     * @param Application $application
63 285
     */
64
    public function __construct(Application $application)
65 285
    {
66 285
        $this->app = $application;
0 ignored issues
show
Documentation Bug introduced by
$application is of type Illuminate\Contracts\Foundation\Application, but the property $app was declared to be of type Illuminate\Foundation\Application. Are you sure that you always receive this specific sub-class here, or does it make sense to add an instanceof 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 given class or a super-class is assigned to a property that is type hinted more strictly.

Either this assignment is in error or an instanceof check should be added for that assignment.

class Alien {}

class Dalek extends Alien {}

class Plot
{
    /** @var  Dalek */
    public $villain;
}

$alien = new Alien();
$plot = new Plot();
if ($alien instanceof Dalek) {
    $plot->villain = $alien;
}
Loading history...
The property app is declared read-only in SleepingOwl\Admin\Admin.
Loading history...
67 285
        $this->models = new ModelCollection();
68
        $this->config = new ConfigRepository(
69
            $this->app['config']->get('sleeping_owl', [])
70
        );
71
72 285
        $this->registerBaseServiceProviders();
73
        $this->registerCoreContainerAliases();
74 285
    }
75 285
76
    /**
77
     * @param TemplateInterface $template
78
     */
79
    public function setTemplate(TemplateInterface $template)
80 285
    {
81
        $this->template = $template;
82 285
    }
83 285
84
    /**
85
     * Initialize class.
86
     */
87
    public function initialize()
88
    {
89
        $this->template->initialize();
90
    }
91 2
92
    /**
93 2
     * @param string $class
94
     * @param Closure|null $callback
95 2
     * @return $this|AdminInterface
96 1
     * @throws Exceptions\RepositoryException
97 1
     */
98
    public function registerModel($class, Closure $callback = null)
99 2
    {
100
        $this->register($model = new ModelConfiguration($this->app, $class));
101
102
        if (is_callable($callback)) {
103
            call_user_func($callback, $model);
104
        }
105
106
        return $this;
107 2
    }
108
109 2
    /**
110
     * @param ModelConfigurationInterface $model
111 2
     *
112 1
     * @return $this
113 1
     */
114
    public function register(ModelConfigurationInterface $model)
115 2
    {
116
        $this->setModel($model->getClass(), $model);
117
118
        if ($model instanceof Initializable) {
119
            $model->initialize();
120
        }
121
122
        return $this;
123 285
    }
124
125 285
    /**
126
     * @param array $sections
127
     *
128
     * @return $this
129
     */
130
    public function registerSections(array $sections)
131 285
    {
132
        foreach ($sections as $model => $section) {
133 285
            if (class_exists($section)) {
134
                $this->register(new $section($this->app, $model));
135
            } else {
136
                $this->missedSections[$model] = $section;
137
            }
138
        }
139
140
        return $this;
141
    }
142
143
    /**
144
     * @return array
145
     */
146
    public function getMissedSections()
147
    {
148
        return $this->missedSections;
149
    }
150 2
151
    /**
152 2
     * @param string $class
153
     * @param ModelConfigurationInterface $model
154 2
     *
155
     * @return $this
156
     */
157
    public function setModel($class, ModelConfigurationInterface $model)
158
    {
159
        $this->models->put($class, $model);
160
161 2
        return $this;
162
    }
163 2
164 1
    /**
165 1
     * @param string|object $class
166
     * @return mixed|null|ModelConfigurationInterface
167 2
     * @throws Exceptions\RepositoryException
168 2
     */
169 2
    public function getModel($class)
170
    {
171 2
        if (is_object($class)) {
172
            $class = get_class($class);
173
        }
174
175
        if (! $this->hasModel($class)) {
176
            $this->registerModel($class);
177 287
        }
178
179 287
        return $this->models->get($class);
180
    }
181
182
    /**
183
     * @return ModelConfigurationInterface[]|ModelCollection
184
     */
185
    public function getModels()
186
    {
187 2
        return $this->models;
188
    }
189 2
190
    /**
191
     * @param string $class
192
     *
193
     * @return bool
194
     */
195
    public function hasModel($class)
196
    {
197
        return $this->models->has($class);
198
    }
199
200
    /**
201
     * @return NavigationInterface
202
     */
203
    public function navigation()
204
    {
205
        return $this->template()->navigation();
206
    }
207
208
    /**
209
     * @return MetaInterface
210
     */
211 1
    public function meta()
212
    {
213 1
        return $this->template()->meta();
214
    }
215
216
    /**
217
     * @return TemplateInterface
218
     */
219
    public function template()
220
    {
221
        return $this->template;
222 1
    }
223
224 1
    /**
225
     * @param $class
226
     * @param int $priority
227
     * @return mixed
228
     * @throws Exceptions\RepositoryException
229
     */
230
    public function addMenuPage($class = null, $priority = 100)
231
    {
232
        return $this->getModel($class)->addToNavigation($priority);
0 ignored issues
show
The method addToNavigation() does not exist on SleepingOwl\Admin\Contra...lConfigurationInterface. It seems like you code against a sub-type of SleepingOwl\Admin\Contra...lConfigurationInterface such as SleepingOwl\Admin\Model\ModelConfigurationManager. ( Ignorable by Annotation )

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

232
        return $this->getModel($class)->/** @scrutinizer ignore-call */ addToNavigation($priority);
Loading history...
233
    }
234
235
    /**
236
     * @param string|Renderable $content
237
     * @param string|null $title
238
     *
239
     * @return \Illuminate\View\View|\Illuminate\Contracts\View\Factory
240
     */
241
    public function view($content, $title = null)
242
    {
243 1
        return $this->app[AdminController::class]->renderContent($content, $title);
244
    }
245 1
246
    /**
247
     * Register all of the base service providers.
248
     *
249
     * @return void
250
     */
251
    protected function registerBaseServiceProviders()
252
    {
253 285
        $providers = [
254
            AliasesServiceProvider::class,
255
            HtmlServiceProvider::class,
256 285
            BreadcrumbsServiceProvider::class,
257 285
            AdminServiceProvider::class,
258 285
        ];
259 285
260 285
        /* Workaround to allow use ServiceProvider-based configurations in old fashion */
261
        if (is_file(app_path('Providers/AdminSectionsServiceProvider.php'))) {
262
            $providers[] = $this->app->getNamespace().'Providers\\AdminSectionsServiceProvider';
263 285
        }
264
265
        $manifestPath = $this->app->bootstrapPath().'/cache/sleepingowladmin-services.php';
266
267 285
        (new ProviderRepository($this->app, new Filesystem(), $manifestPath))->load($providers);
268
    }
269 285
270 285
    /**
271
     * Register the core class aliases in the container.
272
     *
273
     * @return void
274
     */
275
    protected function registerCoreContainerAliases()
276
    {
277 285
        $aliases = [
278
            'sleeping_owl' => ['SleepingOwl\Admin\Admin', 'SleepingOwl\Admin\Contracts\AdminInterface'],
279
            'sleeping_owl.template' => ['SleepingOwl\Admin\Contracts\Template\TemplateInterface'],
280 285
            'sleeping_owl.breadcrumbs' => ['SleepingOwl\Admin\Contracts\Template\BreadcrumbsInterface'],
281 285
            'sleeping_owl.widgets' => ['SleepingOwl\Admin\Contracts\Widgets\WidgetsRegistryInterface', 'SleepingOwl\Admin\Widgets\WidgetsRegistry'],
282 285
            'sleeping_owl.message' => ['SleepingOwl\Admin\Widgets\Messages\MessageStack'],
283 285
            'sleeping_owl.navigation' => ['SleepingOwl\Admin\Navigation', 'SleepingOwl\Admin\Contracts\Navigation\NavigationInterface'],
284 285
            'sleeping_owl.wysiwyg' => ['SleepingOwl\Admin\Wysiwyg\Manager', 'SleepingOwl\Admin\Contracts\Wysiwyg\WysiwygMangerInterface'],
285 285
            'sleeping_owl.meta' => ['assets.meta', 'SleepingOwl\Admin\Contracts\Template\MetaInterface', 'SleepingOwl\Admin\Templates\Meta'],
286 285
        ];
287 285
288 285
        foreach ($aliases as $key => $aliasesItem) {
289
            foreach ($aliasesItem as $alias) {
290 285
                $this->app->alias($key, $alias);
291 285
            }
292 285
        }
293 285
    }
294
}
295