GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 103a86...2f9008 )
by Bram
07:42 queued 05:18
created

CacheServiceFactory   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 79
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 7

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 9
c 1
b 0
f 0
lcom 0
cbo 7
dl 0
loc 79
ccs 0
cts 31
cp 0
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A createService() 0 4 1
A __invoke() 0 12 1
A setupIdGenerator() 0 14 2
B attachStrategiesToEventManager() 0 26 5
1
<?php
2
/**
3
 * @author        Bram Gerritsen [email protected]
4
 * @copyright (c) Bram Gerritsen 2013
5
 * @license       http://opensource.org/licenses/mit-license.php
6
 */
7
8
namespace StrokerCache\Factory;
9
10
use Interop\Container\ContainerInterface;
11
use Interop\Container\Exception\ContainerException;
12
use StrokerCache\Exception\RuntimeException;
13
use StrokerCache\IdGenerator\IdGeneratorPluginManager;
14
use StrokerCache\Listener\ShouldCacheStrategyListener;
15
use StrokerCache\Options\ModuleOptions;
16
use StrokerCache\Service\CacheService;
17
use StrokerCache\Strategy\CacheStrategyPluginManager;
18
use Zend\EventManager\ListenerAggregateInterface;
19
use Zend\ServiceManager\Exception\ServiceNotCreatedException;
20
use Zend\ServiceManager\Exception\ServiceNotFoundException;
21
use Zend\ServiceManager\FactoryInterface;
22
use Zend\ServiceManager\ServiceLocatorInterface;
23
24
class CacheServiceFactory implements FactoryInterface
1 ignored issue
show
Deprecated Code introduced by
The interface Zend\ServiceManager\FactoryInterface has been deprecated with message: Use Zend\ServiceManager\Factory\FactoryInterface instead.

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
25
{
26
    /**
27
     * {@inheritDoc}
28
     */
29
    public function createService(ServiceLocatorInterface $serviceLocator)
30
    {
31
        return $this($serviceLocator, CacheService::class);
32
    }
33
34
    /**
35
     * {@inheritDoc}
36
     */
37
    public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
38
    {
39
        $options      = $container->get(ModuleOptions::class);
40
        $cacheStorage = $container->get('StrokerCache\Storage\CacheStorage');
41
42
        $cacheService = new CacheService($cacheStorage, $options);
43
44
        $this->setupIdGenerator($cacheService, $options, $container);
45
        $this->attachStrategiesToEventManager($cacheService, $options, $container);
46
47
        return $cacheService;
48
    }
49
50
    /**
51
     * @param CacheService            $cacheService
52
     * @param ModuleOptions           $options
53
     * @param ContainerInterface      $container
54
     * @throws RuntimeException
55
     */
56
    protected function setupIdGenerator(
57
        CacheService $cacheService,
58
        ModuleOptions $options,
59
        ContainerInterface $container
60
    ) {
61
        $idGenerator        = $options->getIdGenerator();
62
        $idGeneratorManager = $container->get(IdGeneratorPluginManager::class);
63
64
        if ($idGeneratorManager->has($idGenerator)) {
65
            $cacheService->setIdGenerator($idGeneratorManager->get($idGenerator));
66
        } else {
67
            throw new RuntimeException('No IdGenerator register for key ' . $idGenerator);
68
        }
69
    }
70
71
    /**
72
     * @param CacheService            $cacheService
73
     * @param ModuleOptions           $options
74
     * @param ContainerInterface      $container
75
     */
76
    protected function attachStrategiesToEventManager(
77
        CacheService $cacheService,
78
        ModuleOptions $options,
79
        ContainerInterface $container
80
    ) {
81
        // Register enabled strategies on the cacheListener
82
        $strategies = $options->getStrategies();
83
        if (isset($strategies['enabled'])) {
84
            /** @var $strategyPluginManager CacheStrategyPluginManager */
85
            $strategyPluginManager = $container->get(CacheStrategyPluginManager::class);
86
87
            foreach ($strategies['enabled'] as $alias => $options) {
88
                if (is_numeric($alias)) {
89
                    $alias = $options;
90
                }
91
                $strategy = $strategyPluginManager->get($alias, $options);
92
93
                if ($strategy instanceof ListenerAggregateInterface) {
94
                    $listener = $strategy;
95
                } else {
96
                    $listener = new ShouldCacheStrategyListener($strategy);
97
                }
98
                $listener->attach($cacheService->getEventManager());
99
            }
100
        }
101
    }
102
}
103