Completed
Pull Request — master (#459)
by Vytautas
13:28 queued 09:14
created

FormAnnotationBuilderFactory::__invoke()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 11
ccs 5
cts 5
cp 1
rs 9.4285
cc 1
eloc 5
nc 1
nop 3
crap 1
1
<?php
2
/*
3
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
4
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
5
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
6
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
7
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
8
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
9
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
10
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
11
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
12
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
13
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
14
 *
15
 * This software consists of voluntary contributions made by many individuals
16
 * and is licensed under the MIT license. For more information, see
17
 * <http://www.doctrine-project.org>.
18
 */
19
20
namespace DoctrineORMModule\Service;
21
22
use DoctrineModule\Service\AbstractFactory;
23
use DoctrineORMModule\Form\Annotation\AnnotationBuilder;
24
use Interop\Container\ContainerInterface;
25
use Zend\Form\Factory;
26
use Zend\ServiceManager\ServiceLocatorInterface;
27
28
/**
29
 * Service factory responsible for instantiating {@see \DoctrineORMModule\Form\Annotation\AnnotationBuilder}
30
 *
31
 * @license MIT
32
 * @link    http://www.doctrine-project.org/
33
 * @author  Marco Pivetta <[email protected]>
34
 */
35
class FormAnnotationBuilderFactory extends AbstractFactory
36
{
37
    /**
38
     * {@inheritDoc}
39
     *
40
     * @return \DoctrineORMModule\Form\Annotation\AnnotationBuilder
41
     */
42 1
    public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
0 ignored issues
show
Unused Code introduced by
The parameter $requestedName is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $options is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
43
    {
44
        /* @var $entityManager \Doctrine\ORM\EntityManager */
45 1
        $entityManager = $container->get('doctrine.entitymanager.' . $this->getName());
46
47 1
        $annotationBuilder = new AnnotationBuilder($entityManager);
48
49 1
        $annotationBuilder->setFormFactory($this->getFormFactory($container));
50
51 1
        return $annotationBuilder;
52
    }
53
54
    /**
55
     * {@inheritDoc}
56
     *
57
     * @return \DoctrineORMModule\Form\Annotation\AnnotationBuilder
58
     */
59 1
    public function createService(ServiceLocatorInterface $container)
60
    {
61 1
        return $this($container, \DoctrineORMModule\Form\Annotation\AnnotationBuilder::class);
62
    }
63
64
    /**
65
     * {@inheritDoc}
66
     */
67
    public function getOptionsClass()
68
    {
69
    }
70
71
    /**
72
     * Retrieve the form factory
73
     *
74
     * @param  ContainerInterface $services
75
     * @return Factory
76
     */
77 1
    private function getFormFactory(ContainerInterface $services)
78
    {
79 1
        $elements = null;
80
        
81 1
        if ($services->has('FormElementManager')) {
82 1
            $elements = $services->get('FormElementManager');
83 1
        }
84
85 1
        return new Factory($elements);
86
    }
87
}
88