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.

Link   A
last analyzed

Complexity

Total Complexity 14

Size/Duplication

Total Lines 75
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 14
lcom 1
cbo 1
dl 0
loc 75
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getAllLinks() 0 7 3
A getUrls() 0 8 3
A getMainUrls() 0 8 3
A addNewLink() 0 18 3
A isLinkExist() 0 11 2
1
<?php
2
namespace Serverfireteam\Panel;
3
4
use Carbon\Carbon;
5
use Illuminate\Database\Eloquent\Model;
6
7
class Link extends Model {
8
9
    protected $fillable = ['url', 'display', 'show_menu'];
10
11
    protected $table = 'links';
12
    
13
    static $cache = [];
14
    public static function getAllLinks($forceRefresh = false) // allCached(
15
    {
16
        if (!isset(self::$cache['all']) || $forceRefresh) {
17
            self::$cache['all'] = Link::all();
18
        }
19
        return self::$cache['all'];
20
    }
21
    public static function getUrls($forceRefresh = false) // returnUrls(
22
    {
23
        if (!isset(self::$cache['all_urls']) || $forceRefresh) {
24
            $configs = Link::getAllLinks($forceRefresh);
25
            self::$cache['all_urls'] =  $configs->pluck('url')->toArray();
26
        }
27
        return self::$cache['all_urls'];
28
    }
29
    public static function getMainUrls($forceRefresh = false)
30
    {
31
        if (!isset(self::$cache['main_urls']) || $forceRefresh) {
32
            $configs = Link::where('main', '=', true)->get(['url']);
33
            self::$cache['main_urls'] = $configs->pluck('url')->toArray();
34
        }
35
        return self::$cache['main_urls'];
36
    }
37
38
    /**
39
     * insert new link. this function don't need to use save()
40
     * @param $url
41
     * @param $label
42
     * @param $visibility
43
     * @param bool $checkExistence
44
     */
45
    public function addNewLink($url, $label, $visibility, $checkExistence = false) // getAndSave(
46
    {
47
        if ($checkExistence && $this->isLinkExist($url, $label))
48
        {
49
            return;
50
        }
51
        $now = Carbon::now()->toDateTimeString();
52
        $data = array(
53
            array(
54
                'url'=>$url,
55
                'display'=>$label,
56
                'show_menu'=>$visibility,
57
                'created_at'=> $now,
58
                'updated_at'=> $now
59
            )
60
        );
61
        Link::insert($data);
62
    }
63
64
    /**
65
     * check given url and display label if they added before
66
     * @param $url
67
     * @param $label
68
     * @return bool
69
     */
70
    public function isLinkExist($url, $label)
71
    {
72
        //if you call exists() against a non existent record then it gives error: Call to a member function exists() on null
73
        //Link::where('url', '=', $url)->exists()
74
        $linkCount = Link::where('url', '=', $url)->where('display', '=', $label)->count(); //->first(); if ($link === null)
75
        if ($linkCount <= 0) {
76
            // link doesn't exist
77
            return false;
78
        }
79
        return true;
80
    }
81
}