Skip to content

Commit b99626f

Browse files
committed
Add phpdoc throws
1 parent 9e41bd0 commit b99626f

3 files changed

Lines changed: 29 additions & 20 deletions

File tree

lib/DetectLanguage/Client.php

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,12 @@ class Client
2828
/**
2929
* Perform a request
3030
*
31-
* @param string $method Method name
32-
* @param array $payload Request payload
31+
* @param string $method HTTP method name (GET, POST, etc.)
32+
* @param string $path API endpoint path
33+
* @param array|null $payload Request payload data
3334
*
34-
* @return object
35+
* @return array Response data
36+
* @throws \DetectLanguage\Error When API request fails, invalid response received, or authentication fails
3537
*/
3638
public static function request($method, $path, $payload = null)
3739
{
@@ -55,11 +57,6 @@ public static function request($method, $path, $payload = null)
5557
return $response;
5658
}
5759

58-
/**
59-
* Get request method name.
60-
*
61-
* @return string
62-
*/
6360
protected static function getEngineMethodName()
6461
{
6562
$request_engine = self::$requestEngine;
@@ -84,8 +81,9 @@ protected static function getEngineMethodName()
8481
/**
8582
* Perform request using native PHP streams
8683
*
84+
* @param string $method HTTP method name
8785
* @param string $url Request URL
88-
* @param string $body Request body
86+
* @param string|null $body Request body
8987
*
9088
* @return string Response body
9189
*/
@@ -112,10 +110,12 @@ protected static function requestStream($method, $url, $body)
112110
/**
113111
* Perform request using CURL extension.
114112
*
113+
* @param string $method HTTP method name
115114
* @param string $url Request URL
116-
* @param string $body Request body
115+
* @param string|null $body Request body
117116
*
118117
* @return string Response body
118+
* @throws \DetectLanguage\Error When CURL request fails, times out, or connection fails
119119
*/
120120
protected static function requestCurl($method, $url, $body)
121121
{
@@ -154,7 +154,7 @@ protected static function requestCurl($method, $url, $body)
154154
* Build URL for given method
155155
*
156156
* @param string $method Method name
157-
* @return string
157+
* @return string Complete API URL
158158
*/
159159
protected static function getUrl($method)
160160
{
@@ -164,7 +164,7 @@ protected static function getUrl($method)
164164
/**
165165
* Build request headers.
166166
*
167-
* @return array
167+
* @return array Array of HTTP headers
168168
*/
169169
protected static function getHeaders()
170170
{
@@ -179,7 +179,7 @@ protected static function getHeaders()
179179
/**
180180
* Get User-Agent for the request.
181181
*
182-
* @return string
182+
* @return string User-Agent string
183183
*/
184184
protected static function getUserAgent()
185185
{

lib/DetectLanguage/DetectLanguage.php

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ class DetectLanguage
4242
* Set API key
4343
*
4444
* @static
45-
* @param string $apiKey
45+
* @param string $apiKey The API key for authentication
46+
* @return void
4647
*/
4748
public static function setApiKey($apiKey)
4849
{
@@ -54,7 +55,8 @@ public static function setApiKey($apiKey)
5455
*
5556
* @static
5657
* @param string $text The text for language detection
57-
* @return array detected languages information
58+
* @return array Detected languages information
59+
* @throws \DetectLanguage\Error When API request fails, invalid response received, or authentication fails
5860
*/
5961
public static function detect($text)
6062
{
@@ -71,7 +73,8 @@ public static function detect($text)
7173
*
7274
* @static
7375
* @param string $text The text for language detection
74-
* @return string|null detected language code
76+
* @return string|null Detected language code
77+
* @throws \DetectLanguage\Error When API request fails, invalid response received, or authentication fails
7578
*/
7679
public static function detectCode($text)
7780
{
@@ -88,7 +91,8 @@ public static function detectCode($text)
8891
*
8992
* @static
9093
* @param array $texts The texts for language detection
91-
* @return array detected languages information
94+
* @return array Detected languages information
95+
* @throws \DetectLanguage\Error When API request fails, invalid response received, or authentication fails
9296
*/
9397
public static function detectBatch($texts)
9498
{
@@ -100,6 +104,7 @@ public static function detectBatch($texts)
100104
*
101105
* @static
102106
* @return array account status information
107+
* @throws \DetectLanguage\Error When API request fails, invalid response received, or authentication fails
103108
*/
104109
public static function getStatus()
105110
{
@@ -110,7 +115,8 @@ public static function getStatus()
110115
* Get supported languages.
111116
*
112117
* @static
113-
* @return array languages information
118+
* @return array Supported languages information
119+
* @throws \DetectLanguage\Error When API request fails, invalid response received, or authentication fails
114120
*/
115121
public static function getLanguages()
116122
{
@@ -122,7 +128,8 @@ public static function getLanguages()
122128
/**
123129
* @deprecated use self::detectCode instead
124130
* @param string $text The text for language detection
125-
* @return string|null detected language code
131+
* @return string|null Detected language code
132+
* @throws \DetectLanguage\Error When API request fails, invalid response received, or authentication fails
126133
*/
127134
public static function simpleDetect($text)
128135
{

lib/DetectLanguage/Error.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
namespace DetectLanguage;
44

5-
// backwards compatibility
5+
/**
6+
* @deprecated Use Error class instead
7+
*/
68
class DetectLanguageError extends \Exception
79
{
810
}

0 commit comments

Comments
 (0)