Skip to content

Commit 3efe417

Browse files
committed
Add deprecations
1 parent 6efec7a commit 3efe417

File tree

3 files changed

+30
-5
lines changed

3 files changed

+30
-5
lines changed

CHANGELOG.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1313

1414
### Changed
1515
- Switched to v3 API which uses updated language detection model
16-
- ⚠️ `simpleDetect` method renamed to `detectCode`
1716
- ⚠️ `detect` method result fields are `language` and `score`
18-
- ⚠️ `detect` method no longer accept arrays - use `detectBatch` instead
19-
- HTTPS is used by default. Removed secure mode configuration.
17+
- ⚠️ `simpleDetect` deprecated, use `detectCode` instead
18+
- ⚠️ `detect` for batch detection is deprecated, use `detectBatch` instead
19+
20+
### Removed
21+
- Secure mode configuration. HTTPS is always used.

lib/DetectLanguage/DetectLanguage.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ public static function setApiKey($apiKey)
5959
public static function detect($text)
6060
{
6161
if (is_array($text)) {
62-
throw new Error('detect method does not accept arrays, use detectBatch instead');
62+
trigger_error('detect method does not accept arrays, use detectBatch instead', E_USER_DEPRECATED);
63+
return self::detectBatch($text);
6364
}
6465

6566
return Client::request('POST', 'detect', array('q' => $text));
@@ -115,4 +116,17 @@ public static function getLanguages()
115116
{
116117
return Client::request('GET', 'languages');
117118
}
119+
120+
// DEPRECATED METHODS
121+
122+
/**
123+
* @deprecated use self::detectCode instead
124+
* @param string $text The text for language detection
125+
* @return string|null detected language code
126+
*/
127+
public static function simpleDetect($text)
128+
{
129+
trigger_error('simpleDetect method is deprecated, use detectCode instead', E_USER_DEPRECATED);
130+
return self::detectCode($text);
131+
}
118132
}

tests/DetectLanguage/DetectLanguageTest.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,10 @@ public function testDetect()
3838

3939
public function testDetectWithArray()
4040
{
41-
$this->expectException('\DetectLanguage\Error');
4241
$result = DetectLanguage::detect(array('Hello world'));
42+
43+
$this->assertEquals('en', $result[0][0]->language,
44+
'To detect English language.');
4345
}
4446

4547
public function testDetectCode()
@@ -50,6 +52,13 @@ public function testDetectCode()
5052
'To detect English language.');
5153
}
5254

55+
public function testSimpleDetect()
56+
{
57+
$result = DetectLanguage::simpleDetect('Hello world');
58+
$this->assertEquals('en', $result,
59+
'To detect English language.');
60+
}
61+
5362
public function testCurlRequest()
5463
{
5564
$this->setRequestEngine('curl');

0 commit comments

Comments
 (0)