Completed
Push — master ( 2c2a55...46eca6 )
by Gianluca
05:40
created

FormAnnotationBuilderFactory   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Test Coverage

Coverage 84.62%

Importance

Changes 2
Bugs 0 Features 2
Metric Value
wmc 4
c 2
b 0
f 2
lcom 0
cbo 4
dl 0
loc 43
ccs 11
cts 13
cp 0.8462
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A createService() 0 11 1
A getFormFactory() 0 10 2
A getOptionsClass() 0 3 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 Zend\Form\Factory;
25
use Zend\ServiceManager\ServiceLocatorInterface;
26
27
/**
28
 * Service factory responsible for instantiating {@see \DoctrineORMModule\Form\Annotation\AnnotationBuilder}
29
 *
30
 * @license MIT
31
 * @link    http://www.doctrine-project.org/
32
 * @author  Marco Pivetta <[email protected]>
33
 */
34
class FormAnnotationBuilderFactory extends AbstractFactory
35
{
36
    /**
37
     * {@inheritDoc}
38
     *
39
     * @return \DoctrineORMModule\Form\Annotation\AnnotationBuilder
40
     */
41 1
    public function createService(ServiceLocatorInterface $serviceLocator)
42
    {
43
        /* @var $entityManager \Doctrine\ORM\EntityManager */
44 1
        $entityManager = $serviceLocator->get('doctrine.entitymanager.' . $this->getName());
45
46 1
        $annotationBuilder = new AnnotationBuilder($entityManager);
47
        
48 1
        $annotationBuilder->setFormFactory($this->getFormFactory($serviceLocator));
49
50 1
        return $annotationBuilder;
51
    }
52
53
    /**
54
     * {@inheritDoc}
55
     */
56
    public function getOptionsClass()
57
    {
58
    }
59
60
    /**
61
     * Retrieve the form factory
62
     *
63
     * @param  ServiceLocatorInterface $services
64
     * @return Factory
65
     */
66 1
    private function getFormFactory(ServiceLocatorInterface $services)
67
    {
68 1
        $elements = null;
69
        
70 1
        if ($services->has('FormElementManager')) {
71 1
            $elements = $services->get('FormElementManager');
72 1
        }
73
74 1
        return new Factory($elements);
0 ignored issues
show
Bug introduced by
It seems like $elements defined by $services->get('FormElementManager') on line 71 can also be of type array or object; however, Zend\Form\Factory::__construct() does only seem to accept null|object<Zend\Form\FormElementManager>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
75
    }
76
}
77