Completed
Push — master ( 111bcd...99ca87 )
by Andrey
26:30
created

CacheNamingStrategyFactory::createService()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 15
Code Lines 8

Duplication

Lines 15
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 15
loc 15
rs 9.4285
cc 2
eloc 8
nc 2
nop 1
1
<?php
2
/**
3
 * @link    https://github.com/nnx-framework/jms-serializer-module
4
 * @author  Malofeykin Andrey  <[email protected]>
5
 */
6
namespace Nnx\JmsSerializerModule\NamingStrategy;
7
8
use JMS\Serializer\Naming\CacheNamingStrategy;
9
use JMS\Serializer\Naming\PropertyNamingStrategyInterface;
10
use Zend\ServiceManager\FactoryInterface;
11
use Zend\ServiceManager\MutableCreationOptionsInterface;
12
use Zend\ServiceManager\MutableCreationOptionsTrait;
13
use Zend\ServiceManager\ServiceLocatorInterface;
14
15
/**
16
 * Class CacheNamingStrategyFactory
17
 *
18
 * @package Nnx\JmsSerializerModule\NamingStrategy
19
 */
20 View Code Duplication
class CacheNamingStrategyFactory implements FactoryInterface, MutableCreationOptionsInterface
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
21
{
22
    use MutableCreationOptionsTrait;
23
24
    /**
25
     * @param ServiceLocatorInterface $serviceLocator
26
     *
27
     * @return CacheNamingStrategy
28
     * @throws \Zend\ServiceManager\Exception\ServiceNotFoundException
29
     * @throws \Nnx\JmsSerializerModule\NamingStrategy\Exception\RuntimeException
30
     */
31
    public function createService(ServiceLocatorInterface $serviceLocator)
32
    {
33
        $creationOptions = $this->getCreationOptions();
34
35
        if (!array_key_exists('delegate', $creationOptions)) {
36
            $errMsg = 'Delegate naming strategy not specified';
37
            throw new Exception\RuntimeException($errMsg);
38
        }
39
        $delegateName = $creationOptions['delegate'];
40
41
        /** @var PropertyNamingStrategyInterface $delegate */
42
        $delegate = $serviceLocator->get($delegateName);
43
44
        return new CacheNamingStrategy($delegate);
45
    }
46
}
47