InuitFieldList   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 6
dl 0
loc 49
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
D performInuitTransformation() 0 40 9
1
<?php namespace StudioBonito\SilverStripe\Inuit\Forms\Extensions;
2
3
use ClassInfo;
4
use FieldGroup;
5
use SSViewer;
6
use Tab;
7
use TabSet;
8
9
/**
10
 * An extension to transform the {@link \FormField} objects
11
 * of a {@FieldList} so they use inuit form templates.
12
 *
13
 * @author       Tom Densham <[email protected]>
14
 * @copyright    Studio Bonito Ltd.
15
 */
16
class InuitFieldList extends \Extension
17
{
18
    /**
19
     * Transform all the {@link \FormField} objects in
20
     * the {@link \FieldList} to use inuit form templates.
21
     *
22
     * @return \FieldList
23
     */
24
    public function performInuitTransformation()
25
    {
26
        foreach ($this->owner as $field) {
27
28
            // If we have a Tabset, performInuitTransformation all Tabs
29
            if ($field instanceof TabSet) {
30
                $field->Tabs()->performInuitTransformation();
0 ignored issues
show
Bug introduced by
The method performInuitTransformation() does not exist on FieldList. Did you maybe mean transform()?

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...
31
            }
32
33
            // If we have a Tab, performInuitTransformation all its Fields
34
            if ($field instanceof Tab) {
35
                $field->Fields()->performInuitTransformation();
0 ignored issues
show
Bug introduced by
The method performInuitTransformation() does not exist on FieldList. Did you maybe mean transform()?

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...
36
            }
37
38
            if ($field instanceof FieldGroup) {
39
                $field->FieldList()->performInuitTransformation();
0 ignored issues
show
Bug introduced by
The method performInuitTransformation() does not exist on FieldList. Did you maybe mean transform()?

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...
40
            }
41
42
            $template = "Inuit{$field->class}_holder";
43
            if (SSViewer::hasTemplate($template)) {
44
                $field->setFieldHolderTemplate($template);
45
            } else {
46
                $field->setFieldHolderTemplate("InuitFormField_holder");
47
            }
48
49
            foreach (array_reverse(ClassInfo::ancestry($field)) as $className) {
50
                $inuitCandidate = "Inuit{$className}";
51
                $nativeCandidate = $className;
52
                if (SSViewer::hasTemplate($inuitCandidate)) {
53
                    $field->setTemplate($inuitCandidate);
54
                    break;
55
                } elseif (SSViewer::hasTemplate($nativeCandidate)) {
56
                    $field->setTemplate($nativeCandidate);
57
                    break;
58
                }
59
            }
60
        }
61
62
        return $this->owner;
63
    }
64
}