ContextBuilderFactory::createService()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 10
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 10
loc 10
rs 9.4285
cc 2
eloc 5
nc 2
nop 1
1
<?php
2
/**
3
 * @link    https://github.com/nnx-framework/form-comparator
4
 * @author  Malofeykin Andrey  <[email protected]>
5
 */
6
namespace Nnx\FormComparator\Context;
7
8
use Webmozart\Assert\Assert;
9
use Zend\ServiceManager\AbstractPluginManager;
10
use Zend\ServiceManager\FactoryInterface;
11
use Zend\ServiceManager\ServiceLocatorInterface;
12
use Zend\Form\FormElementManager;
13
14
/**
15
 * Class ContextBuilderFactory
16
 *
17
 * @package Nnx\FormComparator\Context
18
 */
19 View Code Duplication
class ContextBuilderFactory implements FactoryInterface
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
    /**
22
     * @inheritdoc
23
     *
24
     * @param ServiceLocatorInterface $serviceLocator
25
     *
26
     * @return ContextBuilder
27
     * @throws \Zend\ServiceManager\Exception\ServiceNotFoundException
28
     */
29
    public function createService(ServiceLocatorInterface $serviceLocator)
30
    {
31
        $appServiceLocator = $serviceLocator instanceof AbstractPluginManager ? $serviceLocator->getServiceLocator() : $serviceLocator;
32
33
        /** @var FormElementManager $formElementManager */
34
        $formElementManager = $appServiceLocator->get('FormElementManager');
35
        Assert::isInstanceOf($formElementManager, FormElementManager::class);
36
37
        return new ContextBuilder($formElementManager);
38
    }
39
40
}
41