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

FileLocatorFactory   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 28
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A createService() 17 17 3

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\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