Completed
Push — master ( bec978...be88d7 )
by Peter
01:42
created

PlayersQuery::forPlayerIds()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 4
cts 4
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 1
crap 1
1
<?php
2
3
namespace PtrTn\Battlerite\Query;
4
5
use Webmozart\Assert\Assert;
6
7
class PlayersQuery
8
{
9
    /**
10
     * @var string[]
11
     */
12
    private $playerIds;
13
14 1
    private function __construct()
15
    {
16 1
    }
17
18 1
    public static function create(): self
19
    {
20 1
        return new self();
21
    }
22
23 1
    public function forPlayerIds(array $playerIds)
24
    {
25 1
        Assert::allString($playerIds, 'Specified player ids should be an array of strings');
26 1
        $this->playerIds = $playerIds;
27 1
        return $this;
28
    }
29
30 1
    public function toQueryString(): ?string
31
    {
32 1
        $query = [];
33 1
        if (!empty($this->playerIds)) {
34 1
            $query['filter[playerIds]'] = implode(',', $this->playerIds);
35
        }
36
37 1
        if (!empty($query)) {
38 1
            return http_build_query($query);
39
        }
40
41
        return null;
42
    }
43
}
44