DoctrineMongodDBFactory   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 4
dl 0
loc 33
ccs 0
cts 19
cp 0
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getAdapter() 0 7 1
A configureOptionResolver() 0 7 1
A verifyDependencies() 0 8 2
1
<?php
2
3
/*
4
 * This file is part of php-cache organization.
5
 *
6
 * (c) 2015 Aaron Scherer <[email protected]>, Tobias Nyholm <[email protected]>
7
 *
8
 * This source file is subject to the MIT license that is bundled
9
 * with this source code in the file LICENSE.
10
 */
11
12
namespace Cache\AdapterBundle\Factory;
13
14
use Cache\Adapter\Doctrine\DoctrineCachePool;
15
use Doctrine\Common\Cache\MongoDBCache;
16
use MongoClient;
17
use Symfony\Component\OptionsResolver\OptionsResolver;
18
19
/**
20
 * @author Tobias Nyholm <[email protected]>
21
 */
22
final class DoctrineMongodDBFactory extends AbstractDoctrineAdapterFactory
23
{
24
    /**
25
     * {@inheritdoc}
26
     */
27
    public function getAdapter(array $config)
28
    {
29
        $mongo = new MongoClient();
30
        $collection = $mongo->selectCollection($config['host'], $config['collection']);
31
32
        return new DoctrineCachePool(new MongoDBCache($collection));
33
    }
34
35
    /**
36
     * {@inheritdoc}
37
     */
38
    protected static function configureOptionResolver(OptionsResolver $resolver)
39
    {
40
        $resolver->setRequired(['host', 'collection']);
41
42
        $resolver->setAllowedTypes('host', ['string']);
43
        $resolver->setAllowedTypes('collection', ['string']);
44
    }
45
46
    protected static function verifyDependencies()
47
    {
48
        if (!version_compare(phpversion('mongo'), '1.3.0', '>=')) {
49
            throw new \LogicException('Mongo >= 1.3.0 is required.');
50
        }
51
52
        parent::verifyDependencies();
53
    }
54
}
55