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::isLinkExist()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.9
c 0
b 0
f 0
cc 2
nc 2
nop 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
}