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 ( 160b61...162853 )
by Alireza
9s
created

dashboard   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 73
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
c 1
b 0
f 0
lcom 1
cbo 3
dl 0
loc 73
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getItems() 0 8 2
A showLink() 0 8 3
B create() 0 27 1
1
<?php
2
3
namespace Serverfireteam\Panel\libs;
4
5
6
use Illuminate\Support\Collection;
7
use Illuminate\Support\Str;
8
use Serverfireteam\Panel\LinkRepository;
9
10
class dashboard
11
{
12
13
    /**
14
     * Dashboard items cache
15
     * @var array
16
     */
17
    public static $dashboardItems;
18
19
    /**
20
     * Either retrieve the dashboard items from cache or from the config/DB if they were not yet cached
21
     * @return array
22
     */
23
    public static function getItems ()
24
    {
25
        if (!self::$dashboardItems) {
0 ignored issues
show
Bug Best Practice introduced by
The expression self::$dashboardItems of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
26
            self::$dashboardItems = \App::call(self::class . '@create');
27
        }
28
29
        return self::$dashboardItems;
30
    }
31
32
    /**
33
     * Determine whether to show the given entity type in the panel
34
     * @param $link
35
     * @return bool
36
     */
37
    private function showLink ($link)
38
    {
39
        if (!$link['show_menu']) return false;
40
41
        $user = \Auth::guard('panel')->user();
42
43
        return $user->hasRole('super') || $user->hasPermission('/' . $link['url'] . '/all');
44
    }
45
46
    /**
47
     * Return the array of entity types (models / links)
48
     * to show CRUD interfaces for in the panel
49
     *
50
     * @param AppHelper      $appHelper
51
     * @param LinkRepository $linkRepository
52
     *
53
     * @return array
54
     */
55
    public function create (AppHelper $appHelper, LinkRepository $linkRepository)
56
    {
57
        // @TODO cache
58
59
        return $linkRepository->all()
60
61
            ->filter(function ($link) {
62
                return $this->showLink($link);
63
            })
64
65
            ->map(function ($link) use ($appHelper) {
66
67
                $modelName = $link['url'];
68
69
                $model = $appHelper->getModel($modelName);
70
71
                return [
72
                    'modelName'   => $modelName,
73
                    'title'       => $link['display'],
74
                    'count'       => $model::count(),
75
                    'showListUrl' => 'panel/' . $modelName . '/all',
76
                    'addUrl'      => 'panel/' . $modelName . '/edit',
77
                ];
78
            })
79
80
            ->toArray();
81
    }
82
}
83