Test Failed
Pull Request — master (#214)
by
unknown
12:27
created

LoadMultipleTrait::getModels()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Form;
6
7
trait LoadMultipleTrait
8
{
9
    private array $models = [];
10
11
    public function loadMultiple(array $data, ?string $formName = null): bool
12
    {
13
        if ($formName === null) {
14
            /* @var \Yiisoft\Form\FormModelInterface $this */
15
            $formName = $this->getFormName();
16
        }
17
18
        if ($formName !== '') {
19
            $data = $data[$formName];
20
        }
21
22
        $success = true;
23
24
        foreach (array_keys($data) as $i) {
25
            /* @var \Yiisoft\Form\FormModelInterface $model */
26
            $model = clone $this;
27
28
            if ($model->load($data[$i], '') === true) {
29
                $this->models[] = $model;
30
            } else {
31
                $this->models[] = $success = false;
32
            }
33
        }
34
35
        return $success;
36
    }
37
38
    public function getModels(): array
39
    {
40
        return $this->models;
41
    }
42
}
43