Skip to content

Commit 45ec383

Browse files
fix: update PHP SDK code style to fix remaining issues (#690)
Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: Max Prilutskiy <maks.prilutskiy@gmail.com>
1 parent 7496972 commit 45ec383

File tree

2 files changed

+128
-79
lines changed

2 files changed

+128
-79
lines changed

php/sdk/src/LingoDotDevEngine.php

Lines changed: 50 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
/**
33
* PHP SDK for Lingo.dev
44
*
5-
* @category Localization
6-
* @package Lingodotdev\Sdk
7-
* @author Lingo.dev Team <hi@lingo.dev>
8-
* @license MIT
9-
* @link https://lingo.dev
5+
* @category Localization
6+
* @package Lingodotdev\Sdk
7+
* @author Lingo.dev Team <hi@lingo.dev>
8+
* @license MIT https://opensource.org/licenses/MIT
9+
* @link https://lingo.dev
1010
*/
1111

1212
namespace Lingodotdev\Sdk;
@@ -20,11 +20,11 @@
2020
* A powerful localization engine that supports various content types including
2121
* plain text, objects, and chat sequences.
2222
*
23-
* @category Localization
24-
* @package Lingodotdev\Sdk
25-
* @author Lingo.dev Team <hi@lingo.dev>
26-
* @license MIT
27-
* @link https://lingo.dev
23+
* @category Localization
24+
* @package Lingodotdev\Sdk
25+
* @author Lingo.dev Team <hi@lingo.dev>
26+
* @license MIT https://opensource.org/licenses/MIT
27+
* @link https://lingo.dev
2828
*/
2929
class LingoDotDevEngine
3030
{
@@ -87,9 +87,9 @@ public function __construct(array $config = [])
8787
/**
8888
* Localize content using the Lingo.dev API
8989
*
90-
* @param array $payload The content to be localized
91-
* @param array $params Localization parameters including source/target locales and fast mode option
92-
* @param callable|null $progressCallback Optional callback function to report progress (0-100)
90+
* @param array $payload The content to be localized
91+
* @param array $params Localization parameters including source/target locales and fast mode option
92+
* @param callable|null $progressCallback Optional callback function to report progress (0-100)
9393
*
9494
* @return array Localized content
9595
* @internal
@@ -130,11 +130,11 @@ protected function localizeRaw(array $payload, array $params, callable $progress
130130
/**
131131
* Localize a single chunk of content
132132
*
133-
* @param string|null $sourceLocale Source locale
134-
* @param string $targetLocale Target locale
135-
* @param array $payload Payload containing the chunk to be localized
136-
* @param string $workflowId Workflow ID
137-
* @param bool $fast Whether to use fast mode
133+
* @param string|null $sourceLocale Source locale
134+
* @param string $targetLocale Target locale
135+
* @param array $payload Payload containing the chunk to be localized
136+
* @param string $workflowId Workflow ID
137+
* @param bool $fast Whether to use fast mode
138138
*
139139
* @return array Localized chunk
140140
*/
@@ -176,7 +176,7 @@ private function _localizeChunk(?string $sourceLocale, string $targetLocale, arr
176176
/**
177177
* Extract payload chunks based on the ideal chunk size
178178
*
179-
* @param array $payload The payload to be chunked
179+
* @param array $payload The payload to be chunked
180180
*
181181
* @return array An array of payload chunks
182182
*/
@@ -214,7 +214,7 @@ private function _extractPayloadChunks(array $payload): array
214214
/**
215215
* Count words in a record or array
216216
*
217-
* @param mixed $payload The payload to count words in
217+
* @param mixed $payload The payload to count words in
218218
*
219219
* @return int The total number of words
220220
*/
@@ -252,19 +252,13 @@ private function _createId(): string
252252
/**
253253
* Localize a typical PHP array or object
254254
*
255-
* @param array $obj The object to be localized (strings will be extracted and translated)
256-
* @param array $params Localization parameters:
257-
* - sourceLocale: The
258-
* source language code
259-
* (e.g., 'en') -
260-
* targetLocale: The target
261-
* language code (e.g.,
262-
* 'es') - fast: Optional
263-
* boolean to enable fast
264-
* mode (faster but
265-
* potentially lower
266-
* quality)
267-
* @param callable|null $progressCallback Optional callback function to report progress (0-100)
255+
* @param array $obj The object to be localized (strings will be extracted and translated)
256+
* @param array $params Localization parameters:
257+
* - sourceLocale: The source language code (e.g., 'en')
258+
* - targetLocale: The target language code (e.g., 'es')
259+
* - fast: Optional boolean to enable fast mode
260+
* @param callable|null $progressCallback Optional callback function to report progress (0-100)
261+
*
268262
* @return array A new object with the same structure but localized string values
269263
*/
270264
public function localizeObject(array $obj, array $params, callable $progressCallback = null): array
@@ -275,18 +269,13 @@ public function localizeObject(array $obj, array $params, callable $progressCall
275269
/**
276270
* Localize a single text string
277271
*
278-
* @param string $text The text string to be localized
279-
* @param array $params Localization parameters:
280-
* - sourceLocale: The
281-
* source language code
282-
* (e.g., 'en') -
283-
* targetLocale: The target
284-
* language code (e.g.,
285-
* 'es') - fast: Optional
286-
* boolean to enable fast
287-
* mode (faster for bigger
288-
* batches)
289-
* @param callable|null $progressCallback Optional callback function to report progress (0-100)
272+
* @param string $text The text string to be localized
273+
* @param array $params Localization parameters:
274+
* - sourceLocale: The source language code (e.g., 'en')
275+
* - targetLocale: The target language code (e.g., 'es')
276+
* - fast: Optional boolean to enable fast mode
277+
* @param callable|null $progressCallback Optional callback function to report progress (0-100)
278+
*
290279
* @return string The localized text string
291280
*/
292281
public function localizeText(string $text, array $params, callable $progressCallback = null): string
@@ -298,17 +287,12 @@ public function localizeText(string $text, array $params, callable $progressCall
298287
/**
299288
* Localize a text string to multiple target locales
300289
*
301-
* @param string $text The text string to be localized
302-
* @param array $params Localization parameters:
303-
* - sourceLocale: The
304-
* source language code
305-
* (e.g., 'en') -
306-
* targetLocales: An array
307-
* of target language codes
308-
* (e.g., ['es', 'fr']) -
309-
* fast: Optional boolean
310-
* to enable fast mode (for
311-
* bigger batches)
290+
* @param string $text The text string to be localized
291+
* @param array $params Localization parameters:
292+
* - sourceLocale: The source language code (e.g., 'en')
293+
* - targetLocales: An array of target language codes (e.g., ['es', 'fr'])
294+
* - fast: Optional boolean to enable fast mode
295+
*
312296
* @return array An array of localized text strings
313297
*/
314298
public function batchLocalizeText(string $text, array $params): array
@@ -338,19 +322,13 @@ public function batchLocalizeText(string $text, array $params): array
338322
/**
339323
* Localize a chat sequence while preserving speaker names
340324
*
341-
* @param array $chat Array of chat messages, each with 'name' and 'text' properties
342-
* @param array $params Localization parameters:
343-
* - sourceLocale: The
344-
* source language code
345-
* (e.g., 'en') -
346-
* targetLocale: The target
347-
* language code (e.g.,
348-
* 'es') - fast: Optional
349-
* boolean to enable fast
350-
* mode (faster but
351-
* potentially lower
352-
* quality)
353-
* @param callable|null $progressCallback Optional callback function to report progress (0-100)
325+
* @param array $chat Array of chat messages, each with 'name' and 'text' properties
326+
* @param array $params Localization parameters:
327+
* - sourceLocale: The source language code (e.g., 'en')
328+
* - targetLocale: The target language code (e.g., 'es')
329+
* - fast: Optional boolean to enable fast mode
330+
* @param callable|null $progressCallback Optional callback function to report progress (0-100)
331+
*
354332
* @return array Array of localized chat messages with preserved structure
355333
*/
356334
public function localizeChat(array $chat, array $params, callable $progressCallback = null): array
@@ -380,8 +358,9 @@ public function localizeChat(array $chat, array $params, callable $progressCallb
380358
/**
381359
* Detect the language of a given text
382360
*
383-
* @param string $text The text to analyze
384-
* @return string Promise resolving to a locale code (e.g., 'en', 'es', 'fr')
361+
* @param string $text The text to analyze
362+
*
363+
* @return string Locale code (e.g., 'en', 'es', 'fr')
385364
*/
386365
public function recognizeLocale(string $text): string
387366
{

php/sdk/tests/LingoDotDevEngineTest.php

Lines changed: 78 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
11
<?php
2+
/**
3+
* Tests for the LingoDotDevEngine class
4+
*
5+
* @category Tests
6+
* @package Lingodotdev\Sdk\Tests
7+
* @author Lingo.dev Team <hi@lingo.dev>
8+
* @license MIT https://opensource.org/licenses/MIT
9+
* @link https://lingo.dev
10+
*/
211

312
namespace Lingodotdev\Sdk\Tests;
413

@@ -10,9 +19,25 @@
1019
use PHPUnit\Framework\TestCase;
1120
use ReflectionClass;
1221

22+
/**
23+
* Test cases for the LingoDotDevEngine class
24+
*
25+
* @category Tests
26+
* @package Lingodotdev\Sdk\Tests
27+
* @author Lingo.dev Team <hi@lingo.dev>
28+
* @license MIT https://opensource.org/licenses/MIT
29+
* @link https://lingo.dev
30+
*/
1331
class LingoDotDevEngineTest extends TestCase
1432
{
15-
private function createMockEngine($responses)
33+
/**
34+
* Creates a mock engine with predefined responses
35+
*
36+
* @param array $responses Array of mock responses
37+
*
38+
* @return LingoDotDevEngine Mocked engine instance
39+
*/
40+
private function _createMockEngine($responses)
1641
{
1742
$mock = new MockHandler($responses);
1843
$handlerStack = HandlerStack::create($mock);
@@ -28,21 +53,36 @@ private function createMockEngine($responses)
2853
return $engine;
2954
}
3055

56+
/**
57+
* Tests constructor with valid configuration
58+
*
59+
* @return void
60+
*/
3161
public function testConstructorWithValidConfig()
3262
{
3363
$engine = new LingoDotDevEngine(['apiKey' => 'test-api-key']);
3464
$this->assertInstanceOf(LingoDotDevEngine::class, $engine);
3565
}
3666

67+
/**
68+
* Tests constructor with invalid configuration
69+
*
70+
* @return void
71+
*/
3772
public function testConstructorWithInvalidConfig()
3873
{
3974
$this->expectException(\InvalidArgumentException::class);
4075
new LingoDotDevEngine([]);
4176
}
4277

78+
/**
79+
* Tests the localizeText method
80+
*
81+
* @return void
82+
*/
4383
public function testLocalizeText()
4484
{
45-
$engine = $this->createMockEngine(
85+
$engine = $this->_createMockEngine(
4686
[
4787
new Response(
4888
200, [], json_encode(
@@ -64,9 +104,14 @@ public function testLocalizeText()
64104
$this->assertEquals('Hola, mundo!', $result);
65105
}
66106

107+
/**
108+
* Tests the localizeObject method
109+
*
110+
* @return void
111+
*/
67112
public function testLocalizeObject()
68113
{
69-
$engine = $this->createMockEngine(
114+
$engine = $this->_createMockEngine(
70115
[
71116
new Response(
72117
200, [], json_encode(
@@ -99,9 +144,14 @@ public function testLocalizeObject()
99144
);
100145
}
101146

147+
/**
148+
* Tests the batchLocalizeText method
149+
*
150+
* @return void
151+
*/
102152
public function testBatchLocalizeText()
103153
{
104-
$engine = $this->createMockEngine(
154+
$engine = $this->_createMockEngine(
105155
[
106156
new Response(
107157
200, [], json_encode(
@@ -130,9 +180,14 @@ public function testBatchLocalizeText()
130180
$this->assertEquals(['Hola, mundo!', 'Bonjour, monde!'], $result);
131181
}
132182

183+
/**
184+
* Tests the localizeChat method
185+
*
186+
* @return void
187+
*/
133188
public function testLocalizeChat()
134189
{
135-
$engine = $this->createMockEngine(
190+
$engine = $this->_createMockEngine(
136191
[
137192
new Response(
138193
200, [], json_encode(
@@ -167,9 +222,14 @@ public function testLocalizeChat()
167222
$this->assertEquals($expected, $result);
168223
}
169224

225+
/**
226+
* Tests the recognizeLocale method
227+
*
228+
* @return void
229+
*/
170230
public function testRecognizeLocale()
171231
{
172-
$engine = $this->createMockEngine(
232+
$engine = $this->_createMockEngine(
173233
[
174234
new Response(
175235
200, [], json_encode(
@@ -185,9 +245,14 @@ public function testRecognizeLocale()
185245
$this->assertEquals('fr', $result);
186246
}
187247

248+
/**
249+
* Tests error handling in the SDK
250+
*
251+
* @return void
252+
*/
188253
public function testErrorHandling()
189254
{
190-
$engine = $this->createMockEngine(
255+
$engine = $this->_createMockEngine(
191256
[
192257
new Response(
193258
400, [], json_encode(
@@ -208,9 +273,14 @@ public function testErrorHandling()
208273
);
209274
}
210275

276+
/**
277+
* Tests the progress callback functionality
278+
*
279+
* @return void
280+
*/
211281
public function testProgressCallback()
212282
{
213-
$engine = $this->createMockEngine(
283+
$engine = $this->_createMockEngine(
214284
[
215285
new Response(
216286
200, [], json_encode(

0 commit comments

Comments
 (0)