Skip to content

Commit 9e253f2

Browse files
committed
Support PHP 7.4
2 parents 60253f3 + c892597 commit 9e253f2

File tree

6 files changed

+190
-218
lines changed

6 files changed

+190
-218
lines changed

.travis.yml

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
language: php
22
sudo: false
33
php:
4-
- 5.4
5-
- 5.5
6-
- 5.6
7-
- 7
8-
- 7.0
9-
- 7.1
4+
- 7.2
5+
- 7.3
6+
- 7.4
107
install:
118
- pear install pear/PHP_CodeSniffer
9+
- composer install
1210
- phpenv rehash
1311
script:
14-
- phpunit --coverage-text tests
12+
- composer validate
13+
- ./vendor/bin/phpunit --coverage-text tests
1514
- phpcs Text/

Text/LanguageDetect.php

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ public function __construct()
189189
*/
190190
protected function _get_data_loc($fname)
191191
{
192-
if ($fname{0} == '/' || $fname{0} == '.') {
192+
if ($fname[0] == '/' || $fname[0] == '.') {
193193
// if filename starts with a slash, assume it's an absolute pathname
194194
// and skip whatever is in $this->_data_dir
195195
return $fname;
@@ -247,12 +247,6 @@ protected function _readdb($fname)
247247
protected function _checkTrigram($trigram)
248248
{
249249
if (!is_array($trigram)) {
250-
if (ini_get('magic_quotes_runtime')) {
251-
throw new Text_LanguageDetect_Exception(
252-
'Error loading database. Try turning magic_quotes_runtime off.',
253-
Text_LanguageDetect_Exception::MAGIC_QUOTES
254-
);
255-
}
256250
throw new Text_LanguageDetect_Exception(
257251
'Language database is not an array.',
258252
Text_LanguageDetect_Exception::DB_NOT_ARRAY
@@ -1470,31 +1464,31 @@ protected function _utf8char2unicode($char)
14701464
case 1:
14711465
// normal ASCII-7 byte
14721466
// 0xxxxxxx --> 0xxxxxxx
1473-
return ord($char{0});
1467+
return ord($char[0]);
14741468

14751469
case 2:
14761470
// 2 byte unicode
14771471
// 110zzzzx 10xxxxxx --> 00000zzz zxxxxxxx
1478-
$z = (ord($char{0}) & 0x000001F) << 6;
1479-
$x = (ord($char{1}) & 0x0000003F);
1472+
$z = (ord($char[0]) & 0x000001F) << 6;
1473+
$x = (ord($char[1]) & 0x0000003F);
14801474
return ($z | $x);
14811475

14821476
case 3:
14831477
// 3 byte unicode
14841478
// 1110zzzz 10zxxxxx 10xxxxxx --> zzzzzxxx xxxxxxxx
1485-
$z = (ord($char{0}) & 0x0000000F) << 12;
1486-
$x1 = (ord($char{1}) & 0x0000003F) << 6;
1487-
$x2 = (ord($char{2}) & 0x0000003F);
1479+
$z = (ord($char[0]) & 0x0000000F) << 12;
1480+
$x1 = (ord($char[1]) & 0x0000003F) << 6;
1481+
$x2 = (ord($char[2]) & 0x0000003F);
14881482
return ($z | $x1 | $x2);
14891483

14901484
case 4:
14911485
// 4 byte unicode
14921486
// 11110zzz 10zzxxxx 10xxxxxx 10xxxxxx -->
14931487
// 000zzzzz xxxxxxxx xxxxxxxx
1494-
$z1 = (ord($char{0}) & 0x00000007) << 18;
1495-
$z2 = (ord($char{1}) & 0x0000003F) << 12;
1496-
$x1 = (ord($char{2}) & 0x0000003F) << 6;
1497-
$x2 = (ord($char{3}) & 0x0000003F);
1488+
$z1 = (ord($char[0]) & 0x00000007) << 18;
1489+
$z2 = (ord($char[1]) & 0x0000003F) << 12;
1490+
$x1 = (ord($char[2]) & 0x0000003F) << 6;
1491+
$x2 = (ord($char[3]) & 0x0000003F);
14981492
return ($z1 | $z2 | $x1 | $x2);
14991493
}
15001494
}
@@ -1514,7 +1508,7 @@ protected function _utf8char2unicode($char)
15141508
*/
15151509
protected static function _next_char($str, &$counter, $special_convert = false)
15161510
{
1517-
$char = $str{$counter++};
1511+
$char = $str[$counter++];
15181512
$ord = ord($char);
15191513

15201514
// for a description of the utf8 system see
@@ -1538,7 +1532,7 @@ protected static function _next_char($str, &$counter, $special_convert = false)
15381532

15391533
} elseif ($ord >> 5 == 6) { // two-byte char
15401534
// multi-byte chars
1541-
$nextchar = $str{$counter++}; // get next byte
1535+
$nextchar = $str[$counter++]; // get next byte
15421536

15431537
// lower-casing of non-ascii characters is still incomplete
15441538

@@ -1580,12 +1574,12 @@ protected static function _next_char($str, &$counter, $special_convert = false)
15801574
} elseif ($ord >> 4 == 14) { // three-byte char
15811575

15821576
// tag on next 2 bytes
1583-
return $char . $str{$counter++} . $str{$counter++};
1577+
return $char . $str[$counter++] . $str[$counter++];
15841578

15851579
} elseif ($ord >> 3 == 30) { // four-byte char
15861580

15871581
// tag on next 3 bytes
1588-
return $char . $str{$counter++} . $str{$counter++} . $str{$counter++};
1582+
return $char . $str[$counter++] . $str[$counter++] . $str[$counter++];
15891583

15901584
} else {
15911585
// error?

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,6 @@
2727
"ext-mbstring": "May require the mbstring PHP extension"
2828
},
2929
"require-dev": {
30-
"phpunit/phpunit": "*"
30+
"phpunit/phpunit": "8.*|9.*"
3131
}
3232
}

phpcs.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,7 @@
44
<!-- we keep the old php4-style variable names for now -->
55
<exclude name="PEAR.NamingConventions.ValidFunctionName.PublicUnderscore"/>
66
<exclude name="PEAR.NamingConventions.ValidVariableName.PublicUnderscore"/>
7+
<!-- we keep the method names for BC reasons -->
8+
<exclude name="PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps"/>
79
</rule>
810
</ruleset>

0 commit comments

Comments
 (0)