Passed
Push — master ( 6045bf...dbb88a )
by Patrick
03:21
created

GitlabApi::getEvents()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 1
dl 0
loc 9
ccs 6
cts 6
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of forecast.it.fill project.
7
 * (c) Patrick Jaja <[email protected]>
8
 * This source file is subject to the MIT license that is bundled
9
 * with this source code in the file LICENSE.
10
 */
11
12
namespace ForecastAutomation\GitlabClient\Business;
13
14
use ForecastAutomation\GitlabClient\Shared\Dto\GitlabConfigDto;
15
use ForecastAutomation\GitlabClient\Shared\Dto\GitlabQueryDto;
16
use GuzzleHttp\Client;
17
18
class GitlabApi
19
{
20
    private const EVENTS_API = '/api/v4/events';
21
22 1
    public function __construct(private Client $guzzleClient, private GitlabConfigDto $gitlabConfigDto)
23
    {
24 1
    }
25
26 1
    public function getEvents(GitlabQueryDto $queryDto): array
27
    {
28 1
        $res = $this->guzzleClient->request(
29 1
            'GET',
30 1
            self::EVENTS_API,
31 1
            ['query' => array_merge((array) $queryDto, $this->getToken())],
32
        );
33
34 1
        return json_decode((string) $res->getBody(), null, 512, JSON_THROW_ON_ERROR);
35
    }
36
37 1
    private function getToken(): array
38
    {
39 1
        return ['private_token' => $this->gitlabConfigDto->gitlabToken];
40
    }
41
}
42