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

SupportedAddonsLoader::doRequest()   C

Complexity

Conditions 12
Paths 8

Size

Total Lines 44
Code Lines 23

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 12
eloc 23
nc 8
nop 0
dl 0
loc 44
rs 5.1612
c 0
b 0
f 0

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace BringYourOwnIdeas\Maintenance\Util;
4
5
/**
6
 * Handles fetching supported addon details from addons.silverstripe.org
7
 */
8
class SupportedAddonsLoader extends ApiLoader
9
{
10
    /**
11
     * Return the list of supported addons as provided by addons.silverstripe.org
12
     *
13
     * @return array
14
     */
15
    public function getAddonNames()
16
    {
17
        $endpoint = 'addons.silverstripe.org/api/supported-addons';
18
        return $this->doRequest($endpoint, function ($responseBody) {
19
            return isset($responseBody['addons']) ? $responseBody['addons'] : [];
20
        });
21
    }
22
23
    protected function getCacheKey()
24
    {
25
        return 'addons';
26
    }
27
}
28