UserFormsGroupField::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace SilverStripe\UserForms\FormField;
4
5
use SilverStripe\UserForms\Model\EditableFormField\EditableFieldGroupEnd;
6
use SilverStripe\UserForms\Model\EditableFormField;
7
8
/**
9
 * Front end composite field for userforms
10
 */
11
class UserFormsGroupField extends UserFormsCompositeField
12
{
13
    public function __construct($children = null)
14
    {
15
        parent::__construct($children);
16
        $this->setTag('fieldset');
17
    }
18
19
    public function getLegend()
20
    {
21
        // Legend defaults to title
22
        return parent::getLegend() ?: $this->Title();
23
    }
24
25
    public function processNext(EditableFormField $field)
26
    {
27
        // When ending a group, jump up one level
28
        if ($field instanceof EditableFieldGroupEnd) {
29
            return $this->getParent();
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->getParent() returns the type SilverStripe\UserForms\F...UserFormsFieldContainer 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...
30
        }
31
32
        // Otherwise behave as per normal composite field
33
        return parent::processNext($field);
34
    }
35
}
36