| Conditions | 1 |
| Paths | 1 |
| Total Lines | 51 |
| Code Lines | 38 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
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:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 54 | public function testGetOrderEndpoint() |
||
| 55 | { |
||
| 56 | $bybit = (new BybitAPI())->setCredentials('https://api-testnet.bybit.com', 'fL02oi5qo8i2jDxlum', 'Ne1EE35XTprIWrId9vGEAc1ZYJTmodA4qFzZ'); |
||
| 57 | |||
| 58 | $params = (new PlaceOrderRequest()) |
||
| 59 | ->setSide(EnumSide::BUY) |
||
| 60 | ->setOrderType(EnumOrderType::LIMIT) |
||
| 61 | ->setOrderPrice(3000) |
||
| 62 | ->setSymbol("ETHUSDT") |
||
| 63 | ->setOrderQty(1); |
||
| 64 | |||
| 65 | |||
| 66 | $placeOrderEndpoint = $bybit->privateEndpoint(PlaceOrder::class, $params)->execute(); |
||
| 67 | |||
| 68 | /** @var PlaceOrderResponse $orderInfo */ |
||
| 69 | $orderInfo = $placeOrderEndpoint->getResult(); |
||
| 70 | |||
| 71 | $this->assertNotEmpty($orderInfo->getOrderId()); |
||
| 72 | $this->assertNotEmpty($orderInfo->getOrderLinkId()); |
||
| 73 | $this->assertEquals('ETHUSDT', $orderInfo->getSymbol()); |
||
| 74 | $this->assertInstanceOf(\DateTime::class, $orderInfo->getCreateTime()); |
||
| 75 | $this->assertTrue($orderInfo->getOrderPrice() == 3000); |
||
| 76 | $this->assertTrue($orderInfo->getOrderQty() == 1); |
||
| 77 | $this->assertEquals(strtoupper(EnumOrderType::LIMIT), $orderInfo->getOrderType()); |
||
| 78 | $this->assertEquals(strtoupper(EnumSide::BUY), $orderInfo->getSide()); |
||
| 79 | $this->assertEquals('NEW', $orderInfo->getStatus()); |
||
| 80 | $this->assertEquals('GTC', $orderInfo->getTimeInForce()); |
||
| 81 | $this->assertNotEmpty($orderInfo->getAccountId()); |
||
| 82 | $this->assertEmpty($orderInfo->getTriggerPrice()); |
||
| 83 | |||
| 84 | $getOrderResponse = $bybit->privateEndpoint(GetOrder::class, (new GetOrderRequest())->setOrderId($orderInfo->getOrderId()))->execute(); |
||
| 85 | |||
| 86 | $this->assertEquals(0, $getOrderResponse->getReturnCode()); |
||
| 87 | $this->assertEquals('OK', $getOrderResponse->getReturnMessage()); |
||
| 88 | $this->assertInstanceOf(GetOrderResponse::class, $getOrderResponse->getResult()); |
||
| 89 | |||
| 90 | /** @var GetOrderResponse $getOrderInfo */ |
||
| 91 | $getOrderInfo = $getOrderResponse->getResult(); |
||
| 92 | |||
| 93 | $this->assertIsInt($getOrderInfo->getOrderId()); |
||
| 94 | $this->assertIsString($getOrderInfo->getOrderLinkId()); |
||
| 95 | $this->assertIsString($getOrderInfo->getSymbol()); |
||
| 96 | $this->assertIsString($getOrderInfo->getStatus()); |
||
| 97 | $this->assertIsInt($getOrderInfo->getAccountId()); |
||
| 98 | $this->assertIsFloat($getOrderInfo->getOrderPrice()); |
||
| 99 | $this->assertInstanceOf(\DateTime::class, $getOrderInfo->getCreateTime()); |
||
| 100 | $this->assertIsFloat($getOrderInfo->getOrderQty()); |
||
| 101 | $this->assertIsFloat($getOrderInfo->getExecQty()); |
||
| 102 | $this->assertIsString($getOrderInfo->getTimeInForce()); |
||
| 103 | $this->assertIsString($getOrderInfo->getOrderType()); |
||
| 104 | $this->assertIsString($getOrderInfo->getSide()); |
||
| 105 | } |
||
| 106 | } |