Completed
Push — master ( 2b9bd3...31a468 )
by Nicolaas
01:33
created

BuildController::resultsTemplateForBuilder()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
4
namespace SunnySideUp\BuildDataObject;
5
6
7
8
abstract class BuildController extends \Controller {
9
10
11
    private static $form_data_session_variable = 'SunnySideUp\BuildDataObject\DataObjectBuildController';
0 ignored issues
show
Unused Code introduced by
The property $form_data_session_variable is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
12
13
    private static $url_segment = 'build';
0 ignored issues
show
Unused Code introduced by
The property $url_segment is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
14
15
    private static $allowed_actions = [
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
Unused Code introduced by
The property $allowed_actions is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
16
        'primaryformstart' => true,
17
        'PrimaryForm' => true,
18
        'doprimaryform' => true,
19
        'secondaryformstart' => true,
20
        'SecondaryForm' => true,
21
        'dosecondaryform' => true,
22
        'results' => true,
23
        'startover' => true,
24
        'debug' => true
25
    ];
26
27
    protected $myBaseClass = 'DataObject';
28
29
    protected $apiProvider = 'SunnySideUp\BuildDataObject\API';
30
31
    abstract protected function primaryThingsToBuild();
0 ignored issues
show
Documentation introduced by
For interfaces and abstract methods it is generally a good practice to add a @return annotation even if it is just @return void or @return null, so that implementors know what to do in the overridden method.

For interface and abstract methods, it is impossible to infer the return type from the immediate code. In these cases, it is generally advisible to explicitly annotate these methods with a @return doc comment to communicate to implementors of these methods what they are expected to return.

Loading history...
32
33
    abstract protected function secondaryThingsToBuild();
0 ignored issues
show
Documentation introduced by
For interfaces and abstract methods it is generally a good practice to add a @return annotation even if it is just @return void or @return null, so that implementors know what to do in the overridden method.

For interface and abstract methods, it is impossible to infer the return type from the immediate code. In these cases, it is generally advisible to explicitly annotate these methods with a @return doc comment to communicate to implementors of these methods what they are expected to return.

Loading history...
34
35
    public function Link($action = null)
36
    {
37
        if($action) {
38
            $action .= '/';
39
        }
40
        return
41
            '/'.$this->Config()->get('url_segment').
42
            '/'.strtolower($this->myBaseClass).
43
            '/'.$action;
44
    }
45
46
    public function Title()
47
    {
48
        return 'Build a '.$this->myBaseClass.' - Step '.$this->step.' of 2';
49
    }
50
51
52
    public function jQueryLink()
53
    {
54
        return \Director::absoluteURL('/framework/thirdparty/jquery/jquery.js');
55
    }
56
57
    public function startover()
58
    {
59
        $this->saveData('_PrimaryForm', null);
60
        $this->saveData('_SecondaryForm', null);
61
        return $this->redirect($this->link('primaryformstart'));
62
    }
63
64
    /**
65
     *
66
     * @var Form
67
     */
68
    protected $step = 1;
69
70
    /**
71
     *
72
     * @var Form
73
     */
74
    protected $form = null;
75
76
    /**
77
     *
78
     * @var Form
79
     */
80
    protected $prevLink = null;
81
82
    /**
83
     *
84
     * @var ArrayList
85
     */
86
    protected $finalData = null;
87
88
    function index()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
89
    {
90
        return $this->redirect($this->Link('primaryformstart'));
91
    }
92
93
    function primaryformstart()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
94
    {
95
        $this->PrimaryForm();
96
        $this->prevLink = $this->Link('startover');
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->Link('startover') of type string is incompatible with the declared type object<SunnySideUp\BuildDataObject\Form> of property $prevLink.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
97
98
        return $this->renderWith('BuildControllerForm');
99
    }
100
101
    function PrimaryForm()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
102
    {
103
        $this->form = $this->createForm('PrimaryForm', 'Build Model');
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->createForm('PrimaryForm', 'Build Model') of type object<Form> is incompatible with the declared type object<SunnySideUp\BuildDataObject\Form> of property $form.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
104
105
        return $this->form;
106
    }
107
108
    function doprimaryform($data, $form)
0 ignored issues
show
Unused Code introduced by
The parameter $form is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
109
    {
110
        $this->saveData('_PrimaryForm', $data);
111
112
        return $this->redirect($this->Link('secondaryformstart'));
113
    }
114
115
116
    function secondaryformstart()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
117
    {
118
        $this->step = 2;
0 ignored issues
show
Documentation Bug introduced by
It seems like 2 of type integer is incompatible with the declared type object<SunnySideUp\BuildDataObject\Form> of property $step.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
119
        $this->SecondaryForm();
120
        $this->prevLink = $this->Link('primaryformstart');
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->Link('primaryformstart') of type string is incompatible with the declared type object<SunnySideUp\BuildDataObject\Form> of property $prevLink.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
121
122
        return $this->renderWith('BuildControllerForm');
123
    }
124
125
    function SecondaryForm()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
126
    {
127
        $this->form = $this->createForm('SecondaryForm', 'Download Example Class');
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->createForm('Secon...ownload Example Class') of type object<Form> is incompatible with the declared type object<SunnySideUp\BuildDataObject\Form> of property $form.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
128
129
        return $this->form;
130
    }
131
132
133
    function dosecondaryform($data, $form)
0 ignored issues
show
Unused Code introduced by
The parameter $form is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
134
    {
135
        $this->saveData('_SecondaryForm', $data);
136
137
        return $this->redirect($this->Link('results'));
138
    }
139
140
    function results()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
141
    {
142
        $this->finalData = $this->processedFormData($this->retrieveData());
143
        return \SS_HTTPRequest::send_file(
144
            $this->renderWith($this->resultsTemplateForBuilder()),
145
            $this->finalData->Name.'.php'
146
        );
147
    }
148
149
    function debug()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
150
    {
151
        $this->finalData = $this->processedFormData($this->retrieveData());
152
        print_r($this->CanMethodBuilder('canEdit'));
0 ignored issues
show
Bug introduced by
The method CanMethodBuilder() does not exist on SunnySideUp\BuildDataObject\BuildController. Did you maybe mean MyCanMethodBuilder()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
153
        print_r($this->finalData);
154
        die('-----------------------------');
0 ignored issues
show
Coding Style Compatibility introduced by
The method debug() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
155
    }
156
157
    function Form()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
158
    {
159
        return $this->form;
160
    }
161
162
    function FinalData()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
163
    {
164
        return $this->finalData;
165
    }
166
167
    function PrevLink()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
168
    {
169
        return $this->prevLink;
170
    }
171
172
    function MyCanMethodBuilder($type, $value) {
0 ignored issues
show
Unused Code introduced by
The parameter $type is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
173
        if($value === 'parent') {
174
            return null;
175
        } elseif($value === 'true') {
176
            $str = 'true;';
177
        } elseif($value === 'false') {
178
            $str = 'false;';
179
        } else {
180
            $str = 'Permission::check(\''.$value.'\', \'any\', $member);';
181
        }
182
183
        return \DBField::create_field('Varchar', $str);
184
    }
185
186
187
    protected function createForm($formName, $actionTitle)
188
    {
189
        if($formName === 'PrimaryForm') {
190
            $isPrimary = true;
191
            $isSecond = false;
0 ignored issues
show
Unused Code introduced by
$isSecond is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
192
        } elseif($formName === 'SecondaryForm') {
193
            $isPrimary = false;
194
            $isSecond = true;
0 ignored issues
show
Unused Code introduced by
$isSecond is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
195
        } else {
196
            user_error('Set right form type: '.$formName.' is not valid');
197
        }
198
199
        $finalFields = \FieldList::create();
200
201
        if($isPrimary) {
0 ignored issues
show
Bug introduced by
The variable $isPrimary does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
202
            $toBuild = $this->primaryThingsToBuild();
203
            $finalFields->push(\HeaderField::create('Name your '.$this->myBaseClass));
204
            $finalFields->push(\TextField::create('Name', ''));
205
            $finalFields->push(\HeaderField::create('Extends'));
206
            $finalFields->push(\DropdownField::create(
207
                'Extends',
208
                '',
209
                $this->myAPI()->PossibleRelationsWithBaseClass($this->myBaseClass)
210
211
            ));
212
            $additionalFields = $this->additionalPrimaryFields();
213
            foreach($additionalFields as $additionalField) {
214
                $finalFields->push($additionalField);
215
            }
216
        } else {
217
            $toBuild = $this->secondaryThingsToBuild();
218
        }
219
        $formFields = [];
220
221
        $count = 0;
222
        //build fields ...
223
        foreach($toBuild as $item) {
224
            $name = $item[0];
225
            $sourceMethod1 = $item[1];
226
            $sourceMethod2 = $item[2];
227
            $isMultiple = $item[3];
228
229
            //work out style
230
            $hasKeyAndValue = false;
231
            if($sourceMethod1 && $sourceMethod2) {
232
                $hasKeyAndValue = true;
233
            }
234
            $formFields[$count] = [];
235
            $formFields[$count][0] = [
236
                $name.'_HEADER',
237
                'HeaderField',
238
                $name
239
            ];
240
            if($isMultiple) {
241
                $max = 12;
242
            } else {
243
                $max = 1;
244
            }
245
246
            //work out sources
247
            if($sourceMethod1 && $this->myAPI()->hasMethod($sourceMethod1)) {
248
                $source1 = $this->myAPI()->$sourceMethod1();
249
            } else {
250
                $source1 = null;
251
            }
252
            if($sourceMethod2 && $this->myAPI()->hasMethod($sourceMethod2)) {
253
                $source2 = $this->myAPI()->$sourceMethod2();
254
            } elseif($sourceMethod2) {
255
                $source2 = null;
256
            } else {
257
                $source2 = 'ignore';
258
            }
259
260
            //work out field names
261
262
            for($i = 1; $i <= $max; $i++) {
263
                if($hasKeyAndValue) {
264
                    $nameKey = $name.'__KEY__'.$i;
265
                    $nameValue = $name.'__VALUE__'.$i;
266
                } else {
267
                    $nameKey = $name;
268
                    $nameValue = '';
269
                }
270
                if($hasKeyAndValue) {
271
                    //key field
272 View Code Duplication
                    if($source1) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
273
                        $formFields[$count][$i]['KEY'] = [
274
                            $nameKey,
275
                            'DropdownField',
276
                            $source1
277
                        ];
278
                    } else {
279
                        $formFields[$count][$i]['KEY'] = [
280
                            $nameKey,
281
                            'TextField'
282
                        ];
283
                    }
284
285
                    //value field
286 View Code Duplication
                    if($source2) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
287
                        $formFields[$count][$i]['VALUE'] = [
288
                            $nameValue,
289
                            'DropdownField',
290
                            $source2
291
                        ];
292
                    } else {
293
                        $formFields[$count][$i]['VALUE'] = [
294
                            $nameValue,
295
                            'TextField'
296
                        ];
297
                    }
298
                } else {
299
                    //keys only!
300
                    if($source1) {
301
                        $formFields[$count][1] = [
302
                            $nameKey,
303
                            'DropdownField',
304
                            $source1
305
                        ];
306
                    } else {
307
                        $formFields[$count][1] = [
308
                            $nameKey,
309
                            'TextField'
310
                        ];
311
                    }
312
                }
313
            }
314
            if($i > 2) {
315
                $formFields[$count][$i + 1] = [
316
                    $name.'_ADD_'.$i,
317
                    'LiteralField',
318
                    '
319
                    <div class="CompositeField add-and-remove">
320
                        <a href="#" class="add first-add"><i class="material-icons">add_circle_outline</i></a>
321
                        <a href="#" class="remove"><i class="material-icons">remove_circle_outline</i></a>
322
                    </div>
323
                    '
324
                ];
325
            }
326
            $count++;
327
        }
