Completed
Push — 7.4 ( 310a44...3b2076 )
by Nikolaos
05:19
created

AdapterFactory   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 90.91%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 1
dl 0
loc 52
ccs 10
cts 11
cp 0.9091
c 0
b 0
f 0
rs 10
1
<?php
2
3
/**
4
 * This file is part of the Phalcon Framework.
5
 *
6
 * (c) Phalcon Team <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE.txt
9
 * file that was distributed with this source code.
10
 */
11
12
declare(strict_types=1);
13
14
namespace Phalcon\Cache;
15
16
use Phalcon\Cache\Adapter\AdapterInterface;
17
use Phalcon\Factory\AbstractFactory;
18
use Phalcon\Factory\Exception;
19
use Phalcon\Storage\SerializerFactory;
20
21
/**
22
 * Factory to create Cache adapters
23
 *
24
 * @property SerializerFactory|null $serializerFactory
25
 */
26
class AdapterFactory extends AbstractFactory
27
{
28
    /**
29
     * @var SerializerFactory|null
30
     */
31
    private ?SerializerFactory $serializerFactory;
0 ignored issues
show
Bug introduced by
This code did not parse for me. Apparently, there is an error somewhere around this line:

Syntax error, unexpected '?', expecting T_FUNCTION or T_CONST
Loading history...
32
33
    /**
34
     * AdapterFactory constructor.
35
     *
36
     * @param SerializerFactory|null $factory
37
     * @param array                  $services
38
     */
39 22
    public function __construct(SerializerFactory $factory = null, array $services = [])
40
    {
41 22
        $this->serializerFactory = $factory;
42
43 22
        $this->init($services);
44 22
    }
45
46
    /**
47
     * Create a new instance of the adapter
48
     *
49
     * @param string $name
50
     * @param array  $options
51
     *
52
     * @return AdapterInterface
53
     * @throws Exception
54
     */
55 22
    public function newInstance(string $name, array $options = []): AdapterInterface
56
    {
57 22
        $this->checkService($name);
58
59 21
        $definition = $this->mapper[$name];
60
61 21
        return new $definition($this->serializerFactory, $options);
62
    }
63
64
    /**
65
     * Returns the available adapters
66
     */
67 22
    protected function getAdapters(): array
68
    {
69
        return [
70 22
            "apcu"         => 'Phalcon\Cache\Adapter\Apcu',
71
            "libmemcached" => 'Phalcon\Cache\Adapter\Libmemcached',
72
            "memory"       => 'Phalcon\Cache\Adapter\Memory',
73
            "redis"        => 'Phalcon\Cache\Adapter\Redis',
74
            "stream"       => 'Phalcon\Cache\Adapter\Stream',
75
        ];
76
    }
77
}
78