Completed
Push — master ( 59d725...9f24e3 )
by Alex
17s queued 14s
created

MetadataBaseProvider::checkClassMap()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 4
c 1
b 0
f 1
dl 0
loc 6
rs 10
cc 2
nc 2
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace AlgoWeb\PODataLaravel\Providers;
6
7
use Illuminate\Contracts\Foundation\Application;
8
use Illuminate\Support\Facades\App;
9
use Illuminate\Support\Facades\Cache;
10
use Illuminate\Support\ServiceProvider;
11
12
abstract class MetadataBaseProvider extends ServiceProvider
13
{
14
    /** @var Application */
15
    protected $app;
16
17
    /**
18
     * @return bool
19
     */
20
    protected function getIsCaching()
21
    {
22
        return true === env('APP_METADATA_CACHING', false);
23
    }
24
25
    /**
26
     * @param bool      $isCaching
27
     * @param bool|null $hasCache
28
     * @param string    $key
29
     * @param $meta
30
     */
31
    protected function handlePostBoot(bool $isCaching, $hasCache, string $key, $meta)
32
    {
33
        if (!$isCaching) {
34
            Cache::forget($key);
35
            return;
36
        }
37
        $hasCache = isset($hasCache) ? boolval($hasCache) : false;
38
        if (!$hasCache) {
39
            $cacheTime = abs(intval(env('APP_METADATA_CACHE_DURATION', 10)));
40
            $cacheTime = max($cacheTime, 1);
41
            Cache::put($key, $meta, $cacheTime);
42
        }
43
    }
44
45
    protected function getAppNamespace()
46
    {
47
        try {
48
            $startName = App::getNamespace();
49
        } catch (\Exception $e) {
50
            $startName = 'App';
51
        }
52
        return $startName;
53
    }
54
}
55