Code Duplication    Length = 38-39 lines in 2 locations

src/Helpers/CrudApi.php 1 location

@@ 161-198 (lines=38) @@
158
            $output .= $this->fieldHelper->formCreate($fields);
159
            break;
160
        case 'form-edit':
161
            foreach ($fields as $f) {
162
                $ucF = ucfirst($f);
163
164
                $input_attr = [
165
                    'class' => 'form-control',
166
                    'id' => 'editItem'.$ucF,
167
                    'name' => $f,
168
                ];
169
170
                $output .= '<fieldset class="form-group">';
171
172
                $output .= '<label for="'.$input_attr['id'].'">'.$ucF.'</label>';
173
174
                if ($this->fieldHelper->isIdField($f)) {
175
                    $input_attr['type'] = 'select';
176
177
                    $output .= '<select ';
178
                    foreach ($input_attr as $attr => $value) {
179
                        $output .= "{$attr}='{$value}'";
180
                    }
181
182
                    $relation = $this->getRelatedModel($f);
183
                    $output .= '>';
184
185
                    $output .= $this->getRelatedOptions($relation);
186
                    $output .= '</select>';
187
                } else {
188
                    $input_attr['type'] = 'text';
189
190
                    $output .= '<input ';
191
                    foreach ($input_attr as $attr => $value) {
192
                        $output .= "{$attr}='{$value}'";
193
                    }
194
                    $output .= '>';
195
                }
196
197
                $output .= '</fieldset>';
198
            }
199
            break;
200
        case 'table-headings':
201
            $output .= $this->fieldHelper->tableHeadings($fields);

src/Helpers/Field.php 1 location

@@ 103-141 (lines=39) @@
100
    {
101
        $output = '';
102
103
        foreach ($fields as $f) {
104
            $ucF = ucfirst($f);
105
106
            $input_attr = [
107
                'class' => 'form-control',
108
                'id' => 'createItem'.$f,
109
                'name' => $f,
110
            ];
111
112
            $output .= '<fieldset class="form-group">';
113
114
            $output .= '<label for="'.$input_attr['id'].'">'.$ucF.'</label>';
115
116
            if ($this->isIdField($f)) {
117
                $input_attr['type'] = 'select';
118
119
                $output .= '<select ';
120
                foreach ($input_attr as $attr => $value) {
121
                    $output .= "{$attr}='{$value}'";
122
                }
123
124
                $relation = $this->crudApi->getRelatedModel($f);
125
                $output .= '>';
126
127
                $output .= $this->crudApi->getRelatedOptions($relation);
128
129
                $output .= '</select>';
130
            } else {
131
                $input_attr['type'] = 'text';
132
133
                $output .= '<input ';
134
                foreach ($input_attr as $attr => $value) {
135
                    $output .= "{$attr}='{$value}'";
136
                }
137
                $output .= '>';
138
            }
139
140
            $output .= '</fieldset>';
141
        }
142
        return $output;
143
    }
144