Failed Conditions
Pull Request — master (#10)
by Maximo
03:08
created

ModelsMetadataProvider   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Test Coverage

Coverage 42.86%

Importance

Changes 0
Metric Value
eloc 19
dl 0
loc 34
ccs 6
cts 14
cp 0.4286
rs 10
c 0
b 0
f 0
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A register() 0 29 2
1
<?php
0 ignored issues
show
Coding Style introduced by
End of line character is invalid; expected "\n" but found "\r\n"
Loading history...
2
3
declare(strict_types=1);
4
5
namespace Gewaer\Providers;
6
7
use function Gewaer\Core\envValue;
8
use Phalcon\Di\ServiceProviderInterface;
9
use Phalcon\DiInterface;
10
use Phalcon\Mvc\Model\MetaData\Libmemcached;
11
use Phalcon\Mvc\Model\Metadata\Memory as MemoryMetaDataAdapter;
12
use Gewaer\Constants\Flags;
13
14
class ModelsMetadataProvider implements ServiceProviderInterface
15
{
16
    /**
17
     * @param DiInterface $container
18
     */
19 11
    public function register(DiInterface $container)
20
    {
21 4
        $config = $container->getShared('config');
22
23 4
        $container->setShared(
24 4
            'modelsMetadata',
25
            function () use ($config) {
26 11
                if (strtolower($config->app->env) != Flags::PRODUCTION) {
27 11
                    return new MemoryMetaDataAdapter();
28
                }
29
30
                $prefix = 'metadata';
31
                $backOptions = [
32
                    'servers' => [
33
                        0 => [
34
                            'host' => envValue('DATA_API_MEMCACHED_HOST', '127.0.0.1'),
35
                            'port' => envValue('DATA_API_MEMCACHED_PORT', 11211),
36
                            'weight' => envValue('DATA_API_MEMCACHED_WEIGHT', 100),
37
                        ],
38
                    ],
39
                    'client' => [
40
                        \Memcached::OPT_HASH => \Memcached::HASH_MD5,
41
                        \Memcached::OPT_PREFIX_KEY => 'bakaapi-',
42
                    ],
43
                    'lifetime' => 3600,
44
                    'prefix' => $prefix . '-',
45
                ];
46
47
                return new Libmemcached($backOptions);
48 4
            }
49
        );
50 4
    }
51
}
52