From 19219ce13d4a21f86f3659a9c3634ffa85b3bc3c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Richard=20Dobro=C5=88?= Date: Sat, 9 Apr 2022 09:56:37 +0200 Subject: [PATCH] Release 4.0 --- .github/workflows/run-tests.yml | 2 +- .php-cs-fixer.dist.php | 2 +- CHANGELOG.md | 4 +-- README.md | 10 ++++--- composer.json | 7 +++-- src/fbt/Lib/IntlNumberType.php | 4 +-- src/fbt/Lib/NumberFormatConsts.php | 8 ++--- src/fbt/Runtime/FbtRuntimeTypes.php | 4 +-- src/fbt/Runtime/FbtTable.php | 2 +- src/fbt/Runtime/FbtTranslations.php | 2 +- src/fbt/Runtime/Gender.php | 4 +-- src/fbt/Runtime/Shared/IntlPunctuation.php | 4 +-- .../Shared/IntlVariationResolverImpl.php | 2 +- .../Transform/FbtTransform/FbtAutoWrap.php | 2 +- .../Transform/FbtTransform/FbtConstants.php | 30 +++++++++---------- src/fbt/Transform/FbtTransform/FbtUtils.php | 4 +-- .../Transform/FbtTransform/JSFbtBuilder.php | 2 +- .../Processors/FbtFunctionCallProcessor.php | 2 +- .../FbtTransform/Translate/FBLocaleToLang.php | 2 +- .../Translate/Gender/IntlGenderType.php | 4 +-- .../FbtTransform/Translate/IntlVariations.php | 20 ++++++------- src/fbt/Transform/FbtTransform/fbtHash.php | 2 +- tests/TestCase.php | 4 +-- 23 files changed, 65 insertions(+), 62 deletions(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index d5adb74..6e246f5 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -6,7 +6,7 @@ jobs: strategy: fail-fast: false matrix: - php-version: ['7.0', '7.1', '7.2', '7.3', '7.4'] + php-version: ['7.2', '7.3', '7.4', '8.0', '8.1'] name: PHP ${{ matrix.php-version }} diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php index 7c35c8b..7ee4ffa 100644 --- a/.php-cs-fixer.dist.php +++ b/.php-cs-fixer.dist.php @@ -11,7 +11,7 @@ return (new PhpCsFixer\Config()) ->setRules([ - '@PSR2' => true, + '@PSR12' => true, 'array_syntax' => ['syntax' => 'short'], 'ordered_imports' => ['sort_algorithm' => 'alpha'], 'no_unused_imports' => true, diff --git a/CHANGELOG.md b/CHANGELOG.md index 6c9f609..ac3d080 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ All notable changes to `fbt` will be documented in this file. Updates should follow the [Keep a CHANGELOG](http://keepachangelog.com/) principles. -## v3.0 - 2022-02-18 +## v4.0 - 2022-04-09 ### Added -- PHP Internationalization Framework for PHP 7. +- Support PHP >= 7.2. diff --git a/README.md b/README.md index 1903313..23cebd8 100644 --- a/README.md +++ b/README.md @@ -25,9 +25,10 @@ $ composer require richarddobron/fbt ## Version Guidance -| Version | Released | Status | Repo | PHP Version | -|---------|------------|--------|------------------|-------------| -| 3.x | 2022-02-18 | Latest | [v3][fbt-3-repo] | >= 7.0 | +| Version | Released | Status | Repo | PHP Version | +|---------|------------|------------|------------------|-------------| +| 3.x | 2022-02-18 | Maintained | [v3][fbt-3-repo] | >= 7.0 | +| 4.x | 2022-04-09 | Latest | [v4][fbt-4-repo] | >= 7.2 | ## Official integrations @@ -55,6 +56,7 @@ https://github.com/richardDobron/fbt/tree/main/docs ## License FBT is MIT licensed, as found in the [LICENSE](LICENSE) file. -[fbt-3-repo]: https://github.com/richarddobron/fbt +[fbt-3-repo]: https://github.com/richarddobron/fbt/tree/3.x +[fbt-4-repo]: https://github.com/richarddobron/fbt [link-facebook-fbt]: https://github.com/facebook/fbt [simplehtmldom]: https://sourceforge.net/projects/simplehtmldom/files/simplehtmldom/1.9.1/ diff --git a/composer.json b/composer.json index c27c5b7..788a0e6 100644 --- a/composer.json +++ b/composer.json @@ -3,14 +3,14 @@ "description": "A PHP Internationalization Framework for PHP.", "keywords": ["php", "i18n", "framework", "internationalization", "translations"], "require": { - "php": "^7.0", + "php": "^7.2 || ^8.0", "ext-json": "*", "ext-dom": "*", "ext-iconv": "*", "minicli/minicli": "1.0.4" }, "require-dev": { - "phpunit/phpunit": "^6.0" + "phpunit/phpunit": "^8.5.5 || ^9.3.5" }, "license": "MIT", "type": "library", @@ -45,5 +45,6 @@ }, "bin": [ "bin/fbt" - ] + ], + "minimum-stability": "dev" } diff --git a/src/fbt/Lib/IntlNumberType.php b/src/fbt/Lib/IntlNumberType.php index b56155b..c90ba0d 100644 --- a/src/fbt/Lib/IntlNumberType.php +++ b/src/fbt/Lib/IntlNumberType.php @@ -7,11 +7,11 @@ class IntlNumberType { - const LOCALE_TO_NUMBER_TYPE = [ + public const LOCALE_TO_NUMBER_TYPE = [ "pt_PT" => \fbt\Transform\FbtTransform\Translate\CLDR\IntlCLDRNumberType05::class, ]; - const LANG_TO_NUMBER_TYPE = [ + public const LANG_TO_NUMBER_TYPE = [ "bm" => \fbt\Transform\FbtTransform\Translate\CLDR\IntlCLDRNumberType01::class, "bo" => \fbt\Transform\FbtTransform\Translate\CLDR\IntlCLDRNumberType01::class, "dz" => \fbt\Transform\FbtTransform\Translate\CLDR\IntlCLDRNumberType01::class, diff --git a/src/fbt/Lib/NumberFormatConsts.php b/src/fbt/Lib/NumberFormatConsts.php index bb49fed..5659855 100644 --- a/src/fbt/Lib/NumberFormatConsts.php +++ b/src/fbt/Lib/NumberFormatConsts.php @@ -4,9 +4,9 @@ class NumberFormatConsts { - const DEFAULT_LOCALE = 'en_US'; + public const DEFAULT_LOCALE = 'en_US'; - const DEFAULT_CONFIG = [ + public const DEFAULT_CONFIG = [ "decimalSeparator" => '.', "numberDelimiter" => ',', "minDigitsForThousandsSeparator" => 0, @@ -17,7 +17,7 @@ class NumberFormatConsts "numberingSystemData" => null, ]; - const CONFIGS = [ + public const CONFIGS = [ [ "decimalSeparator" => '.', "numberDelimiter" => ',', @@ -174,7 +174,7 @@ class NumberFormatConsts ], ]; - const LOCALE_TO_INDEX = [ + public const LOCALE_TO_INDEX = [ "en_US" => 0, "ca_ES" => 1, "cs_CZ" => 2, diff --git a/src/fbt/Runtime/FbtRuntimeTypes.php b/src/fbt/Runtime/FbtRuntimeTypes.php index 38984fb..46d9d84 100644 --- a/src/fbt/Runtime/FbtRuntimeTypes.php +++ b/src/fbt/Runtime/FbtRuntimeTypes.php @@ -4,12 +4,12 @@ class FbtRuntimeTypes { - const PARAM_VARIATION_TYPE = [ + public const PARAM_VARIATION_TYPE = [ 'number' => 0, 'gender' => 1, ]; - const VALID_PRONOUN_USAGES_TYPE = [ + public const VALID_PRONOUN_USAGES_TYPE = [ 'object' => 0, 'possessive' => 1, 'reflexive' => 2, diff --git a/src/fbt/Runtime/FbtTable.php b/src/fbt/Runtime/FbtTable.php index 2e5f5d3..1495356 100644 --- a/src/fbt/Runtime/FbtTable.php +++ b/src/fbt/Runtime/FbtTable.php @@ -8,7 +8,7 @@ class FbtTable * fbt::XXX calls return arguments in the form of * [, ] to be processed by fbt::_ */ - const ARG = [ + public const ARG = [ "INDEX" => 0, "SUBSTITUTION" => 1, ]; diff --git a/src/fbt/Runtime/FbtTranslations.php b/src/fbt/Runtime/FbtTranslations.php index 2c7f65d..c44ae96 100644 --- a/src/fbt/Runtime/FbtTranslations.php +++ b/src/fbt/Runtime/FbtTranslations.php @@ -7,7 +7,7 @@ class FbtTranslations { - const DEFAULT_SRC_LOCALE = 'en_US'; + public const DEFAULT_SRC_LOCALE = 'en_US'; /** @var array */ public static $translatedFbts = []; diff --git a/src/fbt/Runtime/Gender.php b/src/fbt/Runtime/Gender.php index 4fc6b19..23aeee5 100644 --- a/src/fbt/Runtime/Gender.php +++ b/src/fbt/Runtime/Gender.php @@ -4,7 +4,7 @@ class Gender { - const GENDER_CONST = [ + public const GENDER_CONST = [ 'NOT_A_PERSON' => 0, 'FEMALE_SINGULAR' => 1, 'MALE_SINGULAR' => 2, @@ -20,7 +20,7 @@ class Gender 'UNKNOWN_PLURAL' => 11, ]; - const DATA = [ + public const DATA = [ self::GENDER_CONST['NOT_A_PERSON'] => [ "is_male" => false, "is_female" => false, diff --git a/src/fbt/Runtime/Shared/IntlPunctuation.php b/src/fbt/Runtime/Shared/IntlPunctuation.php index 1ef8538..74dd7f4 100644 --- a/src/fbt/Runtime/Shared/IntlPunctuation.php +++ b/src/fbt/Runtime/Shared/IntlPunctuation.php @@ -8,7 +8,7 @@ class IntlPunctuation * Regular expression snippet containing all the characters that we * count as sentence-final punctuation. */ - const PUNCT_CHAR_CLASS = '[.!?' . + public const PUNCT_CHAR_CLASS = '[.!?' . "\u{3002}" . // Chinese/Japanese period "\u{FF01}" . // Fullwidth exclamation point "\u{FF1F}" . // Fullwidth question mark @@ -20,7 +20,7 @@ class IntlPunctuation "\u{FF0E}" . // Fullwidth full stop ']'; - const ENDS_IN_PUNCT_REGEXP = '/' . + public const ENDS_IN_PUNCT_REGEXP = '/' . self::PUNCT_CHAR_CLASS . "[)\"'" . // JavaScript doesn't support Unicode character diff --git a/src/fbt/Runtime/Shared/IntlVariationResolverImpl.php b/src/fbt/Runtime/Shared/IntlVariationResolverImpl.php index ed9ad39..1d81e5a 100644 --- a/src/fbt/Runtime/Shared/IntlVariationResolverImpl.php +++ b/src/fbt/Runtime/Shared/IntlVariationResolverImpl.php @@ -8,7 +8,7 @@ class IntlVariationResolverImpl { - const EXACTLY_ONE = '_1'; + public const EXACTLY_ONE = '_1'; /** * Wrapper around FbtNumberType::getVariation that special cases our EXACTLY_ONE diff --git a/src/fbt/Transform/FbtTransform/FbtAutoWrap.php b/src/fbt/Transform/FbtTransform/FbtAutoWrap.php index 3bcec30..9b90eaa 100644 --- a/src/fbt/Transform/FbtTransform/FbtAutoWrap.php +++ b/src/fbt/Transform/FbtTransform/FbtAutoWrap.php @@ -6,7 +6,7 @@ class FbtAutoWrap { - const FBT_PARAM_TYPE = [ + public const FBT_PARAM_TYPE = [ 'IMPLICIT' => 'implicit', 'EXPLICIT' => 'explicit', 'NULL' => 'null', diff --git a/src/fbt/Transform/FbtTransform/FbtConstants.php b/src/fbt/Transform/FbtTransform/FbtConstants.php index 41396b5..4d1c97c 100644 --- a/src/fbt/Transform/FbtTransform/FbtConstants.php +++ b/src/fbt/Transform/FbtTransform/FbtConstants.php @@ -12,31 +12,31 @@ class FbtConstants { - const VALID_PRONOUN_USAGES = [ + public const VALID_PRONOUN_USAGES = [ "object" => 0, "possessive" => 1, "reflexive" => 2, "subject" => 3, ]; - const PRONOUN_USAGE = [ + public const PRONOUN_USAGE = [ "OBJECT" => 0, "POSSESSIVE" => 1, "REFLEXIVE" => 2, "SUBJECT" => 3, ]; - const PLURAL_REQUIRED_ATTRIBUTES = [ + public const PLURAL_REQUIRED_ATTRIBUTES = [ 'count' => true, ]; - const SHOW_COUNT = [ + public const SHOW_COUNT = [ 'yes' => true, 'no' => true, 'ifMany' => true, ]; - const PLURAL_OPTIONS = [ + public const PLURAL_OPTIONS = [ 'value' => true, // optional value to replace token (rather than count) 'showCount' => self::SHOW_COUNT, 'name' => true, // token @@ -52,7 +52,7 @@ public static function validPluralOptions(): array ); } - const VALID_PRONOUN_OPTIONS = [ // js~php diff + public const VALID_PRONOUN_OPTIONS = [ // js~php diff 'human' => ['true' => true, 'false' => true], 'capitalize' => ['true' => true, 'false' => true], ]; @@ -60,7 +60,7 @@ public static function validPluralOptions(): array /** * Valid options allowed in the fbt(...) calls. */ - const VALID_FBT_OPTIONS = [ + public const VALID_FBT_OPTIONS = [ 'project' => true, 'author' => true, 'preserveWhitespace' => true, @@ -70,25 +70,25 @@ public static function validPluralOptions(): array 'reporting' => true, // fbt diff ]; - const FBT_BOOLEAN_OPTIONS = [ + public const FBT_BOOLEAN_OPTIONS = [ 'preserveWhitespace' => true, 'doNotExtract' => true, ]; - const FBT_CALL_MUST_HAVE_AT_LEAST_ONE_OF_THESE_ATTRIBUTES = ['desc', 'common']; + public const FBT_CALL_MUST_HAVE_AT_LEAST_ONE_OF_THESE_ATTRIBUTES = ['desc', 'common']; - const FBT_REQUIRED_ATTRIBUTES = [ + public const FBT_REQUIRED_ATTRIBUTES = [ 'desc' => true, ]; - const PRONOUN_REQUIRED_ATTRIBUTES = [ + public const PRONOUN_REQUIRED_ATTRIBUTES = [ 'type' => true, 'gender' => true, ]; - const PLURAL_PARAM_TOKEN = 'number'; + public const PLURAL_PARAM_TOKEN = 'number'; - const REQUIRED_PARAM_OPTIONS = [ + public const REQUIRED_PARAM_OPTIONS = [ 'name' => true, ]; @@ -103,12 +103,12 @@ public static function validParamOptions(): array ); } - const FBT_TYPE = [ + public const FBT_TYPE = [ 'TABLE' => 'table', 'TEXT' => 'text', ]; - const MODULE_NAME = [ + public const MODULE_NAME = [ 'FBT' => 'fbt', // 'REACT_FBT' => 'Fbt', 'FBS' => 'fbs', diff --git a/src/fbt/Transform/FbtTransform/FbtUtils.php b/src/fbt/Transform/FbtTransform/FbtUtils.php index 6755385..d42a376 100644 --- a/src/fbt/Transform/FbtTransform/FbtUtils.php +++ b/src/fbt/Transform/FbtTransform/FbtUtils.php @@ -10,7 +10,7 @@ class FbtUtils { - const FBT_CORE_ATTRIBUTES = [ // js~php diff + public const FBT_CORE_ATTRIBUTES = [ // js~php diff 'implicitDesc' => true, 'implicitFbt' => true, 'paramName' => true, @@ -69,7 +69,7 @@ public static function validateNamespacedFbtElement($moduleName, Node $node): st return $handlerName; } - const SHORT_BOOL_CANDIDATES = [ + public const SHORT_BOOL_CANDIDATES = [ 'common' => 'common', 'doNotExtract' => 'doNotExtract', 'number' => 'number', diff --git a/src/fbt/Transform/FbtTransform/JSFbtBuilder.php b/src/fbt/Transform/FbtTransform/JSFbtBuilder.php index eaeadcd..6248827 100644 --- a/src/fbt/Transform/FbtTransform/JSFbtBuilder.php +++ b/src/fbt/Transform/FbtTransform/JSFbtBuilder.php @@ -18,7 +18,7 @@ class JSFbtBuilder /** @var bool */ private $reactNativeMode; - const PLURAL_KEY_TO_TYPE = [ + public const PLURAL_KEY_TO_TYPE = [ '*' => 'many', IntlVariations::EXACTLY_ONE => 'singular', ]; diff --git a/src/fbt/Transform/FbtTransform/Processors/FbtFunctionCallProcessor.php b/src/fbt/Transform/FbtTransform/Processors/FbtFunctionCallProcessor.php index b237bdc..a677070 100644 --- a/src/fbt/Transform/FbtTransform/Processors/FbtFunctionCallProcessor.php +++ b/src/fbt/Transform/FbtTransform/Processors/FbtFunctionCallProcessor.php @@ -33,7 +33,7 @@ class FbtFunctionCallProcessor /* @var array */ protected $runtimeArgs = []; - const VARIATION = [ + public const VARIATION = [ 'number' => 0, 'gender' => 1, ]; diff --git a/src/fbt/Transform/FbtTransform/Translate/FBLocaleToLang.php b/src/fbt/Transform/FbtTransform/Translate/FBLocaleToLang.php index 5d04a42..9f28f51 100644 --- a/src/fbt/Transform/FbtTransform/Translate/FBLocaleToLang.php +++ b/src/fbt/Transform/FbtTransform/Translate/FBLocaleToLang.php @@ -4,7 +4,7 @@ class FBLocaleToLang { - const LOC_TO_LANG = [ + public const LOC_TO_LANG = [ "cx_PH" => "ceb", "ck_US" => "chr", "fb_AA" => "en", diff --git a/src/fbt/Transform/FbtTransform/Translate/Gender/IntlGenderType.php b/src/fbt/Transform/FbtTransform/Translate/Gender/IntlGenderType.php index c3b6e2e..d68bfc5 100644 --- a/src/fbt/Transform/FbtTransform/Translate/Gender/IntlGenderType.php +++ b/src/fbt/Transform/FbtTransform/Translate/Gender/IntlGenderType.php @@ -6,14 +6,14 @@ class IntlGenderType { - const MERGED_LOCALES = [ + public const MERGED_LOCALES = [ "ht_HT" => 1, "lv_LV" => 1, "ar_AR" => 1, "ks_IN" => 1, ]; - const MERGED_LANGS = [ + public const MERGED_LANGS = [ "ht" => 1, "lv" => 1, "ar" => 1, diff --git a/src/fbt/Transform/FbtTransform/Translate/IntlVariations.php b/src/fbt/Transform/FbtTransform/Translate/IntlVariations.php index dad817b..25a68ed 100644 --- a/src/fbt/Transform/FbtTransform/Translate/IntlVariations.php +++ b/src/fbt/Transform/FbtTransform/Translate/IntlVariations.php @@ -6,11 +6,11 @@ class IntlVariations { - const GENDER_MALE = 1; - const GENDER_FEMALE = 2; - const GENDER_UNKNOWN = 3; + public const GENDER_MALE = 1; + public const GENDER_FEMALE = 2; + public const GENDER_UNKNOWN = 3; - const INTL_NUMBER_VARIATIONS = [ + public const INTL_NUMBER_VARIATIONS = [ 'ZERO' => 0x10, // 0b10000 'ONE' => 0x4, // 0b00100 'TWO' => 0x8, // 0b01000 @@ -19,7 +19,7 @@ class IntlVariations 'OTHER' => 0x18, // 0b11000 ]; - const INTL_GENDER_VARIATIONS = [ + public const INTL_GENDER_VARIATIONS = [ 'MALE' => 1, 'FEMALE' => 2, 'UNKNOWN' => 3, @@ -27,12 +27,12 @@ class IntlVariations // Two bitmasks for representing gender/number variations. Give a bit // between number/gender in case CLDR ever exceeds 7 options - const INTL_VARIATION_MASK = [ + public const INTL_VARIATION_MASK = [ 'NUMBER' => 0x1c, // 0b11100 'GENDER' => 0x03, // 0b00011 ]; - const INTL_FBT_VARIATION_TYPE = [ + public const INTL_FBT_VARIATION_TYPE = [ 'GENDER' => 1, 'NUMBER' => 2, 'PRONOUN' => 3, @@ -55,10 +55,10 @@ public static function getType($n): int // This is not CLDR, but an fbt-specific marker that exists so that // singular phrases are not overwritten by multiplexed plural phrases // with a singular entry - const EXACTLY_ONE = '_1'; + public const EXACTLY_ONE = '_1'; - const SUBJECT = '__subject__'; - const VIEWING_USER = '__viewing_user__'; + public const SUBJECT = '__subject__'; + public const VIEWING_USER = '__viewing_user__'; public static function isValidValue($v): bool { diff --git a/src/fbt/Transform/FbtTransform/fbtHash.php b/src/fbt/Transform/FbtTransform/fbtHash.php index 8c4100e..8290fc8 100644 --- a/src/fbt/Transform/FbtTransform/fbtHash.php +++ b/src/fbt/Transform/FbtTransform/fbtHash.php @@ -7,7 +7,7 @@ class fbtHash { - const BASE_N_SYMBOLS = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; + public const BASE_N_SYMBOLS = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; // Compute the baseN string for a given unsigned integer. public static function uintToBaseN($numberArg, $base): string diff --git a/tests/TestCase.php b/tests/TestCase.php index 72b7703..a5a3f01 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -7,7 +7,7 @@ abstract class TestCase extends \PHPUnit\Framework\TestCase { - public function setUp() + public function setUp(): void { FbtConfig::set('author', 'richard'); FbtConfig::set('locale', 'sk_SK'); @@ -18,7 +18,7 @@ public function setUp() }); } - protected function tearDown() + protected function tearDown(): void { parent::tearDown();