Completed
Push — feature/middleware ( f1ca06...1ed36f )
by Romain
02:16
created

DefaultFormObjectBuilder::insertObjectProperties()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 4
nc 3
nop 0
1
<?php
2
/*
3
 * 2017 Romain CANON <[email protected]>
4
 *
5
 * This file is part of the TYPO3 FormZ project.
6
 * It is free software; you can redistribute it and/or modify it
7
 * under the terms of the GNU General Public License, either
8
 * version 3 of the License, or any later version.
9
 *
10
 * For the full copyright and license information, see:
11
 * http://www.gnu.org/licenses/gpl-3.0.html
12
 */
13
14
namespace Romm\Formz\Form\FormObject\Builder;
15
16
use Romm\ConfigurationObject\ConfigurationObjectFactory;
17
use Romm\Formz\Form\Definition\FormDefinition;
18
use Romm\Formz\Form\FormObject\Definition\FormDefinitionObject;
19
use Romm\Formz\Service\TypoScriptService;
20
use TYPO3\CMS\Core\Utility\GeneralUtility;
21
22
/**
23
 * Default form object builder.
24
 *
25
 * It fetches the form configuration array from TypoScript, and automatically
26
 * inserts the class properties of the form in the properties of the form
27
 * object.
28
 */
29
class DefaultFormObjectBuilder extends AbstractFormObjectBuilder
30
{
31
    /**
32
     * @see DefaultFormObjectBuilder
33
     */
34
    public function process()
35
    {
36
        $this->insertObjectProperties();
37
    }
38
39
    /**
40
     * @return FormDefinitionObject
41
     */
42
    protected function getFormDefinitionObject()
43
    {
44
        $configurationArray = TypoScriptService::get()->getFormConfiguration($this->className);
0 ignored issues
show
Bug introduced by
It seems like getFormConfiguration() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
45
        $configurationObject = ConfigurationObjectFactory::convert(FormDefinition::class, $configurationArray);
46
47
        /** @var FormDefinitionObject $formDefinitionObject */
48
        $formDefinitionObject = GeneralUtility::makeInstance(
49
            FormDefinitionObject::class,
50
            $configurationObject->getObject(true),
51
            $configurationObject->getValidationResult()
52
        );
53
54
        return $formDefinitionObject;
55
    }
56
57
    /**
58
     * Will insert all the accessible properties of the form class in the form
59
     * object.
60
     */
61
    protected function insertObjectProperties()
62
    {
63
        foreach ($this->static->getProperties() as $propertyName) {
64
            if (false === $this->static->getDefinition()->hasField($propertyName)) {
65
                $this->static->getDefinition()->addField($propertyName);
66
            }
67
        }
68
    }
69
70
    /**
71
     * @return FormDefinition
72
     */
73
    public function getFormDefinition()
74
    {
75
        return null;
76
    }
77
}
78