Group::GetGroupSummary()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 26

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 26
ccs 10
cts 10
cp 1
rs 9.504
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 2
1
<?php
2
3
namespace Syntax\SteamApi\Steam;
4
5
use Syntax\SteamApi\Client;
6
use Syntax\SteamApi\Containers\Group as GroupContainer;
7
8
class Group extends Client
9
{
10 2
    public function GetGroupSummary($group)
11
    {
12
        // Set up the api details
13 2
        $this->method = 'memberslistxml';
14
15 2
        if (is_numeric($group)) {
16 1
            $this->url = 'http://steamcommunity.com/gid/';
17
        } else {
18 1
            $this->url = 'http://steamcommunity.com/groups/';
19
        }
20
21 2
        $this->url = $this->url . $group;
22
23
        // Set up the arguments
24
        $arguments = [
25 2
            'xml' => 1,
26
        ];
27
28
        // Get the client
29 2
        $client = $this->setUpXml($arguments);
30
31
        // Clean up the games
32 2
        $group = new GroupContainer($client);
0 ignored issues
show
Bug introduced by
It seems like $client defined by $this->setUpXml($arguments) on line 29 can be null; however, Syntax\SteamApi\Containers\Group::__construct() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
33
34 2
        return $group;
35
    }
36
}
37