1 | <?php |
||
2 | |||
3 | namespace SilverStripe\UserForms\FormField; |
||
4 | |||
5 | use SilverStripe\Forms\CompositeField; |
||
6 | use SilverStripe\UserForms\Model\EditableFormField; |
||
7 | use SilverStripe\UserForms\Model\EditableFormField\EditableFormStep; |
||
8 | |||
9 | /** |
||
10 | * Represents a composite field group, which may contain other groups |
||
11 | */ |
||
12 | abstract class UserFormsCompositeField extends CompositeField implements UserFormsFieldContainer |
||
13 | { |
||
14 | /** |
||
15 | * Parent field |
||
16 | * |
||
17 | * @var UserFormsFieldContainer |
||
18 | */ |
||
19 | protected $parent = null; |
||
20 | |||
21 | public function getParent() |
||
22 | { |
||
23 | return $this->parent; |
||
24 | } |
||
25 | |||
26 | public function setParent(UserFormsFieldContainer $parent) |
||
27 | { |
||
28 | $this->parent = $parent; |
||
29 | return $this; |
||
30 | } |
||
31 | |||
32 | public function processNext(EditableFormField $field) |
||
33 | { |
||
34 | // When we find a step, bubble up to the top |
||
35 | if ($field instanceof EditableFormStep) { |
||
36 | return $this->getParent()->processNext($field); |
||
37 | } |
||
38 | |||
39 | // Skip over fields that don't generate formfields |
||
40 | if (get_class($field) === EditableFormField::class || !$field->getFormField()) { |
||
41 | return $this; |
||
0 ignored issues
–
show
|
|||
42 | } |
||
43 | /** @var EditableFormField $formField */ |
||
44 | $formField = $field->getFormField(); |
||
45 | |||
46 | // Save this field |
||
47 | $this->push($formField); |
||
48 | |||
49 | // Nest fields that are containers |
||
50 | if ($formField instanceof UserFormsFieldContainer) { |
||
51 | return $formField->setParent($this); |
||
52 | } |
||
53 | |||
54 | // Add any subsequent fields to this |
||
55 | return $this; |
||
0 ignored issues
–
show
The expression
return $this returns the type SilverStripe\UserForms\F...UserFormsCompositeField 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...
|
|||
56 | } |
||
57 | } |
||
58 |
In the issue above, the returned value is violating the contract defined by the mentioned interface.
Let's take a look at an example: