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

JsonSerializationVisitorFactory   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 32
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 0
cbo 4
dl 32
loc 32
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A createService() 19 19 4

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
/**
3
 * @link    https://github.com/nnx-framework/jms-serializer-module
4
 * @author  Malofeykin Andrey  <[email protected]>
5
 */
6
namespace Nnx\JmsSerializerModule\Visitor;
7
8
use JMS\Serializer\JsonSerializationVisitor;
9
use Zend\ServiceManager\FactoryInterface;
10
use Zend\ServiceManager\MutableCreationOptionsInterface;
11
use Zend\ServiceManager\MutableCreationOptionsTrait;
12
use Zend\ServiceManager\ServiceLocatorInterface;
13
use Metadata\Driver\FileLocator;
14
15
/**
16
 * Class FileLocatorFactory
17
 *
18
 * @package Nnx\JmsSerializerModule\Visitor
19
 */
20 View Code Duplication
class JsonSerializationVisitorFactory 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, NamingStrategyTrait;
23
24
    /**
25
     * @param ServiceLocatorInterface $serviceLocator
26
     *
27
     * @return FileLocator
28
     * @throws \Zend\ServiceManager\Exception\ServiceNotFoundException
29
     * @throws \Nnx\JmsSerializerModule\Visitor\Exception\RuntimeException
30
     * @throws \Nnx\JmsSerializerModule\MetadataDriver\Exception\RuntimeException
31
     */
32
    public function createService(ServiceLocatorInterface $serviceLocator)
33
    {
34
        $namingStrategy = $this->getNamingStrategyFromContainer($serviceLocator);
35
        $visitor = new JsonSerializationVisitor($namingStrategy);
36
37
        $creationOptions = $this->getCreationOptions();
38
        if (array_key_exists('jsonOptions', $creationOptions)) {
39
            $jsonOptions = $creationOptions['jsonOptions'];
40
            if (!is_array($jsonOptions)) {
41
                $errMsg = 'Json options is not array';
42
                throw new Exception\RuntimeException($errMsg);
43
            }
44
            if (array_key_exists('options', $jsonOptions)) {
45
                $visitor->setOptions($jsonOptions['options']);
46
            }
47
        }
48
49
        return $visitor;
50
    }
51
}
52