Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
60.00% covered (warning)
60.00%
3 / 5
0.00% covered (danger)
0.00%
0 / 1
CRAP
0.00% covered (danger)
0.00%
0 / 1
ConnectionFactory
60.00% covered (warning)
60.00%
3 / 5
0.00% covered (danger)
0.00%
0 / 1
8.30
0.00% covered (danger)
0.00%
0 / 1
 __construct
n/a
0 / 0
n/a
0 / 0
1
 create
60.00% covered (warning)
60.00%
3 / 5
0.00% covered (danger)
0.00%
0 / 1
6.60
1<?php
2/**
3 * Jingga
4 *
5 * PHP Version 8.1
6 *
7 * @package   phpOMS\DataStorage\Cache\Connection
8 * @copyright Dennis Eichhorn
9 * @license   OMS License 2.0
10 * @version   1.0.0
11 * @link      https://jingga.app
12 */
13declare(strict_types=1);
14
15namespace phpOMS\DataStorage\Cache\Connection;
16
17use phpOMS\DataStorage\Cache\CacheType;
18
19/**
20 * Cache connection factory.
21 *
22 * @package phpOMS\DataStorage\Cache\Connection
23 * @license OMS License 2.0
24 * @link    https://jingga.app
25 * @since   1.0.0
26 */
27class ConnectionFactory
28{
29    /**
30     * Constructor.
31     *
32     * @since 1.0.0
33     * @codeCoverageIgnore
34     */
35    private function __construct()
36    {
37    }
38
39    /**
40     * Create cache connection.
41     *
42     * @param string[] $cacheData the basic cache information for establishing a connection
43     *
44     * @return ConnectionInterface
45     *
46     * @throws \InvalidArgumentException throws this exception if the cache is not supported
47     *
48     * @since 1.0.0
49     */
50    public static function create(array $cacheData) : ConnectionInterface
51    {
52        switch ($cacheData['type'] ?? '') {
53            case CacheType::FILE:
54                return new FileCache($cacheData['path'] ?? '');
55            case CacheType::REDIS:
56                return new RedisCache($cacheData['data'] ?? []);
57            case CacheType::MEMCACHED:
58                return new MemCached($cacheData['data'] ?? []);
59            default:
60                throw new \InvalidArgumentException('Cache "' . ($cacheData['type'] ?? '') . '" is not supported.');
61        }
62    }
63}