OutputFormBuilder   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 110
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 10
lcom 1
cbo 0
dl 0
loc 110
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A listOfKnownLabels() 0 17 2
A providers() 0 19 2
A setOutputForm() 0 14 1
A setFormOptions() 0 19 1
A turnRequestedValueIntoCheckboxStatus() 0 12 3
A typeOfResults() 0 17 1
1
<?php
2
3
/*
4
 * The MIT License
5
 *
6
 * Copyright 2016 Daniel Popiniuc
7
 *
8
 * Permission is hereby granted, free of charge, to any person obtaining a copy
9
 * of this software and associated documentation files (the "Software"), to deal
10
 * in the Software without restriction, including without limitation the rights
11
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
 * copies of the Software, and to permit persons to whom the Software is
13
 * furnished to do so, subject to the following conditions:
14
 *
15
 * The above copyright notice and this permission notice shall be included in
16
 * all copies or substantial portions of the Software.
17
 *
18
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24
 * THE SOFTWARE.
25
 */
26
27
namespace danielgp\info_compare;
28
29
trait OutputFormBuilder
30
{
31
32
    private $defaults;
33
    private $superGlobals;
34
35
    private function listOfKnownLabels($inArray)
36
    {
37
        $informatorLabels = array_diff($inArray['KnownLabels'], ['--- List of known labels']);
38
        $tmpOptions            = [];
39
        foreach ($informatorLabels as $value) {
40
            $tmpOptions[] = '<input type="radio" name="Label" id="Label_' . $value . '" value="' . $value . '" '
41
                    . $this->turnRequestedValueIntoCheckboxStatus([
42
                        'CheckedValue'  => $value,
43
                        'RequestedName' => 'Label',
44
                    ])
45
                    . '/><label for="Label_' . $value . '">' . $value . '</label>';
46
        }
47
        return '<fieldset style="float:left;">'
48
                . '<legend>Informator Label to use</legend>'
49
                . implode('<br/>', $tmpOptions)
50
                . '</fieldset>';
51
    }
52
53
    private function providers($inArray)
54
    {
55
        $tmpOptions = [];
56
        foreach ($inArray['Servers'] as $key => $value) {
57
            $tmpOptions[] = '<a href="' . $value['url'] . '" target="_blank">run-me</a>&nbsp;'
58
                    . '<input type="radio" name="' . $inArray['ConfigName'] . '" id="'
59
                    . $inArray['ConfigName'] . '_' . $key . '" value="' . $key . '" '
60
                    . $this->turnRequestedValueIntoCheckboxStatus([
61
                        'CheckedValue'  => (string) $key,
62
                        'RequestedName' => $inArray['ConfigName'],
63
                    ])
64
                    . '/>'
65
                    . '<label for="' . $inArray['ConfigName'] . '_' . $key . '">' . $value['name'] . '</label>';
66
        }
67
        return '<fieldset style="float:left;">'
68
                . '<legend>' . $inArray['TitleStart'] . ' config providers</legend>'
69
                . implode('<br/>', $tmpOptions)
70
                . '</fieldset>';
71
    }
72
73
    protected function setOutputForm($inArray)
74
    {
75
        $sReturn = $this->setFormOptions($inArray);
76
        return '<div class="tabbertab" id="tabOptions" title="Options">'
77
                . '<style type="text/css" media="all" scoped>label { width: auto; }</style>'
78
                . '<form method="get" action="'
79
                . $inArray['SuperGlobals']->server->get('PHP_SELF')
80
                . '">'
81
                . '<input type="submit" value="Apply" />'
82
                . '<br/>' . implode('', $sReturn)
83
                . '</form>'
84
                . '<div style="float:none;clear:both;height:1px;">&nbsp;</div>'
85
                . '</div><!--from tabOptions-->';
86
    }
87
88
    private function setFormOptions($inArray)
89
    {
90
        $this->defaults     = $inArray['Defaults'];
91
        $this->superGlobals = $inArray['SuperGlobals'];
92
        $sReturn            = [];
93
        $sReturn[]          = $this->typeOfResults();
94
        $sReturn[]          = $this->providers([
95
            'ConfigName' => 'localConfig',
96
            'Servers'    => $inArray['Servers'],
97
            'TitleStart' => 'Source',
98
        ]);
99
        $sReturn[]          = $this->providers([
100
            'ConfigName' => 'serverConfig',
101
            'Servers'    => $inArray['Servers'],
102
            'TitleStart' => 'Target',
103
        ]);
104
        $sReturn[]          = $this->listOfKnownLabels(['KnownLabels' => $inArray['KnownLabels']]);
105
        return $sReturn;
106
    }
107
108
    private function turnRequestedValueIntoCheckboxStatus($inArray)
109
    {
110
        if (is_null($this->superGlobals->get($inArray['RequestedName']))) {
111
            $valToSet = (string) $this->defaults[$inArray['RequestedName']];
112
            $this->superGlobals->request->set($inArray['RequestedName'], $valToSet);
113
        }
114
        $checkboxStatus = '';
115
        if ($this->superGlobals->get($inArray['RequestedName']) === $inArray['CheckedValue']) {
116
            $checkboxStatus = 'checked ';
117
        }
118
        return $checkboxStatus;
119
    }
120
121
    private function typeOfResults()
122
    {
123
        return '<fieldset style="float:left;"><legend>Type of results displayed</legend>'
124
                . '<input type="radio" name="displayOnlyDifferent" id="displayOnlyDifferent" value="1" '
125
                . $this->turnRequestedValueIntoCheckboxStatus([
126
                    'CheckedValue'  => '1',
127
                    'RequestedName' => 'displayOnlyDifferent',
128
                ])
129
                . '/><label for="displayOnlyDifferent">Only the Different values</label>'
130
                . '<br/><input type="radio" name="displayOnlyDifferent" id="displayAll" value="0" '
131
                . $this->turnRequestedValueIntoCheckboxStatus([
132
                    'CheckedValue'  => '0',
133
                    'RequestedName' => 'displayOnlyDifferent',
134
                ])
135
                . '/><label for="displayAll">All</label>'
136
                . '</fieldset>';
137
    }
138
}
139