ModelsCacheProvider   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 16
c 2
b 0
f 0
dl 0
loc 31
rs 10
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A register() 0 26 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Canvas\Providers;
6
7
use function Canvas\Core\envValue;
8
9
use Canvas\Constants\Flags;
10
use Phalcon\Cache\Backend\Memory;
0 ignored issues
show
Bug introduced by
The type Phalcon\Cache\Backend\Memory was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
11
use Phalcon\Cache\Backend\Redis;
0 ignored issues
show
Bug introduced by
The type Phalcon\Cache\Backend\Redis was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
12
use Phalcon\Cache\Frontend\Data;
0 ignored issues
show
Bug introduced by
The type Phalcon\Cache\Frontend\Data was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
13
use Phalcon\Cache\Frontend\None;
0 ignored issues
show
Bug introduced by
The type Phalcon\Cache\Frontend\None was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
14
use Phalcon\DiInterface;
0 ignored issues
show
Bug introduced by
The type Phalcon\DiInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
15
use Phalcon\Di\ServiceProviderInterface;
0 ignored issues
show
Bug introduced by
The type Phalcon\Di\ServiceProviderInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
16
17
class ModelsCacheProvider implements ServiceProviderInterface
18
{
19
    /**
20
     * @param DiInterface $container
21
     */
22
    public function register(DiInterface $container)
23
    {
24
        $config = $container->get('config');
25
26
        $container->setShared(
27
            'modelsCache',
28
            function () use ($config) {
29
                if (strtolower($config->app->env) != Flags::PRODUCTION) {
30
                    $frontCache = new None();
31
                    $cache = new Memory($frontCache);
32
                } else {
33
                    $frontCache = new Data([
34
                        'lifetime' => envValue('MODELS_CACHE_LIFETIME', 86400),
35
                    ]);
36
37
                    $cache = new Redis(
38
                        $frontCache,
39
                        [
40
                            'host' => envValue('REDIS_HOST', '127.0.0.1'),
41
                            'port' => envValue('REDIS_PORT', 6379),
42
                            'prefix' => 'modelsCache',
43
                        ]
44
                    );
45
                }
46
47
                return $cache;
48
            }
49
        );
50
    }
51
}
52