Passed
Push — master ( a6819e...14f211 )
by
unknown
09:28 queued 02:18
created

MiniGroupList::findBySlug()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 4
c 1
b 0
f 0
nc 3
nop 1
dl 0
loc 7
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace MySociety\TheyWorkForYou\DataClass\Groups;
6
7
use MySociety\TheyWorkForYou\DataClass\BaseCollection;
8
9
/**
10
 * @extends BaseCollection<MiniGroup>
11
 */
12
class MiniGroupList extends BaseCollection {
13
    public function __construct(MiniGroup ...$members) {
14
        $this->items = $members;
0 ignored issues
show
Documentation Bug introduced by
It seems like $members of type array<integer,MySociety\...Class\Groups\MiniGroup> is incompatible with the declared type Rutek\Dataclass\T[] of property $items.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
15
    }
16
17
    public function findByName(string $name): ?MiniGroup {
18
        foreach ($this->items as $member) {
19
            if ($member->name === $name) {
20
                return $member;
21
            }
22
        }
23
        return null;
24
    }
25
26
    public function findBySlug(string $slug): ?MiniGroup {
27
        foreach ($this->items as $member) {
28
            if ($member->slug === $slug) {
29
                return $member;
30
            }
31
        }
32
        return null;
33
    }
34
35
    public static function uk_committees(): self {
36
        $file_dir = RAWDATA . "scrapedjson/committees/uk_committees_groups.json";
0 ignored issues
show
Bug introduced by
The constant MySociety\TheyWorkForYou\DataClass\Groups\RAWDATA was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
37
38
        $result = self::fromCachedFile($file_dir);
39
        // if $result is null the file isn't present, return an empty list
40
        if ($result === null) {
41
            return new self();
42
        }
43
        return $result;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $result returns the type MySociety\TheyWorkForYou\DataClass\BaseInterface which includes types incompatible with the type-hinted return MySociety\TheyWorkForYou...ss\Groups\MiniGroupList.
Loading history...
44
    }
45
}
46