Passed
Push — master ( fcb909...cb681d )
by Robbie
02:26
created

ModuleHealthLoader::getModuleHealthInfo()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 1
nop 0
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace BringYourOwnIdeas\Maintenance\Util;
4
5
/**
6
 * Handles fetching module health information from addons.silverstripe.org
7
 */
8
class ModuleHealthLoader extends ApiLoader
9
{
10
    /**
11
     * @var string[]
12
     */
13
    protected $moduleNames = [];
14
15
    /**
16
     * Return the list of supported addons as provided by addons.silverstripe.org
17
     *
18
     * @return array
19
     */
20
    public function getModuleHealthInfo()
21
    {
22
        $addons = $this->getModuleNames();
23
        $endpoint = 'addons.silverstripe.org/api/ratings?addons=' . implode(',', $addons);
24
        return $this->doRequest($endpoint, function ($responseBody) {
25
            return isset($responseBody) ? $responseBody['ratings'] : [];
26
        });
27
    }
28
29
    /**
30
     * @return string[]
31
     */
32
    public function getModuleNames()
33
    {
34
        return $this->moduleNames;
35
    }
36
37
    /**
38
     * @param string[] $moduleNames
39
     * @return $this
40
     */
41
    public function setModuleNames(array $moduleNames)
42
    {
43
        $this->moduleNames = $moduleNames;
44
        return $this;
45
    }
46
47
    protected function getCacheKey()
48
    {
49
        return sha1(json_encode($this->getModuleNames()));
50
    }
51
}
52