Completed
Pull Request — master (#175)
by
unknown
13:09
created

FormContractor   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 5
Bugs 1 Features 0
Metric Value
wmc 6
c 5
b 1
f 0
lcom 0
cbo 2
dl 0
loc 33
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B fixFieldDescription() 0 27 6
1
<?php
2
3
/*
4
 * This file is part of the Sonata Project package.
5
 *
6
 * (c) Thomas Rabaix <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Sonata\DoctrineMongoDBAdminBundle\Builder;
13
14
use Sonata\AdminBundle\Admin\AdminInterface;
15
use Sonata\AdminBundle\Admin\FieldDescriptionInterface;
16
use Sonata\AdminBundle\Builder\AbstractFormContractor;
17
18
class FormContractor extends AbstractFormContractor
19
{
20
    /**
21
     * {@inheritdoc}
22
     */
23
    public function fixFieldDescription(AdminInterface $admin, FieldDescriptionInterface $fieldDescription)
24
    {
25
        if ($admin->getModelManager()->hasMetadata($admin->getClass())) {
26
            $metadata = $admin->getModelManager()->getMetadata($admin->getClass());
27
28
            // set the default field mapping
29
            if (isset($metadata->fieldMappings[$fieldDescription->getName()])) {
30
                $fieldDescription->setFieldMapping($metadata->fieldMappings[$fieldDescription->getName()]);
31
            }
32
33
            // set the default association mapping
34
            if (isset($metadata->associationMappings[$fieldDescription->getName()])) {
35
                $fieldDescription->setAssociationMapping($metadata->associationMappings[$fieldDescription->getName()]);
36
            }
37
        }
38
39
        if (!$fieldDescription->getType()) {
40
            throw new \RuntimeException(sprintf('Please define a type for field `%s` in `%s`', $fieldDescription->getName(), get_class($admin)));
41
        }
42
43
        $fieldDescription->setAdmin($admin);
44
        $fieldDescription->setOption('edit', $fieldDescription->getOption('edit', 'standard'));
45
46
        if ($fieldDescription->describesAssociation()) {
0 ignored issues
show
Bug introduced by
The method describesAssociation() does not seem to exist on object<Sonata\AdminBundl...ldDescriptionInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
47
            $admin->attachAdminClass($fieldDescription);
48
        }
49
    }
50
}
51