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 ( 3569fe...568257 )
by Alireza
12s
created

Link   A

Complexity

Total Complexity 14

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 14
lcom 1
cbo 0
dl 0
loc 60
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 11 3
A isLinkExist() 0 11 2
1
<?php
2
namespace Serverfireteam\Panel;
3
4
use Illuminate\Database\Eloquent\Model;
5
6
class Link extends Model {
7
8
    protected $fillable = ['url', 'display', 'show_menu'];
9
10
    protected $table = 'links';
11
    
12
    static $cache = [];
13
    public static function getAllLinks($forceRefresh = false) // allCached(
14
    {
15
        if (!isset(self::$cache['all']) || $forceRefresh) {
16
            self::$cache['all'] = Link::all();
17
        }
18
        return self::$cache['all'];
19
    }
20
    public static function getUrls($forceRefresh = false) // returnUrls(
21
    {
22
        if (!isset(self::$cache['all_urls']) || $forceRefresh) {
23
            $configs = Link::getAllLinks($forceRefresh);
24
            self::$cache['all_urls'] =  $configs->pluck('url')->toArray();
25
        }
26
        return self::$cache['all_urls'];
27
    }
28
    public static function getMainUrls($forceRefresh = false)
29
    {
30
        if (!isset(self::$cache['main_urls']) || $forceRefresh) {
31
            $configs = Link::where('main', '=', true)->get(['url']);
32
            self::$cache['main_urls'] = $configs->pluck('url')->toArray();
33
        }
34
        return self::$cache['main_urls'];
35
    }
36
    public function addNewLink($url, $label, $visibility, $checkExistence = false) // getAndSave(
37
    {
38
        if ($checkExistence && $this->isLinkExist($url, $label))
39
        {
40
            return;
41
        }
42
        $this->url = $url;
43
        $this->display = $label;
44
        $this->show_menu = $visibility;
45
        $this->save();
46
    }
47
48
    /**
49
     * check given url and display label if they added before
50
     * @param $url
51
     * @param $label
52
     * @return bool
53
     */
54
    public function isLinkExist($url, $label)
55
    {
56
        //if you call exists() against a non existent record then it gives error: Call to a member function exists() on null
57
        //Link::where('url', '=', $url)->exists()
58
        $linkCount = Link::where('url', '=', $url)->where('display', '=', $label)->count(); //->first(); if ($link === null)
59
        if ($linkCount <= 0) {
60
            // link doesn't exist
61
            return false;
62
        }
63
        return true;
64
    }
65
}