Completed
Push — master ( 0ced52...d99b90 )
by Markus
03:30
created

LockSymfonyServiceProvider   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
eloc 8
dl 0
loc 38
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A createSymfonyLockFactory() 0 5 1
A register() 0 3 1
A createLockFactory() 0 9 1
1
<?php
2
3
namespace Jellyfish\LockSymfony;
4
5
use Pimple\Container;
6
use Pimple\ServiceProviderInterface;
7
use Symfony\Component\Lock\Factory as SymfonyLockFactory;
8
use Symfony\Component\Lock\Store\RedisStore;
9
10
class LockSymfonyServiceProvider implements ServiceProviderInterface
11
{
12
    /**
13
     * @param \Pimple\Container $pimple
14
     *
15
     * @return void
16
     */
17
    public function register(Container $pimple): void
18
    {
19
        $this->createLockFactory($pimple);
20
    }
21
22
    /**
23
     * @param \Pimple\Container $container
24
     *
25
     * @return \Pimple\ServiceProviderInterface
26
     */
27
    protected function createLockFactory(Container $container): ServiceProviderInterface
28
    {
29
        $self = $this;
30
31
        $container->offsetSet('lock_factory', function (Container $container) use ($self) {
32
            return new LockFactory($self->createSymfonyLockFactory($container));
33
        });
34
35
        return $this;
36
    }
37
38
    /**
39
     * @param \Pimple\Container $container
40
     *
41
     * @return \Symfony\Component\Lock\Factory
42
     */
43
    protected function createSymfonyLockFactory(Container $container): SymfonyLockFactory
44
    {
45
        $redisStore = new RedisStore($container->offsetGet('redis_client'));
46
47
        return new SymfonyLockFactory($redisStore);
48
    }
49
}
50