• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

lmc-eu / matej-client-php / 7527331519

15 Jan 2024 10:11AM UTC coverage: 100.0%. Remained the same
7527331519

Pull #135

github

web-flow
Merge 117257645 into 9666a6254
Pull Request #135: Update to new coding standard

20 of 21 new or added lines in 5 files covered. (95.24%)

400 existing lines in 23 files now uncovered.

758 of 758 relevant lines covered (100.0%)

18.54 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

100.0
/src/Http/ResponseDecoder.php
1
<?php declare(strict_types=1);
2

3
namespace Lmc\Matej\Http;
4

5
use Lmc\Matej\Exception\ResponseDecodingException;
6
use Lmc\Matej\Model\Response;
7
use Psr\Http\Message\ResponseInterface;
8

9
class ResponseDecoder implements ResponseDecoderInterface
10
{
11
    public function decode(ResponseInterface $httpResponse, string $responseClass = Response::class): Response
12
    {
UNCOV
13
        $responseData = json_decode($httpResponse->getBody()->getContents());
24✔
14

UNCOV
15
        if (json_last_error() !== JSON_ERROR_NONE) {
24✔
UNCOV
16
            throw ResponseDecodingException::forJsonError(json_last_error_msg(), $httpResponse);
4✔
17
        }
18

UNCOV
19
        if (!$this->isResponseValid($responseData)) {
20✔
UNCOV
20
            throw ResponseDecodingException::forInvalidData($httpResponse);
4✔
21
        }
22

UNCOV
23
        $responseId = $httpResponse->getHeader(RequestManager::RESPONSE_ID_HEADER)[0] ?? null;
16✔
24

NEW
UNCOV
25
        return new $responseClass(
16✔
UNCOV
26
            (int) $responseData->commands->number_of_commands,
16✔
UNCOV
27
            (int) $responseData->commands->number_of_successful_commands,
16✔
UNCOV
28
            (int) $responseData->commands->number_of_failed_commands,
16✔
UNCOV
29
            (int) $responseData->commands->number_of_skipped_commands,
16✔
UNCOV
30
            $responseData->commands->responses,
16✔
UNCOV
31
            $responseId
12✔
UNCOV
32
        );
12✔
33
    }
34

35
    private function isResponseValid(\stdClass $responseData): bool
36
    {
UNCOV
37
        return isset(
15✔
UNCOV
38
            $responseData->commands,
20✔
UNCOV
39
            $responseData->commands->number_of_commands,
20✔
UNCOV
40
            $responseData->commands->number_of_successful_commands,
20✔
UNCOV
41
            $responseData->commands->number_of_failed_commands,
20✔
UNCOV
42
            $responseData->commands->number_of_skipped_commands,
20✔
UNCOV
43
            $responseData->commands->responses,
20✔
UNCOV
44
            $responseData->message,
20✔
UNCOV
45
            $responseData->status
20✔
UNCOV
46
        );
15✔
47
    }
48
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc