CacheStorageFactory::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 4
rs 10
1
<?php
2
3
/**
4
 * This file is part of the bugloos/fault-tolerance-bundle project.
5
 * (c) Bugloos <https://bugloos.com/>
6
 * For the full copyright and license information, please view
7
 * the LICENSE file that was distributed with this source code.
8
 */
9
10
namespace Bugloos\FaultToleranceBundle\RequestCache\Storage;
11
12
use Exception;
13
14
/**
15
 * @author Mojtaba Gheytasi <[email protected]>
16
 */
17
class CacheStorageFactory
18
{
19
    private string $redisUrl;
20
21
    private string $mongodbUrl;
22
23
    public function __construct(string $redisUrl = '', string $mongodbUrl = '')
24
    {
25
        $this->redisUrl = $redisUrl;
26
        $this->mongodbUrl = $mongodbUrl;
27
    }
28
29
    /**
30
     * @param string $storage
31
     *
32
     * @return StorageInterface
33
     *
34
     * @throws Exception
35
     */
36
    public function create(string $storage): StorageInterface
37
    {
38
        switch ($storage) {
39
            case 'redis':
40
                return new RedisStorage($this->redisUrl);
41
            case 'mongodb':
42
                return new MongoDbStorage($this->mongodbUrl);
43
            default:
44
                throw new Exception();
45
        }
46
    }
47
}
48