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.
Completed
Push — master ( 7294ea...cabfcb )
by Daniel
01:23
created

MiniCms::getBlockOutput()   B

Complexity

Conditions 7
Paths 24

Size

Total Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 18
rs 8.8333
c 0
b 0
f 0
cc 7
nc 24
nop 3
1
<?php
2
3
namespace Chadanuk\MiniCms;
4
5
use Chadanuk\MiniCms\Page;
6
use Illuminate\Http\Request;
7
use Illuminate\Routing\Route;
8
use Illuminate\Routing\Router;
9
10
class MiniCms
11
{
12
    public $pageBlocks = null;
13
14
    public function createPage(array $pageData = []): Page
15
    {
16
        return Page::create($pageData);
17
    }
18
19
    public function getPageBySlug(string $slug): Page
20
    {
21
        return Page::where('slug', $slug)->first();
22
    }
23
24
    public function renderAdmin()
25
    {
26
        $request = request();
27
28
        if (!$request->is(config('mini-cms.admin-path') . '/*')) {
29
            return response('', 404);
30
        }
31
32
        $adminRouteServiceProvider = new MiniCmsAdminRouteServiceProvider(app());
33
        $adminRouteServiceProvider->boot();
34
        $response = null;
35
36
        $routes = collect(app()->routes->getRoutes())->filter(
37
            function (Route $route) use ($request, $response) {
38
39
                return is_string($route->action['uses']) && stristr($route->action['uses'], 'Chadanuk\MiniCms') !== false && $route->matches($request) && $route->uri !== config('mini-cms.admin-path') . '/mini-cms/{miniCmsPath}';
40
            }
41
        );
42
43
        if ($routes->count() === 0) {
44
            return '';
45
        }
46
47
        $route = $routes->first();
48
49
        return $route->bind($request)->run();
50
    }
51
52
    public function getBlockOutput(String $type, String $label, string $pageSlug = null)
53
    {
54
        $request = request();
55
        $page = $pageSlug ? Page::findBySlug($pageSlug) : $request->route('page');
56
        if (!$page && $request->is('/')) {
57
            $page = Page::findBySlug(('home'));
58
        }
59
60
        if (!$this->pageBlocks) {
61
            $this->pageBlocks = $page->pageBlocks();
62
        }
63
64
        if ($this->pageBlocks->count() === 0) {
65
            return '';
66
        }
67
        $block = $this->pageBlocks->where('block.label', $label)->where('block.type', $type)->first();
68
        return $block ? $block->render() : '';
69
    }
70
71
    public function renderBlock(String $type, String $label, string $pageSlug = null)
72
    {
73
        echo static::getBlockOutput($type, $label, $pageSlug);
74
    }
75
}
76