Test Failed
Pull Request — master (#20)
by Vladislav
02:49
created

WalletBalanceTest::testSuccessEndpoint()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 81
Code Lines 22

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 22
nc 2
nop 0
dl 0
loc 81
rs 9.568
c 0
b 0
f 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
namespace Carpenstar\ByBitAPI\Derivatives\Contract\Account\WalletBalance\Tests;
3
4
use Carpenstar\ByBitAPI\BybitAPI;
5
use Carpenstar\ByBitAPI\Derivatives\Contract\Account\WalletBalance\Interfaces\IWalletBalanceResponseItemInterface;
6
use Carpenstar\ByBitAPI\Derivatives\Contract\Account\WalletBalance\Request\WalletBalanceRequest;
7
use Carpenstar\ByBitAPI\Derivatives\Contract\Account\WalletBalance\WalletBalance;
8
use PHPUnit\Framework\TestCase;
9
10
class WalletBalanceTest extends TestCase
11
{
12
    public function testSuccessEndpoint()
13
    {
14
        $bybit = (new BybitAPI())->setCredentials('https://api-testnet.bybit.com','fL02oi5qo8i2jDxlum', 'Ne1EE35XTprIWrId9vGEAc1ZYJTmodA4qFzZ');
0 ignored issues
show
Bug introduced by
The call to Carpenstar\ByBitAPI\BybitAPI::__construct() has too few arguments starting with host. ( Ignorable by Annotation )

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

14
        $bybit = (/** @scrutinizer ignore-call */ new BybitAPI())->setCredentials('https://api-testnet.bybit.com','fL02oi5qo8i2jDxlum', 'Ne1EE35XTprIWrId9vGEAc1ZYJTmodA4qFzZ');

This check compares calls to functions or methods with their respective definitions. If the call has less arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
Bug introduced by
The method setCredentials() does not exist on Carpenstar\ByBitAPI\BybitAPI. ( Ignorable by Annotation )

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

14
        $bybit = (new BybitAPI())->/** @scrutinizer ignore-call */ setCredentials('https://api-testnet.bybit.com','fL02oi5qo8i2jDxlum', 'Ne1EE35XTprIWrId9vGEAc1ZYJTmodA4qFzZ');

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
15
16
        $response = $bybit->privateEndpoint(WalletBalance::class, (new WalletBalanceRequest()))->execute();
17
18
        echo "Return code: {$response->getReturnCode()} \n";
19
        echo "Return message: {$response->getReturnMessage()} \n";
20
21
        $walletBalances = array_slice($response->getResult()->getBalances(), 0, 3);
22
23
        /** @var IWalletBalanceResponseItemInterface $balance */
24
        foreach ($walletBalances as $balance) {
25
            echo "----- \n";
26
            echo "Coin: {$balance->getCoin()} \n";
27
            echo "Equity: {$balance->getEquity()} \n";
28
            echo "Wallet Balance: {$balance->getWalletBalance()} \n";
29
            echo "Position Margin: {$balance->getPositionMargin()} \n";
30
            echo "Available Balance: {$balance->getAvailableBalance()} \n";
31
            echo "Order Margin: {$balance->getOrderMargin()} \n";
32
            echo "Occ Closing Fee: {$balance->getOccClosingFee()} \n";
33
            echo "Occ Funding Fee: {$balance->getOccFundingFee()} \n";
34
            echo "Unrealised PnL: {$balance->getUnrealisedPnl()} \n";
35
            echo "Cumulative Realised PnL: {$balance->getCumRealisedPnl()} \n";
36
            echo "Given Cash: {$balance->getGivenCash()} \n";
37
            echo "Service Cash: {$balance->getServiceCash()} \n";
38
            echo "Account IM: {$balance->getAccountIM()} \n";
39
            echo "Account MM: {$balance->getAccountMM()} \n";
40
        }
41
42
        /**
43
         * Return code: 0
44
         * Return message: OK
45
         * -----
46
         * Coin: BTC
47
         * Equity: 0.2
48
         * Wallet Balance: 0.2
49
         * Position Margin: 0
50
         * Available Balance: 0.2
51
         * Order Margin: 0
52
         * Occ Closing Fee: 0
53
         * Occ Funding Fee: 0
54
         * Unrealised PnL: 0
55
         * Cumulative Realised PnL: 0
56
         * Given Cash: 0
57
         * Service Cash: 0
58
         * Account IM:
59
         * Account MM:
60
         * -----
61
         * Coin: ETH
62
         * Equity: 0
63
         * Wallet Balance: 0
64
         * Position Margin: 0
65
         * Available Balance: 0
66
         * Order Margin: 0
67
         * Occ Closing Fee: 0
68
         * Occ Funding Fee: 0
69
         * Unrealised PnL: 0
70
         * Cumulative Realised PnL: 0
71
         * Given Cash: 0
72
         * Service Cash: 0
73
         * Account IM:
74
         * Account MM:
75
         * -----
76
         * Coin: EOS
77
         * Equity: 0
78
         * Wallet Balance: 0
79
         * Position Margin: 0
80
         * Available Balance: 0
81
         * Order Margin: 0
82
         * Occ Closing Fee: 0
83
         * Occ Funding Fee: 0
84
         * Unrealised PnL: 0
85
         * Cumulative Realised PnL: 0
86
         * Given Cash: 0
87
         * Service Cash: 0
88
         * Account IM:
89
         * Account MM:
90
         */
91
92
        $this->assertTrue(true);
93
    }
94
95
}