Passed
Pull Request — master (#154)
by Alex
07:05
created

MetadataBaseProvider   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 8
c 0
b 0
f 0
dl 0
loc 47
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A handlePostBoot() 0 11 4
A getIsCaching() 0 3 1
A getClassMap() 0 12 3
1
<?php
2
3
namespace AlgoWeb\PODataLaravel\Providers;
4
5
use Illuminate\Support\Facades\Cache;
6
use Illuminate\Support\ServiceProvider;
7
8
abstract class MetadataBaseProvider extends ServiceProvider
9
{
10
11
    /**
12
     * @return bool
13
     */
14
    protected function getIsCaching()
15
    {
16
        return true === env('APP_METADATA_CACHING', false);
17
    }
18
19
    /**
20
     * @param $isCaching
21
     * @param $hasCache
22
     * @param $key
23
     * @param $meta
24
     */
25
    protected function handlePostBoot($isCaching, $hasCache, $key, $meta)
26
    {
27
        if ($isCaching) {
28
            assert(isset($hasCache));
0 ignored issues
show
Bug introduced by
The call to assert() has too few arguments starting with description. ( Ignorable by Annotation )

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

28
            /** @scrutinizer ignore-call */ 
29
            assert(isset($hasCache));

This check compares calls to functions or methods with their respective definitions. If the call has less arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
29
            if (!$hasCache) {
30
                $cacheTime = env('APP_METADATA_CACHE_DURATION', null);
31
                $cacheTime = !is_numeric($cacheTime) ? 10 : abs($cacheTime);
32
                Cache::put($key, $meta, $cacheTime);
33
            }
34
        } else {
35
            Cache::forget($key);
36
        }
37
    }
38
39
    /**
40
     * @param $classMap
41
     * @return array
42
     */
43
    protected function getClassMap()
44
    {
45
        $classes = get_declared_classes();
46
        $autoClass = null;
47
        foreach ($classes as $class) {
48
            if (\Illuminate\Support\Str::startsWith($class, 'Composer\\Autoload\\ComposerStaticInit')) {
49
                $autoClass = $class;
50
            }
51
        }
52
53
        $classes = $autoClass::$classMap;
54
        return array_keys($classes);
55
    }
56
}
57