Skip to content

Commit

Permalink
Fixes interface and for PHPCQ
Browse files Browse the repository at this point in the history
  • Loading branch information
zonky2 committed Mar 13, 2024
1 parent ed16ed8 commit e69de3f
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 25 deletions.
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"phpcq/runner-bootstrap": "^1.0@dev"
},
"conflict": {
"contao-community-alliance/dependency-container": "<2.1,>=3.0"
"contao-community-alliance/dependency-container": "<2.1 >=3.0"
},
"autoload": {
"psr-4": {
Expand All @@ -60,7 +60,8 @@
"config": {
"allow-plugins": {
"contao-components/installer": false,
"contao/manager-plugin": false
"contao/manager-plugin": false,
"php-http/discovery": true
}
},
"extra": {
Expand Down
13 changes: 5 additions & 8 deletions src/AbstractTranslator.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/**
* This file is part of contao-community-alliance/translator.
*
* (c) 2013-2018 Contao Community Alliance.
* (c) 2013-2024 Contao Community Alliance.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
Expand All @@ -14,7 +14,8 @@
* @author Christian Schiffler <[email protected]>
* @author Tristan Lins <[email protected]>
* @author Sven Baumann <[email protected]>
* @copyright 2013-2018 Contao Community Alliance.
* @author Ingolf Steinhardt <[email protected]>
* @copyright 2013-2024 Contao Community Alliance.
* @license https://github.com/contao-community-alliance/translator/blob/master/LICENSE LGPL-3.0
* @filesource
*/
Expand Down Expand Up @@ -124,16 +125,12 @@ protected function buildChoiceLookupList($choices)

foreach ($choices as $range => $choice) {
/** @psalm-suppress RedundantCastGivenDocblockType - There is no way to enforce string array key :/ */
$range = explode(':', (string) $range);

if (count($range) < 2) {
$range[] = '';
}
$range = array_merge(explode(':', (string) $range), ['0']);

$array[] = (object) [
'range' => (object) [
'from' => (int) $range[0],
'to' => (int) $range[1],
'to' => (int) $range[1],
],
'string' => $choice
];
Expand Down
9 changes: 5 additions & 4 deletions src/StaticTranslator.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ protected static function sortPluralizedCompare($a, $b)
/** @psalm-suppress RedundantCastGivenDocblockType - There is no way to enforce string array key :/ */
$rangeB = explode(':', (string) $b);

$rangeA0 = !empty($rangeA[0] ?? null);
$rangeB0 = !empty($rangeB[0] ?? null);
$rangeA0 = '' !== ($rangeA[0]);
$rangeB0 = '' !== ($rangeB[0]);
// Both range starts provided.
if ($rangeA0 && $rangeB0) {
return strcmp($rangeA[0], $rangeB[0]);
Expand All @@ -85,10 +85,11 @@ protected static function sortPluralizedCompare($a, $b)
return 1;
}

$rangeA1 = !empty($rangeA[1] ?? null);
$rangeB1 = !empty($rangeB[1] ?? null);
$rangeA1 = '' !== ($rangeA[1] ?? '');
$rangeB1 = '' !== ($rangeB[1] ?? '');
// Both are an open start range.
if ($rangeA1 && $rangeB1) {
/** @psalm-suppress PossiblyUndefinedArrayOffset - the booleans already ensure we have the keys present. */
return strcmp($rangeA[1], $rangeB[1]);
}

Expand Down
25 changes: 14 additions & 11 deletions src/TranslatorInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/**
* This file is part of contao-community-alliance/translator.
*
* (c) 2013-2018 Contao Community Alliance.
* (c) 2013-2024 Contao Community Alliance.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
Expand All @@ -14,7 +14,8 @@
* @author Christian Schiffler <[email protected]>
* @author Tristan Lins <[email protected]>
* @author Sven Baumann <[email protected]>
* @copyright 2013-2018 Contao Community Alliance.
* @author Ingolf Steinhardt <[email protected]>
* @copyright 2013-2024 Contao Community Alliance.
* @license https://github.com/contao-community-alliance/translator/blob/master/LICENSE LGPL-3.0
* @filesource
*/
Expand All @@ -25,16 +26,18 @@

/**
* This interface describes a translator.
*
* @psalm-type TParameterArray=array<string, string>|list<float|int|string>
*/
interface TranslatorInterface
{
/**
* Translate a string in a specific domain.
*
* @param string $string The translation string.
* @param string|null $domain The translation domain.
* @param array $parameters Parameters used in translation.
* @param string|null $locale The translation locale.
* @param string $string The translation string.
* @param string|null $domain The translation domain.
* @param TParameterArray $parameters Parameters used in translation.
* @param string|null $locale The translation locale.
*
* @return string
*/
Expand All @@ -43,11 +46,11 @@ public function translate($string, $domain = null, array $parameters = [], $loca
/**
* Translate a pluralized string in a specific domain.
*
* @param string $string The translation string.
* @param int $number The pluralization number.
* @param string|null $domain The translation domain.
* @param array $parameters Parameters used in translation.
* @param string|null $locale The translation locale.
* @param string $string The translation string.
* @param int $number The pluralization number.
* @param string|null $domain The translation domain.
* @param TParameterArray $parameters Parameters used in translation.
* @param string|null $locale The translation locale.
*
* @return string
*/
Expand Down

0 comments on commit e69de3f

Please sign in to comment.