Skip to content

Commit

Permalink
Небольшие исправления форматирования
Browse files Browse the repository at this point in the history
  • Loading branch information
visavi committed Dec 12, 2023
1 parent eb0a664 commit cdda308
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 22 deletions.
44 changes: 26 additions & 18 deletions src/Rzd/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Rzd;

use GuzzleHttp\Exception\GuzzleException;
use JsonException;

class Api
{
Expand Down Expand Up @@ -50,7 +51,7 @@ public function __construct(Config $config = null)
* @param array $params Массив параметров
*
* @return string
* @throws GuzzleException
* @throws GuzzleException|JsonException
*/
public function trainRoutes(array $params): string
{
Expand All @@ -59,7 +60,7 @@ public function trainRoutes(array $params): string
];
$routes = $this->query->get($this->path, $layer + $params);

return json_encode($routes->tp[0]->list, JSON_UNESCAPED_UNICODE);
return json_encode($routes->tp[0]->list, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE);
}

/**
Expand All @@ -68,7 +69,7 @@ public function trainRoutes(array $params): string
* @param array $params Массив параметров
*
* @return string
* @throws GuzzleException
* @throws GuzzleException|JsonException
*/
public function trainRoutesReturn(array $params): string
{
Expand All @@ -78,9 +79,11 @@ public function trainRoutesReturn(array $params): string
$routes = $this->query->get($this->path, $layer + $params);

return json_encode([
'forward' => $routes->tp[0]->list,
'back' => $routes->tp[1]->list
], JSON_UNESCAPED_UNICODE);
'forward' => $routes->tp[0]->list,
'back' => $routes->tp[1]->list,
],
JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE
);
}

/**
Expand All @@ -89,7 +92,7 @@ public function trainRoutesReturn(array $params): string
* @param array $params Массив параметров
*
* @return string
* @throws GuzzleException
* @throws GuzzleException|JsonException
*/
public function trainCarriages(array $params): string
{
Expand All @@ -99,11 +102,14 @@ public function trainCarriages(array $params): string
$carriages = $this->query->get($this->path, $layer + $params);

return json_encode([
'cars' => $carriages->lst[0]->cars ?? null,
'functionBlocks' => $carriages->lst[0]->functionBlocks ?? null,
'schemes' => $carriages->schemes ?? null,
'companies' => $carriages->insuranceCompany ?? null,
], JSON_UNESCAPED_UNICODE);
'cars' => $carriages->lst[0]->cars ?? null,
'functionBlocks' => $carriages->lst[0]->functionBlocks ?? null,
'schemes' => $carriages->schemes ?? null,
'companies' => $carriages->insuranceCompany ?? null,
],
JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE
);

}

/**
Expand All @@ -112,7 +118,7 @@ public function trainCarriages(array $params): string
* @param array $params Массив параметров
*
* @return string
* @throws GuzzleException
* @throws GuzzleException|JsonException
*/
public function trainStationList(array $params): string
{
Expand All @@ -122,9 +128,11 @@ public function trainStationList(array $params): string
$stations = $this->query->get($this->stationListPath, $layer + $params);

return json_encode([
'train' => $stations->data->trainInfo,
'routes' => $stations->data->routes,
], JSON_UNESCAPED_UNICODE);
'train' => $stations->data->trainInfo,
'routes' => $stations->data->routes,
],
JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE
);
}

/**
Expand All @@ -133,7 +141,7 @@ public function trainStationList(array $params): string
* @param array $params Массив параметров
*
* @return string
* @throws GuzzleException
* @throws GuzzleException|JsonException
*/
public function stationCode(array $params): string
{
Expand All @@ -155,6 +163,6 @@ public function stationCode(array $params): string
}
}

return json_encode($stations, JSON_UNESCAPED_UNICODE);
return json_encode($stations, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE);
}
}
6 changes: 3 additions & 3 deletions src/Rzd/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

class Config
{
private bool $debug = false;
private string $language = 'ru';
private float $timeout = 5.0;
private bool $debug = false;
private string $language = 'ru';
private float $timeout = 5.0;
private ?string $proxy = null;
private ?string $userAgent = null;
private ?string $referer = null;
Expand Down
2 changes: 1 addition & 1 deletion src/Rzd/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ protected function run(string $path, array $params, string $method): mixed
$response = $this->client->request($method, $path, $data + $options);

$content = $response->getBody()->getContents();
$content = json_decode($content);
$content = json_decode($content, false, 512, JSON_THROW_ON_ERROR);

$result = $content->result ?? 'OK';

Expand Down

0 comments on commit cdda308

Please sign in to comment.