indexPriceKlineTest   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 22
c 1
b 0
f 0
dl 0
loc 33
rs 10
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A testSuccessEndpoint() 0 31 3
1
<?php
2
3
namespace Carpenstar\ByBitAPI\Derivatives\MarketData\IndexPriceKline\Tests;
4
5
use Carpenstar\ByBitAPI\BybitAPI;
6
use Carpenstar\ByBitAPI\Core\Enums\EnumIntervals;
7
use Carpenstar\ByBitAPI\Derivatives\MarketData\IndexPriceKline\IndexPriceKline;
8
use Carpenstar\ByBitAPI\Derivatives\MarketData\IndexPriceKline\Request\IndexPriceKlineRequest;
9
use Carpenstar\ByBitAPI\Derivatives\MarketData\IndexPriceKline\Response\IndexPriceKlineResponseItem;
10
use PHPUnit\Framework\TestCase;
11
12
class indexPriceKlineTest extends TestCase
13
{
14
    public function testSuccessEndpoint()
15
    {
16
        echo "\n //// --- //// \n";
17
18
        $bybit = (new BybitAPI())->setCredentials('https://api-testnet.bybit.com');
19
20
        $response = $bybit->publicEndpoint(IndexPriceKline::class,
21
            (new IndexPriceKlineRequest())->setSymbol('BTCUSDT')->setInterval(EnumIntervals::HOUR_1)->setStart('2024-07-26 10:00:00')->setEnd('2024-07-27 11:00:00')->setLimit(4)
22
        )->execute();
23
24
25
        if ($response->getReturnCode() == 0) {
26
            echo "CODE: {$response->getReturnCode()}\n";
27
            echo "MESSAGE: {$response->getReturnMessage()}\n";
28
    
29
            /** @var IndexPriceKlineResponseItem $indexItem */
30
            foreach ($response->getResult()->getKlineList() as $indexItem) {
0 ignored issues
show
Bug introduced by
The method getKlineList() does not exist on Carpenstar\ByBitAPI\Core\Objects\AbstractResponse. It seems like you code against a sub-type of Carpenstar\ByBitAPI\Core\Objects\AbstractResponse such as Carpenstar\ByBitAPI\Deri...\Response\KlineResponse or Carpenstar\ByBitAPI\Deri...IndexPriceKlineResponse or Carpenstar\ByBitAPI\Deri...\MarkPriceKlineResponse. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

30
            foreach ($response->getResult()->/** @scrutinizer ignore-call */ getKlineList() as $indexItem) {
Loading history...
31
                echo " --- \n";
32
                echo "Start Time: {$indexItem->getStartTime()->format('Y-m-d H:i:s')}\n";
33
                echo "Open Price: {$indexItem->getOpen()}\n";
34
                echo "High Price: {$indexItem->getHigh()}\n";
35
                echo "Low Price: {$indexItem->getLow()}\n";
36
                echo "Close Price: {$indexItem->getClose()}\n";
37
            }
38
    
39
            $this->assertTrue(true);    
40
        } else {
41
            echo "API ERORR: " . get_class($this) . "\n";
42
            echo "CODE: {$response->getReturnCode()} \n"; 
43
            echo "MESSAGE: {$response->getReturnMessage()} \n"; 
44
            echo "EXTENDED:" . implode(";\n", $response->getExtendedInfo()) . "\n"; 
45
        }
46
    }
47
}
48