Passed
Pull Request — master (#1856)
by
unknown
05:30
created

Detail::has_value()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 3
c 1
b 0
f 0
nc 2
nop 0
dl 0
loc 9
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace MySociety\TheyWorkForYou\DataClass\Regmem;
6
7
use MySociety\TheyWorkForYou\DataClass\BaseModel;
8
9
class Detail extends BaseModel {
10
    public string $source;
11
    public ?string $slug = null;
12
    public ?string $display_as = null;
13
    public ?string $common_key = null;
14
    public ?string $description = null;
15
    public ?string $type = null;
16
    public $value = null;
17
    public AnnotationList $annotations;
18
19
20
    public function has_value(): bool {
21
        // if not null or empty string when removing trailing whitespace
22
23
        // if string, trim and return false if empty
24
        if (is_string($this->value)) {
25
            return trim($this->value) !== '';
26
        }
27
28
        return $this->value !== null;
29
    }
30
31
    /**
32
     * @return \Iterator<Detail>|
33
     */
34
    public function sub_details(): \Iterator {
35
        $items = new \ArrayIterator();
36
37
        if (!$this->type === 'container') {
0 ignored issues
show
introduced by
The condition ! $this->type === 'container' is always false.
Loading history...
38
            return $items;
39
        }
40
41
42
        foreach ($this->value as $detail_group) {
43
            foreach ($detail_group as $detail) {
44
                $detail_obj = self::fromArray($detail);
45
                $items[] = $detail_obj;
46
            }
47
        }
48
49
        return $items;
50
    }
51
52
}
53