Passed
Push — master ( ebdfbb...20570e )
by
unknown
02:32
created

code/FormField/UserFormsFieldList.php (1 issue)

1
<?php
2
3
namespace SilverStripe\UserForms\FormField;
4
5
use SilverStripe\Forms\FieldList;
6
use SilverStripe\UserForms\Model\EditableFormField;
7
8
/**
9
 * A list of formfields which allows for iterative processing of nested composite fields
10
 */
11
class UserFormsFieldList extends FieldList implements UserFormsFieldContainer
12
{
13
    public function processNext(EditableFormField $field)
14
    {
15
        $formField = $field->getFormField();
16
        if (!$formField) {
17
            return $this;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this returns the type SilverStripe\UserForms\F...ield\UserFormsFieldList which is incompatible with the return type mandated by SilverStripe\UserForms\F...ontainer::processNext() of SilverStripe\UserForms\F...\EditableContainerField.

In the issue above, the returned value is violating the contract defined by the mentioned interface.

Let's take a look at an example:

interface HasName {
    /** @return string */
    public function getName();
}

class Name {
    public $name;
}

class User implements HasName {
    /** @return string|Name */
    public function getName() {
        return new Name('foo'); // This is a violation of the ``HasName`` interface
                                // which only allows a string value to be returned.
    }
}
Loading history...
18
        }
19
20
        $this->push($formField);
21
22
        if ($formField instanceof UserFormsFieldContainer) {
23
            return $formField->setParent($this);
24
        }
25
26
        return $this;
27
    }
28
29
    public function getParent()
30
    {
31
        // Field list does not have a parent
32
        return null;
33
    }
34
35
    public function setParent(UserFormsFieldContainer $parent)
36
    {
37
        return $this;
38
    }
39
40
    /**
41
     * Remove all empty steps
42
     */
43
    public function clearEmptySteps()
44
    {
45
        foreach ($this as $field) {
46
            if ($field instanceof UserFormsStepField && count($field->getChildren()) === 0) {
47
                $this->remove($field);
48
            }
49
        }
50
    }
51
}
52