FormAnnotationBuilderFactory::__invoke()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 9
ccs 5
cts 5
cp 1
rs 9.9666
c 0
b 0
f 0
cc 1
nc 1
nop 3
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace DoctrineORMModule\Service;
6
7
use DoctrineModule\Service\AbstractFactory;
8
use DoctrineORMModule\Form\Annotation\AnnotationBuilder;
9
use Interop\Container\ContainerInterface;
10
use Laminas\Form\Factory;
11
use Laminas\ServiceManager\ServiceLocatorInterface;
12
13
/**
14
 * Service factory responsible for instantiating {@see \DoctrineORMModule\Form\Annotation\AnnotationBuilder}
15
 */
16
class FormAnnotationBuilderFactory extends AbstractFactory
17
{
18
    /**
19
     * {@inheritDoc}
20
     *
21
     * @return AnnotationBuilder
22
     */
23 1
    public function __invoke(ContainerInterface $container, $requestedName, ?array $options = null)
24
    {
25 1
        $entityManager = $container->get('doctrine.entitymanager.' . $this->getName());
26
27 1
        $annotationBuilder = new AnnotationBuilder($entityManager);
28 1
        $annotationBuilder->setFormFactory($this->getFormFactory($container));
29
30 1
        return $annotationBuilder;
31
    }
32
33
    /**
34
     * {@inheritDoc}
35
     *
36
     * @return AnnotationBuilder
37
     */
38 1
    public function createService(ServiceLocatorInterface $container)
39
    {
40 1
        return $this($container, AnnotationBuilder::class);
41
    }
42
43
    public function getOptionsClass() : string
44
    {
45
    }
46
47
    /**
48
     * Retrieve the form factory
49
     */
50 1
    private function getFormFactory(ContainerInterface $services) : Factory
51
    {
52 1
        $elements = null;
53
54 1
        if ($services->has('FormElementManager')) {
55 1
            $elements = $services->get('FormElementManager');
56
        }
57
58 1
        return new Factory($elements);
59
    }
60
}
61