Passed
Pull Request — master (#1834)
by
unknown
05:14
created

Base::display()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 20
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 13
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 20
rs 9.8333
1
<?php
2
3
namespace MySociety\TheyWorkForYou\Homepage;
4
5
abstract class Base {
6
    public function display() {
7
        global $this_page;
8
        $this_page = $this->page;
9
10
        $data = [];
11
12
        $common = new \MySociety\TheyWorkForYou\Common();
13
14
        $data['debates'] = $this->getDebatesData();
15
16
        $user = new \MySociety\TheyWorkForYou\User();
17
        $data['mp_data'] = $user->getRep($this->cons_type, $this->mp_house);
18
19
        $data['regional'] = $this->getRegionalList();
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $data['regional'] is correct as $this->getRegionalList() targeting MySociety\TheyWorkForYou...Base::getRegionalList() seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
20
        $data['popular_searches'] = $common->getPopularSearches();
21
        $data['featured'] = $this->getEditorialContent($data);
22
        $data['divisions'] = $this->getRecentDivisions();
23
        $data['search_box'] = $this->getSearchBox($data);
24
25
        return $data;
26
    }
27
28
    abstract protected function getSearchBox(array $data): \MySociety\TheyWorkForYou\Search\SearchBox;
29
    abstract protected function getEditorialContent(array &$data);
30
31
    protected function getRegionalList() {
32
        return null;
33
    }
34
35
    private function getRecentDivisions() {
36
        $divisions = new \MySociety\TheyWorkForYou\Divisions();
37
        return $divisions->getRecentDebatesWithDivisions(5, $this->houses);
38
    }
39
40
    protected function getDebatesData() {
41
        $debates = []; // holds the most recent data there is data for, indexed by type
42
43
        $recent_content = [];
44
45
        foreach ($this->recent_types as $class => $recent) {
46
            $class = "\\$class";
47
            $instance = new $class();
48
            $more_url = new \MySociety\TheyWorkForYou\Url($recent[1]);
49
            if ($recent[0] == 'recent_pbc_debates') {
50
                $content = [ 'data' => $instance->display($recent[0], ['num' => 5], 'none') ];
51
            } elseif ($recent[1] == 'senedddebatesfront' || $recent[1] == 'nidebatesfront') {
52
                $content = $instance->display($recent[0], ['days' => 30, 'num' => 6], 'none');
53
                # XXX Bit hacky, for now
54
                foreach ($content['data'] as $d) {
55
                    $d['more_url'] = $more_url->generate();
56
                    $d['desc'] = '';
57
                    $recent_content[] = $d;
58
                }
59
                $content = [];
60
            } else {
61
                $content = $instance->display($recent[0], ['days' => 7, 'num' => 1], 'none');
62
                if (isset($content['data']) && count($content['data'])) {
63
                    $content = $content['data'][0];
64
                } else {
65
                    $content = [];
66
                }
67
            }
68
            if ($content) {
69
                $content['more_url'] = $more_url->generate();
70
                $content['desc'] = $recent[2];
71
                $recent_content[] = $content;
72
            }
73
        }
74
75
        $debates['recent'] = $recent_content;
76
77
        return $debates;
78
    }
79
}
80