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

FileLocatorFactory::createService()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 17
Code Lines 10

Duplication

Lines 17
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 17
loc 17
rs 9.4285
cc 3
eloc 10
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\MetadataDriver;
7
8
use Zend\ServiceManager\FactoryInterface;
9
use Zend\ServiceManager\MutableCreationOptionsInterface;
10
use Zend\ServiceManager\MutableCreationOptionsTrait;
11
use Zend\ServiceManager\ServiceLocatorInterface;
12
use Metadata\Driver\FileLocator;
13
14
15
/**
16
 * Class FileLocatorFactory
17
 *
18
 * @package Nnx\JmsSerializerModule\MetadataDriver
19
 */
20 View Code Duplication
class FileLocatorFactory 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 FileLocator
28
     * @throws \Nnx\JmsSerializerModule\MetadataDriver\Exception\RuntimeException
29
     */
30
    public function createService(ServiceLocatorInterface $serviceLocator)
31
    {
32
        $creationOptions = $this->getCreationOptions();
33
34
        if (!array_key_exists('directories', $creationOptions)) {
35
            $errMsg = 'Directories for FileLocator is not specified';
36
            throw new Exception\RuntimeException($errMsg);
37
        }
38
        $directories = $creationOptions['directories'];
39
40
        if (!is_array($directories)) {
41
            $errMsg = 'Directories for FileLocator is not array';
42
            throw new Exception\RuntimeException($errMsg);
43
        }
44
45
        return new FileLocator($directories);
46
    }
47
}
48