Completed
Push — feature/version-2 ( 4aa9b8...6dfc1b )
by Romain
02:16
created

getConfigurationValidationResult()   A

Complexity

Conditions 2
Paths 2

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 2
eloc 4
nc 2
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\Service;
15
16
use Romm\Formz\Configuration\ConfigurationFactory;
17
use Romm\Formz\Form\FormObject\Definition\FormDefinitionObject;
18
use Romm\Formz\Form\FormObject\FormObjectStatic;
19
use TYPO3\CMS\Extbase\Error\Result;
20
21
class FormObjectConfiguration
22
{
23
    /**
24
     * @var FormObjectStatic
25
     */
26
    protected $static;
27
28
    /**
29
     * @var FormDefinitionObject
30
     */
31
    protected $definition;
32
33
    /**
34
     * @var Result
35
     */
36
    protected $configurationValidationResult;
37
38
    /**
39
     * @param FormObjectStatic     $static
40
     * @param FormDefinitionObject $definition
41
     */
42
    public function __construct(FormObjectStatic $static, FormDefinitionObject $definition)
43
    {
44
        $this->static = $static;
45
        $this->definition = $definition;
46
    }
47
48
    /**
49
     * This function will merge and return the validation results of both the
50
     * global FormZ configuration object, and this form configuration object.
51
     *
52
     * @return Result
53
     */
54
    public function getConfigurationValidationResult()
55
    {
56
        if (null === $this->configurationValidationResult) {
57
            $this->configurationValidationResult = $this->getMergedValidationResult();
58
        }
59
60
        return $this->configurationValidationResult;
61
    }
62
63
    /**
64
     * Resets the validation result and merges it with the global FormZ
65
     * configuration.
66
     *
67
     * @return Result
68
     */
69
    protected function getMergedValidationResult()
70
    {
71
        $globalConfigurationValidationResult = $this->getGlobalConfigurationValidationResult();
72
73
        $result = new Result;
74
        $result->merge($globalConfigurationValidationResult);
75
76
        $propertyName = 'forms.' . $this->static->getClassName();
77
        $formValidationResult = $this->definition->getValidationResult();
78
79
        $result->forProperty($propertyName)->merge($formValidationResult);
80
81
        return $result;
82
    }
83
84
    /**
85
     * @return Result
86
     */
87
    protected function getGlobalConfigurationValidationResult()
88
    {
89
        return ConfigurationFactory::get()->getFormzConfiguration()->getValidationResult();
90
    }
91
}
92