Passed
Push — TYPO3_11 ( e359af...fe321d )
by
unknown
11:21
created

FeatureFlagBehaviourFormSelectElement   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 25
c 1
b 0
f 0
dl 0
loc 46
ccs 0
cts 17
cp 0
rs 10
wmc 4

1 Method

Rating   Name   Duplication   Size   Complexity  
A render() 0 41 4
1
<?php
2
namespace Aoe\FeatureFlag\Form\Element;
3
4
use Aoe\FeatureFlag\Domain\Model\Mapping;
5
use Aoe\FeatureFlag\Service\FeatureFlagService;
6
7
/***************************************************************
8
 *  Copyright notice
9
 *
10
 *  (c) 2021 AOE GmbH <[email protected]>
11
 *
12
 *  All rights reserved
13
 *
14
 *  This script is part of the TYPO3 project. The TYPO3 project is
15
 *  free software; you can redistribute it and/or modify
16
 *  it under the terms of the GNU General Public License as published by
17
 *  the Free Software Foundation; either version 3 of the License, or
18
 *  (at your option) any later version.
19
 *
20
 *  The GNU General Public License can be found at
21
 *  http://www.gnu.org/copyleft/gpl.html.
22
 *
23
 *  This script is distributed in the hope that it will be useful,
24
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
25
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
26
 *  GNU General Public License for more details.
27
 *
28
 *  This copyright notice MUST APPEAR in all copies of the script!
29
 ***************************************************************/
30
31
/**
32
 * This is rendered for type=user, renderType=selectFeatureFlagBehaviour
33
 */
34
class FeatureFlagBehaviourFormSelectElement extends AbstractFormSelectElement
35
{
36
    /**
37
     * @return array As defined in initializeResultArray() of AbstractNode
38
     */
39
    public function render()
40
    {
41
        $propertyArray = [
42
            'table' => $this->data['tableName'],
43
            'field' => $this->data['fieldName'],
44
            'row' => $this->data['databaseRow']
45
        ];
46
47
        // check, which behavior is selected
48
        $isBehaviorHideSelected = false;
49
        $isBehaviorShowSelected = false;
50
        $activeMapping = $this->mappingRepository->findOneByForeignTableNameAndUid(
51
            $propertyArray['row']['uid'],
52
            $propertyArray['table']
53
        );
54
        if ($activeMapping instanceof Mapping) {
0 ignored issues
show
introduced by
$activeMapping is always a sub-type of Aoe\FeatureFlag\Domain\Model\Mapping.
Loading history...
55
            if ($activeMapping->getBehavior() === FeatureFlagService::BEHAVIOR_HIDE) {
0 ignored issues
show
introduced by
The condition $activeMapping->getBehav...gService::BEHAVIOR_HIDE is always false.
Loading history...
56
                $isBehaviorHideSelected = true;
57
            } elseif ($activeMapping->getBehavior() === FeatureFlagService::BEHAVIOR_SHOW) {
0 ignored issues
show
introduced by
The condition $activeMapping->getBehav...gService::BEHAVIOR_SHOW is always false.
Loading history...
58
                $isBehaviorShowSelected = true;
59
            }
60
        }
61
62
        $optionElements = [
63
            [
64
                'name' => $this->getLanguageService()->sL(
65
                    'LLL:EXT:feature_flag/Resources/Private/Language/locallang.xlf:tx_featureflag_behavior.hide'
66
                ),
67
                'value' => FeatureFlagService::BEHAVIOR_HIDE,
68
                'isSelected' => $isBehaviorHideSelected
69
            ],
70
            [
71
                'name' => $this->getLanguageService()->sL(
72
                    'LLL:EXT:feature_flag/Resources/Private/Language/locallang.xlf:tx_featureflag_behavior.show'
73
                ),
74
                'value' => FeatureFlagService::BEHAVIOR_SHOW,
75
                'isSelected' => $isBehaviorShowSelected
76
            ]
77
        ];
78
79
        return $this->renderElement($optionElements);
80
    }
81
}
82