XmlDeserializationVisitorFactory::createService()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 18
Code Lines 11

Duplication

Lines 18
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 18
loc 18
rs 9.4285
cc 3
eloc 11
nc 3
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\Visitor;
7
8
use JMS\Serializer\XmlDeserializationVisitor;
9
use Zend\ServiceManager\FactoryInterface;
10
use Zend\ServiceManager\MutableCreationOptionsInterface;
11
use Zend\ServiceManager\MutableCreationOptionsTrait;
12
use Zend\ServiceManager\ServiceLocatorInterface;
13
14
/**
15
 * Class XmlDeserializationVisitorFactory
16
 *
17
 * @package Nnx\JmsSerializerModule\Visitor
18
 */
19 View Code Duplication
class XmlDeserializationVisitorFactory 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...
20
{
21
    use MutableCreationOptionsTrait, NamingStrategyTrait;
22
23
    /**
24
     * @param ServiceLocatorInterface $serviceLocator
25
     *
26
     * @return XmlDeserializationVisitor
27
     * @throws \Zend\ServiceManager\Exception\ServiceNotFoundException
28
     * @throws \Nnx\JmsSerializerModule\Visitor\Exception\RuntimeException
29
     */
30
    public function createService(ServiceLocatorInterface $serviceLocator)
31
    {
32
        $creationOptions = $this->getCreationOptions();
33
34
        $namingStrategy = $this->getNamingStrategyFromContainer($serviceLocator);
35
        $xmlDeserializationVisitor = new XmlDeserializationVisitor($namingStrategy);
36
37
        if (array_key_exists('doctypeWhitelist', $creationOptions)) {
38
            $doctypeWhitelist = $creationOptions['doctypeWhitelist'];
39
            if (!is_array($doctypeWhitelist)) {
40
                $errMsg = 'Doctype whitelist not array';
41
                throw new Exception\RuntimeException($errMsg);
42
            }
43
            $xmlDeserializationVisitor->setDoctypeWhitelist($doctypeWhitelist);
44
        }
45
46
        return $xmlDeserializationVisitor;
47
    }
48
}
49