Completed
Push — travis ( 254a42 )
by Akihito
02:20
created

ProdModule   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 51.72%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 6
c 3
b 0
f 0
lcom 1
cbo 2
dl 0
loc 47
ccs 15
cts 29
cp 0.5172
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A installFileCache() 0 12 1
A configure() 0 15 4
A installApcCache() 0 12 1
1
<?php
2
/**
3
 * This file is part of the BEAR.Package package.
4
 *
5
 * @license http://opensource.org/licenses/MIT MIT
6
 */
7
namespace BEAR\Package\Context;
8
9
use BEAR\Package\Context\Provider\FilesystemCacheProvider;
10
use BEAR\RepositoryModule\Annotation\Storage;
11
use BEAR\Resource\Annotation\LogicCache;
12
use Doctrine\Common\Annotations\AnnotationReader;
13
use Doctrine\Common\Annotations\CachedReader;
14
use Doctrine\Common\Annotations\Reader;
15
use Doctrine\Common\Cache\ApcCache;
16
use Doctrine\Common\Cache\ApcuCache;
17
use Doctrine\Common\Cache\Cache;
18
use Doctrine\Common\Cache\CacheProvider;
19
use Doctrine\Common\Cache\FileCache;
20
use Doctrine\Common\Cache\FilesystemCache;
21
use Ray\Di\AbstractModule;
22
use Ray\Di\Scope;
23
24
class ProdModule extends AbstractModule
25
{
26
    /**
27
     * {@inheritdoc}
28
     */
29 1
    protected function configure()
30
    {
31 1
        if (function_exists('apcu_fetch') && class_exists(ApcuCache::class)) {
32
            $this->installApcCache(ApcuCache::class);
33
34
            return;
35
        }
36 1
        if (function_exists('apc_fetch')) {
37
            $this->installApcCache(ApcCache::class);
38
39
            return;
40
        }
41 1
        $this->installFileCache();
42
43 1
    }
44
45
    private function installApcCache($apcClass)
46
    {
47
        $this->bind(Cache::class)->to($apcClass)->in(Scope::SINGLETON);
48
        $this->bind(Reader::class)->toConstructor(
49
            CachedReader::class,
50
            'reader=annotation_reader'
51
        );
52
        $this->bind(Reader::class)->annotatedWith('annotation_reader')->to(AnnotationReader::class);
53
        $this->bind(CacheProvider::class)->annotatedWith(Storage::class)->to($apcClass)->in(Scope::SINGLETON);
54
        $this->bind(Cache::class)->annotatedWith(LogicCache::class)->to($apcClass)->in(Scope::SINGLETON);
55
        $this->bind(Cache::class)->annotatedWith(Storage::class)->to($apcClass)->in(Scope::SINGLETON);
56
    }
57
58 1
    private function installFileCache()
59
    {
60 1
        $this->bind(Cache::class)->toProvider(FilesystemCacheProvider::class)->in(Scope::SINGLETON);
61 1
        $this->bind(Reader::class)->toConstructor(
62 1
            CachedReader::class,
63
            'reader=annotation_reader'
64 1
        );
65 1
        $this->bind(Reader::class)->annotatedWith('annotation_reader')->to(AnnotationReader::class);
66 1
        $this->bind(CacheProvider::class)->annotatedWith(Storage::class)->toProvider(FilesystemCacheProvider::class)->in(Scope::SINGLETON);
67 1
        $this->bind(Cache::class)->annotatedWith(LogicCache::class)->toProvider(FilesystemCacheProvider::class)->in(Scope::SINGLETON);
68 1
        $this->bind(Cache::class)->annotatedWith(Storage::class)->toProvider(FilesystemCacheProvider::class)->in(Scope::SINGLETON);
69 1
    }
70
}
71