Skip to content

Commit

Permalink
Exceptions annotations (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
actions-user committed Oct 19, 2022
1 parent 3071c1c commit 4dd695d
Show file tree
Hide file tree
Showing 4 changed files with 168 additions and 26 deletions.
77 changes: 62 additions & 15 deletions src/API/OpenApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,13 @@ public function __construct(
}

/**
* @throws Throwable
* @throws Exceptions\InvalidArgument
* @throws Exceptions\InvalidState
* @throws Exceptions\OpenApiCall
* @throws MetadataExceptions\InvalidData
* @throws MetadataExceptions\Logic
* @throws MetadataExceptions\MalformedInput
* @throws RuntimeException
*/
public function connect(): void
{
Expand Down Expand Up @@ -193,7 +199,10 @@ public function isConnected(): bool
}

/**
* @throws Throwable
* @throws Exceptions\InvalidArgument
* @throws Exceptions\OpenApiCall
* @throws MetadataExceptions\Logic
* @throws RuntimeException
*/
public function getUid(): string
{
Expand All @@ -209,7 +218,10 @@ public function getUid(): string
}

/**
* @throws Throwable
* @throws Exceptions\InvalidState
* @throws Exceptions\InvalidArgument
* @throws MetadataExceptions\Logic
* @throws RuntimeException
*/
public function getUserDevices(
string $userId,
Expand Down Expand Up @@ -268,7 +280,10 @@ public function getUserDevices(
/**
* @param Array<string> $deviceIds
*
* @throws Throwable
* @throws Exceptions\InvalidState
* @throws Exceptions\InvalidArgument
* @throws MetadataExceptions\Logic
* @throws RuntimeException
*/
public function getUserDevicesFactoryInfos(
array $deviceIds,
Expand Down Expand Up @@ -328,7 +343,10 @@ public function getUserDevicesFactoryInfos(
}

/**
* @throws Throwable
* @throws Exceptions\InvalidState
* @throws Exceptions\InvalidArgument
* @throws MetadataExceptions\Logic
* @throws RuntimeException
*/
public function getUserDeviceDetail(
string $deviceId,
Expand Down Expand Up @@ -396,7 +414,10 @@ public function getUserDeviceDetail(
}

/**
* @throws Throwable
* @throws Exceptions\InvalidState
* @throws Exceptions\InvalidArgument
* @throws MetadataExceptions\Logic
* @throws RuntimeException
*/
public function getUserDeviceSpecifications(
string $deviceId,
Expand Down Expand Up @@ -485,7 +506,10 @@ public function getUserDeviceSpecifications(
}

/**
* @throws Throwable
* @throws Exceptions\InvalidState
* @throws Exceptions\InvalidArgument
* @throws MetadataExceptions\Logic
* @throws RuntimeException
*/
public function getUserDeviceStatus(
string $deviceId,
Expand Down Expand Up @@ -544,7 +568,10 @@ public function getUserDeviceStatus(
/**
* @param Array<string, mixed> $params
*
* @throws Throwable
* @throws Exceptions\InvalidState
* @throws Exceptions\InvalidArgument
* @throws MetadataExceptions\Logic
* @throws RuntimeException
*/
public function getDevices(
array $params = [],
Expand Down Expand Up @@ -610,7 +637,10 @@ public function getDevices(
/**
* @param Array<string> $deviceIds
*
* @throws Throwable
* @throws Exceptions\InvalidState
* @throws Exceptions\InvalidArgument
* @throws MetadataExceptions\Logic
* @throws RuntimeException
*/
public function getDevicesFactoryInfos(
array $deviceIds,
Expand Down Expand Up @@ -670,7 +700,10 @@ public function getDevicesFactoryInfos(
}

/**
* @throws Throwable
* @throws Exceptions\InvalidState
* @throws Exceptions\InvalidArgument
* @throws MetadataExceptions\Logic
* @throws RuntimeException
*/
public function getDeviceInformation(
string $deviceId,
Expand Down Expand Up @@ -717,7 +750,10 @@ public function getDeviceInformation(
}

/**
* @throws Throwable
* @throws Exceptions\InvalidState
* @throws Exceptions\InvalidArgument
* @throws MetadataExceptions\Logic
* @throws RuntimeException
*/
public function getDeviceSpecification(
string $deviceId,
Expand Down Expand Up @@ -806,7 +842,10 @@ public function getDeviceSpecification(
}

/**
* @throws Throwable
* @throws Exceptions\InvalidState
* @throws Exceptions\InvalidArgument
* @throws MetadataExceptions\Logic
* @throws RuntimeException
*/
public function getDeviceStatus(
string $deviceId,
Expand Down Expand Up @@ -863,7 +902,10 @@ public function getDeviceStatus(
}

/**
* @throws Throwable
* @throws Exceptions\InvalidState
* @throws Exceptions\InvalidArgument
* @throws MetadataExceptions\Logic
* @throws RuntimeException
*/
public function setDeviceStatus(
string $deviceId,
Expand Down Expand Up @@ -924,7 +966,9 @@ public function setDeviceStatus(
/**
* @param Array<string, mixed> $params
*
* @throws Throwable
* @throws Exceptions\InvalidArgument
* @throws MetadataExceptions\Logic
* @throws RuntimeException
*/
private function callRequest(
string $method,
Expand Down Expand Up @@ -1072,7 +1116,10 @@ function (Message\ResponseInterface $response) use ($deferred, $method, $path, $
}

/**
* @throws Throwable
* @throws Exceptions\InvalidArgument
* @throws Exceptions\OpenApiCall
* @throws MetadataExceptions\Logic
* @throws RuntimeException
*/
private function checkResponse(string $path, Message\ResponseInterface $response): Message\ResponseInterface
{
Expand Down
40 changes: 36 additions & 4 deletions src/Clients/Cloud.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
namespace FastyBird\Connector\Tuya\Clients;

use DateTimeInterface;
use Exception;
use FastyBird\Connector\Tuya;
use FastyBird\Connector\Tuya\API;
use FastyBird\Connector\Tuya\Consumers;
Expand All @@ -39,6 +40,7 @@
use Ratchet\RFC6455;
use React\EventLoop;
use React\Socket;
use RuntimeException;
use Throwable;
use function array_key_exists;
use function base64_decode;
Expand Down Expand Up @@ -324,7 +326,14 @@ public function disconnect(): void

/**
* @throws DevicesExceptions\Terminate
* @throws Throwable
* @throws DevicesExceptions\InvalidState
* @throws MetadataExceptions\FileNotFound
* @throws MetadataExceptions\InvalidArgument
* @throws MetadataExceptions\InvalidData
* @throws MetadataExceptions\InvalidState
* @throws MetadataExceptions\Logic
* @throws MetadataExceptions\MalformedInput
* @throws Exception
*/
private function handleCommunication(): void
{
Expand Down Expand Up @@ -364,7 +373,14 @@ private function handleCommunication(): void

/**
* @throws DevicesExceptions\Terminate
* @throws Throwable
* @throws DevicesExceptions\InvalidState
* @throws MetadataExceptions\FileNotFound
* @throws MetadataExceptions\InvalidArgument
* @throws MetadataExceptions\InvalidData
* @throws MetadataExceptions\InvalidState
* @throws MetadataExceptions\Logic
* @throws MetadataExceptions\MalformedInput
* @throws Exception
*/
private function processDevice(MetadataEntities\DevicesModule\Device $deviceItem): bool
{
Expand Down Expand Up @@ -392,7 +408,16 @@ private function processDevice(MetadataEntities\DevicesModule\Device $deviceItem
}

/**
* @throws Throwable
* @throws Exceptions\InvalidState
* @throws Exceptions\InvalidArgument
* @throws DevicesExceptions\InvalidState
* @throws MetadataExceptions\FileNotFound
* @throws MetadataExceptions\InvalidArgument
* @throws MetadataExceptions\InvalidData
* @throws MetadataExceptions\InvalidState
* @throws MetadataExceptions\Logic
* @throws MetadataExceptions\MalformedInput
* @throws RuntimeException
*/
private function readDeviceData(
string $cmd,
Expand Down Expand Up @@ -535,8 +560,15 @@ function () use ($cmd, $deviceItem): void {
}

/**
* @throws DevicesExceptions\InvalidState
* @throws DevicesExceptions\Terminate
* @throws Throwable
* @throws Exception
* @throws MetadataExceptions\FileNotFound
* @throws MetadataExceptions\InvalidArgument
* @throws MetadataExceptions\InvalidData
* @throws MetadataExceptions\InvalidState
* @throws MetadataExceptions\Logic
* @throws MetadataExceptions\MalformedInput
*/
private function writeChannelsProperty(MetadataEntities\DevicesModule\Device $deviceItem): bool
{
Expand Down
52 changes: 49 additions & 3 deletions src/Clients/Discovery.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,14 @@
use FastyBird\Connector\Tuya\Types;
use FastyBird\Library\Metadata;
use FastyBird\Library\Metadata\Entities as MetadataEntities;
use FastyBird\Library\Metadata\Exceptions as MetadataExceptions;
use FastyBird\Module\Devices\Exceptions as DevicesExceptions;
use Nette;
use Nette\Utils;
use Psr\Log;
use React\Datagram;
use React\EventLoop;
use RuntimeException;
use SplObjectStorage;
use Throwable;
use function array_filter;
Expand Down Expand Up @@ -107,7 +110,16 @@ public function __construct(
}

/**
* @throws Throwable
* @throws DevicesExceptions\InvalidState
* @throws Exceptions\InvalidState
* @throws Exceptions\InvalidArgument
* @throws MetadataExceptions\FileNotFound
* @throws MetadataExceptions\InvalidArgument
* @throws MetadataExceptions\InvalidData
* @throws MetadataExceptions\InvalidState
* @throws MetadataExceptions\Logic
* @throws MetadataExceptions\MalformedInput
* @throws RuntimeException
*/
public function discover(): void
{
Expand All @@ -134,7 +146,16 @@ public function disconnect(): void
}

/**
* @throws Throwable
* @throws DevicesExceptions\InvalidState
* @throws Exceptions\InvalidState
* @throws Exceptions\InvalidArgument
* @throws MetadataExceptions\FileNotFound
* @throws MetadataExceptions\InvalidArgument
* @throws MetadataExceptions\InvalidData
* @throws MetadataExceptions\InvalidState
* @throws MetadataExceptions\Logic
* @throws MetadataExceptions\MalformedInput
* @throws RuntimeException
*/
private function discoverLocalDevices(): void
{
Expand Down Expand Up @@ -220,6 +241,14 @@ private function discoverLocalDevices(): void
}

/**
* @throws DevicesExceptions\InvalidState
* @throws Exceptions\InvalidState
* @throws MetadataExceptions\FileNotFound
* @throws MetadataExceptions\InvalidArgument
* @throws MetadataExceptions\InvalidData
* @throws MetadataExceptions\InvalidState
* @throws MetadataExceptions\Logic
* @throws MetadataExceptions\MalformedInput
* @throws Throwable
*/
private function discoverCloudDevices(): void
Expand Down Expand Up @@ -376,7 +405,16 @@ private function handleDiscoveredLocalDevice(string $packet): void
*
* @return Array<Entities\Messages\DiscoveredLocalDevice>
*
* @throws Throwable
* @throws DevicesExceptions\InvalidState
* @throws Exceptions\InvalidState
* @throws Exceptions\InvalidArgument
* @throws MetadataExceptions\FileNotFound
* @throws MetadataExceptions\InvalidArgument
* @throws MetadataExceptions\InvalidData
* @throws MetadataExceptions\InvalidState
* @throws MetadataExceptions\Logic
* @throws MetadataExceptions\MalformedInput
* @throws RuntimeException
*/
private function handleFoundLocalDevices(array $devices): array
{
Expand Down Expand Up @@ -517,6 +555,14 @@ private function handleFoundLocalDevices(array $devices): array
*
* @return Array<Entities\Messages\DiscoveredCloudDevice>
*
* @throws DevicesExceptions\InvalidState
* @throws Exceptions\InvalidState
* @throws MetadataExceptions\FileNotFound
* @throws MetadataExceptions\InvalidArgument
* @throws MetadataExceptions\InvalidData
* @throws MetadataExceptions\InvalidState
* @throws MetadataExceptions\Logic
* @throws MetadataExceptions\MalformedInput
* @throws Throwable
*/
private function handleFoundCloudDevices(
Expand Down

0 comments on commit 4dd695d

Please sign in to comment.