328
        //create fields ...
329
        $count = 0;
330
        foreach($formFields as $outerCount => $subFieldList) {
331
            $count++;
332
            $compositeField = \CompositeField::create();
333
            $compositeField->addExtraClass('OuterComposite pos'.$count);
334
            $innerCount = 0;
335
            foreach($subFieldList as $fieldDetails) {
336
                $innerCount++;
337
                if(isset($fieldDetails['KEY']) && isset($fieldDetails['VALUE'])) {
338
                    $subCompositeField = \CompositeField::create();
339
                    $subCompositeField->addExtraClass('InnerComposite pos'.$innerCount);
340
                    $innerInnerCount = 0;
0 ignored issues
show
Unused Code introduced by
$innerInnerCount is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
341
                    foreach($fieldDetails as $fieldDetailsInner) {
342
                        $fieldName = $fieldDetailsInner[0];
343
                        $fieldType = $fieldDetailsInner[1];
344
                        $additionalClasses = [];
345
                        if(strpos($fieldName, '__KEY__')) {
346
                            $additionalClasses[] = 'mykey';
347
                        }
348
                        if(strpos($fieldName, '__VALUE__')) {
349
                            $additionalClasses[] = 'myvalue';
350
                        }
351
                        if(isset($fieldDetailsInner[2])) {
352
                            $source = $fieldDetailsInner[2];
353
                            $source = $this->prependNullOption( $source );
354
                            $tempField = $fieldType::create($fieldName, '', $source);
355
                        } else {
356
                            $tempField = $fieldType::create($fieldName, '');
357
                        }
358
                        if(count($additionalClasses)) {
359
                            $classes = implode(' ', $additionalClasses);
360
                            $tempField->addExtraClass($classes);
361
                        }
362
                        $subCompositeField->push($tempField);
363
                    }
364
                    $compositeField->push($subCompositeField);
365
                } else {
366
                    $fieldName = $fieldDetails[0];
367
                    $fieldType = $fieldDetails[1];
368
                    if($fieldType === 'DropdownField') {
369
                        $source = $fieldDetails[2];
370
                        $source = $this->prependNullOption($source);
371
                        $compositeField->push($fieldType::create($fieldName, '', $source));
372
                    } elseif($fieldType === 'HeaderField') {
373
                        $title = str_replace('_', ' ', $fieldDetails[2]);
374
                        $compositeField->push($fieldType::create($fieldName, $title));
375
                    } elseif($fieldType === 'LiteralField') {
376
                        $title = $fieldDetails[2];
377
                        $compositeField->push($fieldType::create($fieldName, $title));
378
                    } else {
379
                        $compositeField->push($fieldType::create($fieldName, ''));
380
                    }
381
                }
382
            }
383
            $finalFields->push($compositeField);
384
        }
