Issues (138)

src/Traits/HasDisplayGroupsTrait.php (1 issue)

Labels
Severity
1
<?php
2
3
namespace Nip\Form\Traits;
4
5
use Nip_Form_DisplayGroup;
6
7
/**
8
 * Trait HasDisplayGroupsTrait
9
 * @package Nip\Form\Traits
10
 */
11
trait HasDisplayGroupsTrait
12
{
13
    protected $_displayGroups = [];
14
15
    /**
16
     * Add a display group
17
     * Groups named elements for display purposes.
18
     * @param array $elements
19
     * @param $name
20
     * @return $this
21
     */
22 1
    public function addDisplayGroup(array $elements, $name)
23
    {
24 1
        $group = $this->newDisplayGroup();
25 1
        foreach ($elements as $element) {
26 1
            if (isset($this->_elements[$element])) {
27 1
                $add = $this->getElement($element);
0 ignored issues
show
It seems like getElement() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

27
                /** @scrutinizer ignore-call */ 
28
                $add = $this->getElement($element);
Loading history...
28 1
                if (null !== $add) {
29 1
                    $group->addElement($add);
30
                }
31
            }
32
        }
33 1
        if (empty($group)) {
34
            trigger_error('No valid elements specified for display group');
35
        }
36
37 1
        $name = (string)$name;
38 1
        $group->setLegend($name);
39
40 1
        $this->_displayGroups[$name] = $group;
41
42 1
        return $this;
43
    }
44
45
    /**
46
     * @return Nip_Form_DisplayGroup
47
     */
48 1
    public function newDisplayGroup()
49
    {
50 1
        $group = new Nip_Form_DisplayGroup();
51 1
        $group->setForm($this);
52
53 1
        return $group;
54
    }
55
56
    /**
57
     * @param string $name
58
     * @return Nip_Form_DisplayGroup
59
     */
60 1
    public function getDisplayGroup($name)
61
    {
62 1
        if (array_key_exists($name, $this->_displayGroups)) {
63 1
            return $this->_displayGroups[$name];
64
        }
65
66
        return null;
67
    }
68
69
    /**
70
     * @return Nip_Form_DisplayGroup[]
71
     */
72
    public function getDisplayGroups()
73
    {
74
        return $this->_displayGroups;
75
    }
76
}
77