Passed
Push — master ( 54c1b4...a67e0e )
by Vladislav
11:20 queued 09:15
created

SuccessResponse::getNextPageCursor()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Carpenstar\ByBitAPI\Core\Objects;
4
5
use Carpenstar\ByBitAPI\Core\Builders\ResponseDtoBuilder;
6
use Carpenstar\ByBitAPI\Core\Interfaces\IResponseInterface;
7
use Carpenstar\ByBitAPI\Core\Interfaces\ISuccessCurlResponseDtoInterface;
8
use Carpenstar\ByBitAPI\Core\Objects\Collection\EntityCollection;
9
10
class SuccessResponse implements ISuccessCurlResponseDtoInterface, IResponseInterface
11
{
12
    private int $retCode;
13
    private string $retMsg;
14
    private array $retExtInfo;
15
    private ?string $nextPageCursor;
16
    private AbstractResponse $result;
17
18
    public function __construct(string $responseClassName, int $retCode, string $retMsg, ?array $retExtInfo, array $result, ?string $nextPageCursor = null)
19
    {
20
        $this->retCode = $retCode;
21
        $this->retMsg = $retMsg;
22
        $this->retExtInfo = $retExtInfo ?? [];
23
        $this->nextPageCursor = $nextPageCursor;
24
        $this->result = $this->draw([$result], $responseClassName);
25
    }
26
27
    public function getReturnCode(): int
28
    {
29
        return $this->retCode;
30
    }
31
32
    public function getReturnMessage(): string
33
    {
34
        return $this->retMsg;
35
    }
36
37
    public function getNextPageCursor(): ?string
38
    {
39
        return $this->nextPageCursor;
40
    }
41
42
    public function getResult(): AbstractResponse
43
    {
44
        return $this->result;
45
    }
46
47
    protected function draw(array $result, string $responseClassName): AbstractResponse
48
    {
49
        $collection = new EntityCollection();
50
        array_walk($result, function ($item) use ($collection, $responseClassName) {
51
            $collection->push(ResponseDtoBuilder::make($responseClassName, $item));
52
        });
53
54
        return $collection->fetch();
0 ignored issues
show
Bug Best Practice introduced by
The expression return $collection->fetch() returns the type null which is incompatible with the type-hinted return Carpenstar\ByBitAPI\Core\Objects\AbstractResponse.
Loading history...
55
    }
56
57
    public function getExtendedInfo(): array
58
    {
59
        return $this->retExtInfo;
60
    }
61
}