385
        $actions = \FieldList::create(
386
            [\FormAction::create('do'.strtolower($formName), $actionTitle)]
387
        );
388
389
        $form = \Form::create($this, $formName, $finalFields, $actions);
390
        $form->setFormAction($this->Link($formName));
391
        $form->loadDataFrom($this->retrieveData());
392
393
        return $form;
394
    }
395
396
    /**
397
     * returns an array of fields
398
     * @return array
399
     */
400
    protected function additionalPrimaryFields()
401
    {
402
        return [];
403
    }
404
405
    protected function saveData($name, $data)
406
    {
407
        $var = $this->Config()->get('form_data_session_variable');
408
        \Session::set($var.$name, $data);
409
        \Session::save();
410
    }
411
412
    private $_data = null;
413
414
    protected function retrieveData()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
415
    {
416
        if(! $this->_data) {
417
            $var = $this->Config()->get('form_data_session_variable');
418
            $retrieveDataPrimary = \Session::get($var.'_PrimaryForm');
419
            if ($retrieveDataPrimary && (is_array($retrieveDataPrimary) || is_object($retrieveDataPrimary))) {
0 ignored issues
show
Unused Code introduced by
This if statement is empty and can be removed.

This check looks for the bodies of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These if bodies can be removed. If you have an empty if but statements in the else branch, consider inverting the condition.

if (rand(1, 6) > 3) {
//print "Check failed";
} else {
    print "Check succeeded";
}

could be turned into

if (rand(1, 6) <= 3) {
    print "Check succeeded";
}

This is much more concise to read.

Loading history...
420
                //do nothing
421
            } else {
422
                $retrieveDataPrimary = [];
423
            }
424
            $retrieveDataSecondary = \Session::get($var.'_SecondaryForm');
425
            if ($retrieveDataSecondary && (is_array($retrieveDataSecondary) || is_object($retrieveDataSecondary))) {
0 ignored issues
show
Unused Code introduced by
This if statement is empty and can be removed.

This check looks for the bodies of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These if bodies can be removed. If you have an empty if but statements in the else branch, consider inverting the condition.

if (rand(1, 6) > 3) {
//print "Check failed";
} else {
    print "Check succeeded";
}

could be turned into

if (rand(1, 6) <= 3) {
    print "Check succeeded";
}

This is much more concise to read.

Loading history...
426
                //do nothing
427
            } else {
428
                $retrieveDataSecondary = [];
429
            }
430
            $this->_data = $retrieveDataPrimary + $retrieveDataSecondary;
431
        }
432
433
        return $this->_data;
434
    }
