Passed
Push — clean ( 020cee...b072b2 )
by Akihito
06:30
created

ProdModule   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 54.17%

Importance

Changes 6
Bugs 0 Features 0
Metric Value
wmc 5
c 6
b 0
f 0
lcom 1
cbo 2
dl 0
loc 40
ccs 13
cts 24
cp 0.5417
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 10 3
A installApcuCache() 0 11 1
A installFileCache() 0 11 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 Doctrine\Common\Annotations\AnnotationReader;
12
use Doctrine\Common\Annotations\CachedReader;
13
use Doctrine\Common\Annotations\Reader;
14
use Doctrine\Common\Cache\ApcuCache;
15
use Doctrine\Common\Cache\Cache;
16
use Doctrine\Common\Cache\CacheProvider;
17
use Ray\Di\AbstractModule;
18
use Ray\Di\Scope;
19
20
class ProdModule extends AbstractModule
21
{
22
    /**
23
     * {@inheritdoc}
24
     */
25 1
    protected function configure()
26
    {
27 1
        if (function_exists('apcu_fetch') && class_exists(ApcuCache::class)) {
28
            $this->installApcuCache(ApcuCache::class);
29
30
            return;
31
        }
32
33 1
        $this->installFileCache();
34 1
    }
35
36
    private function installApcuCache($apcClass)
37
    {
38
        $this->bind(Cache::class)->to($apcClass)->in(Scope::SINGLETON);
39
        $this->bind(Reader::class)->toConstructor(
40
            CachedReader::class,
41
            'reader=annotation_reader'
42
        );
43
        $this->bind(Reader::class)->annotatedWith('annotation_reader')->to(AnnotationReader::class);
44
        $this->bind(CacheProvider::class)->annotatedWith(Storage::class)->to($apcClass)->in(Scope::SINGLETON);
45
        $this->bind(Cache::class)->annotatedWith(Storage::class)->to($apcClass)->in(Scope::SINGLETON);
46
    }
47
48 1
    private function installFileCache()
49
    {
50 1
        $this->bind(Cache::class)->toProvider(FilesystemCacheProvider::class)->in(Scope::SINGLETON);
51 1
        $this->bind(Reader::class)->toConstructor(
52 1
            CachedReader::class,
53
            'reader=annotation_reader'
54 1
        );
55 1
        $this->bind(Reader::class)->annotatedWith('annotation_reader')->to(AnnotationReader::class);
56 1
        $this->bind(CacheProvider::class)->annotatedWith(Storage::class)->toProvider(FilesystemCacheProvider::class)->in(Scope::SINGLETON);
57 1
        $this->bind(Cache::class)->annotatedWith(Storage::class)->toProvider(FilesystemCacheProvider::class)->in(Scope::SINGLETON);
58 1
    }
59
}
60