SettingRepository   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 19
c 1
b 0
f 1
dl 0
loc 45
rs 10
wmc 6

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getSetting() 0 18 1
A getCacheSetting() 0 13 3
A getModelClass() 0 3 1
A __construct() 0 3 1
1
<?php
2
3
namespace App\Repositories;
4
5
use App\Setting as Model;
6
use Cache;
7
8
class SettingRepository extends InitRepository
9
{
10
    public function __construct()
11
    {
12
        parent::__construct();
13
    }
14
15
    protected function getModelClass()
16
    {
17
        return Model::class;
18
    }
19
20
    public function getSetting()
21
    {
22
        $columns = [
23
      // 'id',
24
      'name',
25
      'value',
26
    ];
27
28
        $result = $this->startConditions()
29
      ->select($columns)
0 ignored issues
show
Bug introduced by
The method select() does not exist on Illuminate\Contracts\Foundation\Application. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

29
      ->/** @scrutinizer ignore-call */ select($columns)

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
30
      ->get();
31
32
        $setting = $result->mapWithKeys(function ($item) {
33
            return [$item['name'] => $item['value']];
34
        });
35
36
        // dd($setting);
37
        return $setting;
38
    }
39
40
    public function getCacheSetting()
41
    {
42
        $cache_name = 'setting';
43
44
        if (Cache::has($cache_name) && !Cache::get($cache_name)->isEmpty()) {
45
            $data_cache = Cache::get($cache_name);
46
        } else {
47
            $data_cache = Cache::remember($cache_name, $this->cache_time_forever, function () {
48
                return $this->getSetting();
49
            });
50
        }
51
52
        return $data_cache;
53
    }
54
}
55