435
436
    private $_processed_data = null;
437
438
    protected function processedFormData($data = null) {
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
439
        if(! $this->_processed_data) {
440
            if(! $data) {
441
                $data = $this->retrieveData();
442
            }
443
            $array = [];
444
            foreach($data as $key => $value) {
445
                if($key && $value) {
446
                    if(
447
                        strpos($key, '__KEY__') ||
448
                        strpos($key, '__VALUE__')
449
                    ) {
450
                        $parts = explode('__', $key);
451
                        if(!isset($array[$parts[0]])) {
452
                            $array[$parts[0]] = [];
453
                        }
454
                        if(! isset($array[$parts[0]][$parts[2]])) {
455
                            $array[$parts[0]][$parts[2]] = [];
456
                        }
457
                        $array[$parts[0]][$parts[2]][$parts[1]] = $value;
458
                    } elseif(substr($key, 0, 3) === 'can') {
459
                        $array[$key] = $this->MyCanMethodBuilder($key, $value);
460
                    } else {
461
                        $array[$key] = $value;
462
                    }
463
                }
464
            }
465
            foreach($array as $field => $values) {
466
                $alInner = \ArrayList::create();
467
                if(is_array($values)) {
468
                    foreach($values as $key => $valuePairs) {
469
                        if(isset($valuePairs['KEY']) && isset($valuePairs['VALUE'])) {
470
                            if($valuePairs['VALUE'] == 'true') {
471
                                $valuePairArray = [
472
                                    'Key' => $valuePairs['KEY'],
473
                                    'UnquotedValue' => $valuePairs['VALUE'],
474
                                ];
475
                            } else {
476
                                $valuePairArray = [
477
                                    'Key' => $valuePairs['KEY'],
478
                                    'Value' => $valuePairs['VALUE'],
479
                                ];
480
                            }
481
                            $alInner->push(\ArrayData::create($valuePairArray));
482
                        }
483
                    }
484
                    $array[$field] = $alInner;
485
                } else {
0 ignored issues
show
Unused Code introduced by
This else statement is empty and can be removed.

This check looks for the else branches of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These else branches can be removed.

if (rand(1, 6) > 3) {
print "Check failed";
} else {
    //print "Check succeeded";
}

could be turned into

if (rand(1, 6) > 3) {
    print "Check failed";
}

This is much more concise to read.

Loading history...
486
                    //do nothing
487
                }
488
            }
489
            $this->_processed_data = \ArrayData::create($array);
490
        }
491
492
        return $this->_processed_data;
493
    }
494
495
496
    protected function resultsTemplateForBuilder()
497
    {
498
        return str_replace(__NAMESPACE__ .'\\', '', $this->class).'Results';
499
    }
500
501
502
    protected function prependNullOption($source)
503
    {
504
        $source = ['' => '--- Please Select ---'] + $source;
505
506
        return $source;
507
    }
508
509
510
    protected function myAPI()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
511
    {
512
        $class = $this->apiProvider;
513
514
        return $class::inst($this->myBaseClass, $this->processedFormData());
515
    }
516
517
518
}
519