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

CamelCaseNamingStrategyFactory::createService()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 16
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 16
rs 9.4285
cc 3
eloc 9
nc 4
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\CamelCaseNamingStrategy;
9
use Zend\ServiceManager\FactoryInterface;
10
use Zend\ServiceManager\MutableCreationOptionsInterface;
11
use Zend\ServiceManager\MutableCreationOptionsTrait;
12
use Zend\ServiceManager\ServiceLocatorInterface;
13
14
/**
15
 * Class CamelCaseNamingStrategyFactory
16
 *
17
 * @package Nnx\JmsSerializerModule\NamingStrategy
18
 */
19
class CamelCaseNamingStrategyFactory implements FactoryInterface, MutableCreationOptionsInterface
20
{
21
    use MutableCreationOptionsTrait;
22
23
    /**
24
     * @inheritdoc
25
     *
26
     * @param ServiceLocatorInterface $serviceLocator
27
     *
28
     * @return CamelCaseNamingStrategy
29
     */
30
    public function createService(ServiceLocatorInterface $serviceLocator)
31
    {
32
        $creationOptions = $this->getCreationOptions();
33
34
        $separator = '_';
35
        if (array_key_exists('separator', $creationOptions)) {
36
            $separator = (string)$creationOptions['separator'];
37
        }
38
39
        $lowerCase = true;
40
        if (array_key_exists('lowerCase', $creationOptions)) {
41
            $lowerCase = (boolean)$creationOptions['lowerCase'];
42
        }
43
44
        return new CamelCaseNamingStrategy($separator, $lowerCase);
45
    }
46
}
47