MetadataBaseProvider   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Importance

Changes 4
Bugs 0 Features 1
Metric Value
wmc 6
eloc 12
c 4
b 0
f 1
dl 0
loc 39
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getAppNamespace() 0 3 1
A handlePostBoot() 0 11 4
A getIsCaching() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace AlgoWeb\PODataLaravel\Providers;
6
7
use AlgoWeb\PODataLaravel\Controllers\MetadataControllerContainer;
8
use AlgoWeb\PODataLaravel\Models\ClassReflectionHelper;
9
use AlgoWeb\PODataLaravel\Models\IMetadataRelationshipContainer;
10
use AlgoWeb\PODataLaravel\Models\ObjectMap\Map;
11
use Illuminate\Contracts\Foundation\Application;
12
use Illuminate\Support\Facades\App;
13
use Illuminate\Support\Facades\Cache;
14
use Illuminate\Support\ServiceProvider;
15
16
abstract class MetadataBaseProvider extends ServiceProvider
17
{
18
    /** @var Application */
19
    protected $app;
20
21
    /**
22
     * @return bool
23
     */
24
    protected function getIsCaching()
25
    {
26
        return true === env('APP_METADATA_CACHING', false);
27
    }
28
29
    /**
30
     * @param bool          $isCaching
31
     * @param bool|null     $hasCache
32
     * @param string        $key
33
     * @param mixed         $meta
34
     */
35
    protected function handlePostBoot(bool $isCaching, ?bool $hasCache, string $key, $meta): void
36
    {
37
        if (!$isCaching) {
38
            Cache::forget($key);
39
            return;
40
        }
41
        $hasCache = isset($hasCache) ? boolval($hasCache) : false;
42
        if (!$hasCache) {
43
            $cacheTime = abs(intval(env('APP_METADATA_CACHE_DURATION', 10)));
44
            $cacheTime = max($cacheTime, 1);
45
            Cache::put($key, $meta, $cacheTime);
46
        }
47
    }
48
49
    /**
50
     * @return string
51
     */
52
    protected function getAppNamespace(): string
53
    {
54
        return ClassReflectionHelper::getAppNamespace();
55
    }
56
}
57