Passed
Pull Request — develop (#349)
by Schlaefer
15:02 queued 10s
created

Plugin   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Test Coverage

Coverage 83.33%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
eloc 15
c 3
b 0
f 0
dl 0
loc 32
ccs 10
cts 12
cp 0.8333
rs 10
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A onPluginsLoaded() 0 20 3
1
<?php
2
/**
3
 * Plugin class
4
 */
5
namespace Phile\Plugin\Phile\PhpFastCache;
6
7
use Phile\Core\ServiceLocator;
8
use Phile\Plugin\AbstractPlugin;
9
10
/**
11
 * Class Plugin
12
 * Default Phile cache engine
13
 *
14
 * @author  PhileCMS
15
 * @link    https://philecms.github.io
16
 * @license http://opensource.org/licenses/MIT
17
 * @package Phile\Plugin\Phile\PhpFastCache
18
 */
19
class Plugin extends AbstractPlugin
20
{
21
    /**
22
     * {@inheritDoc}
23
     */
24
    protected $events = ['plugins_loaded' => 'onPluginsLoaded'];
25
26
    /**
27
     * onPluginsLoaded method
28
     *
29
     * @return void
30
     */
31 31
    public function onPluginsLoaded()
32
    {
33 31
        $storage = $this->settings['storage'];
34 31
        $config = $this->settings;
35
36 31
        if (!empty($config['phpFastCacheConfig'])) {
37
            $cacheConfig = $config['phpFastCacheConfig'];
38
        } else {
39
            // Remove options unknown to Phpfastcache triggering errors
40 31
            unset($config['active'], $config['storage']);
41 31
            if ($storage == 'files') {
42
                $cacheConfig = new \Phpfastcache\Drivers\Files\Config($config);
43
            } else {
44 31
                $cacheConfig = new \Phpfastcache\Config\ConfigurationOption($config);
45
            }
46
        }
47
48 31
        $psr16Cache = new \Phpfastcache\Helper\Psr16Adapter($storage, $cacheConfig);
49 31
        $phileCache = new PhileToPsr16CacheAdapter($psr16Cache);
50 31
        ServiceLocator::registerService('Phile_Cache', $phileCache);
51
    }
52
}
53