From 84582807d22f4fd802b1df4da4ececb0b6209e2c Mon Sep 17 00:00:00 2001 From: Olivier Laviale Date: Sat, 17 Jul 2021 01:05:37 +0200 Subject: [PATCH] Localized inflections are now autoloaded --- README.md | 15 ++- lib/Inflections.php | 10 +- lib/Inflections/en.php | 139 ++++++++++++++------------ lib/Inflections/es.php | 65 ++++++------ lib/Inflections/fr.php | 49 +++++---- lib/Inflections/nb.php | 35 ++++--- lib/Inflections/pt.php | 169 +++++++++++++++++--------------- lib/Inflections/tr.php | 31 +++--- lib/InflectionsConfigurator.php | 11 +++ lib/Inflector.php | 13 +-- phpcs.xml | 10 +- 11 files changed, 307 insertions(+), 240 deletions(-) create mode 100644 lib/InflectionsConfigurator.php diff --git a/README.md b/README.md index 5921fa6..3f0b53b 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ A multilingual inflector that transforms words from singular to plural, underscore to camel case, and formats strings in various ways. Inflections are localized, the default english inflections for pluralization, singularization, and -uncountable words are kept in [lib/inflections/en.php](lib/Inflections/en.php). +uncountable words are kept in [lib/Inflections/en.php](lib/Inflections/en.php). Inflections are currently available for the following languages: @@ -28,7 +28,7 @@ composer require icanboogie/inflector -### Usage +## Usage These are some examples of the inflector with the `en` locale (default). @@ -135,8 +135,15 @@ echo pluralize('üçgen', 'tr'); // "üçgenler" ``` +## About inflections -### Acknowledgements +Inflections are localized, the configurators are kept in [lib/Inflections/en.php](lib/Inflections/en.php). Since v2.1, +these configurators are auto-loaded classes, which means, in theory, you could add your own or overwrite those already +defined by specifying another `ICanBoogie\\Inflections\\` in your `composer.json` file. + + + +## Acknowledgements Most of the code and documentation was adapted from [Ruby On Rails](http://rubyonrails.org/)'s [Inflector](http://api.rubyonrails.org/classes/ActiveSupport/Inflector.html) and @@ -155,7 +162,7 @@ Significant differences: -### Getting started +## Getting started **Inflector** expects to work in UTF-8, which is the default encoding character set starting PHP 5.6, for older versions please use `mb_internal_encoding()` as follows: diff --git a/lib/Inflections.php b/lib/Inflections.php index 153fc03..b725b16 100644 --- a/lib/Inflections.php +++ b/lib/Inflections.php @@ -42,14 +42,14 @@ public static function get(string $locale = INFLECTOR_DEFAULT_LOCALE): Inflectio return self::$inflections[$locale]; } - $instance = new self(); + $inflections = new self(); - /* @var $inflections callable */ + /* @var $configurator InflectionsConfigurator */ - $inflections = require __DIR__ . "/Inflections/{$locale}.php"; - $inflections($instance); + $configurator = __NAMESPACE__ . "\\Inflections\\$locale"; + $configurator::configure($inflections); - return self::$inflections[$locale] = $instance; + return self::$inflections[$locale] = $inflections; } /** diff --git a/lib/Inflections/en.php b/lib/Inflections/en.php index 255e84a..8683268 100644 --- a/lib/Inflections/en.php +++ b/lib/Inflections/en.php @@ -9,73 +9,82 @@ * file that was distributed with this source code. */ -namespace ICanBoogie; +namespace ICanBoogie\Inflections; + +use ICanBoogie\Inflections; +use ICanBoogie\InflectionsConfigurator; + +use function explode; /** * English Inflections. + * + * @codeCoverageIgnore */ -//@codeCoverageIgnoreStart -return function (Inflections $inflect): void { - $inflect - ->plural('/$/', 's') - ->plural('/s$/i', 's') - ->plural('/^(ax|test)is$/i', '\1es') - ->plural('/(alias|status)$/i', '\1es') - ->plural('/(bu)s$/i', '\1ses') - ->plural('/(buffal|tomat|potat|volcan|her)o$/i', '\1oes') - ->plural('/([ti])um$/i', '\1a') - ->plural('/([ti])a$/i', '\1a') - ->plural('/sis$/i', 'ses') - ->plural('/(?:([^f])fe|([lr])f)$/i', '\1\2ves') - ->plural('/(hive)$/i', '\1s') - ->plural('/([^aeiouy]|qu)y$/i', '\1ies') - ->plural('/(x|ch|ss|sh)$/i', '\1es') - ->plural('/(matr|vert|ind)(?:ix|ex)$/i', '\1ices') - ->plural('/^(m|l)ouse$/i', '\1ice') - ->plural('/^(m|l)ice$/i', '\1ice') - ->plural('/^(ox)$/i', '\1en') - ->plural('/^(oxen)$/i', '\1') - ->plural('/(quiz)$/i', '\1zes') - ->singular('/s$/i', '') - ->singular('/(ss)$/i', '\1') - ->singular('/(n)ews$/i', '\1ews') - ->singular('/([ti])a$/i', '\1um') - ->singular('/((a)naly|(b)a|(d)iagno|(p)arenthe|(p)rogno|(s)ynop|(t)he)(sis|ses)$/i', '\1sis') - ->singular('/(^analy)(sis|ses)$/i', '\1sis') - ->singular('/([^f])ves$/i', '\1fe') - ->singular('/(hive)s$/i', '\1') - ->singular('/(tive)s$/i', '\1') - ->singular('/([lr])ves$/i', '\1f') - ->singular('/([^aeiouy]|qu)ies$/i', '\1y') - ->singular('/(s)eries$/i', '\1eries') - ->singular('/(m)ovies$/i', '\1ovie') - ->singular('/(x|ch|ss|sh)es$/i', '\1') - ->singular('/^(m|l)ice$/i', '\1ouse') - ->singular('/(bus)(es)?$/i', '\1') - ->singular('/(o)es$/i', '\1') - ->singular('/(shoe)s$/i', '\1') - ->singular('/(cris|test)(is|es)$/i', '\1is') - ->singular('/^(a)x[ie]s$/i', '\1xis') - ->singular('/(alias|status)(es)?$/i', '\1') - ->singular('/^(ox)en/i', '\1') - ->singular('/(vert|ind)ices$/i', '\1ex') - ->singular('/(matr)ices$/i', '\1ix') - ->singular('/(quiz)zes$/i', '\1') - ->singular('/(database)s$/i', '\1') - ->irregular('leaf', 'leaves') - ->irregular('loaf', 'loaves') - ->irregular('octopus', 'octopuses') - ->irregular('virus', 'viruses') - ->irregular('person', 'people') - ->irregular('man', 'men') - ->irregular('child', 'children') - ->irregular('sex', 'sexes') - ->irregular('move', 'moves') - ->irregular('zombie', 'zombies') - ->irregular('goose', 'geese') - ->irregular('genus', 'genera') +final class en implements InflectionsConfigurator +{ + public static function configure(Inflections $inflections): void + { + $inflections + ->plural('/$/', 's') + ->plural('/s$/i', 's') + ->plural('/^(ax|test)is$/i', '\1es') + ->plural('/(alias|status)$/i', '\1es') + ->plural('/(bu)s$/i', '\1ses') + ->plural('/(buffal|tomat|potat|volcan|her)o$/i', '\1oes') + ->plural('/([ti])um$/i', '\1a') + ->plural('/([ti])a$/i', '\1a') + ->plural('/sis$/i', 'ses') + ->plural('/(?:([^f])fe|([lr])f)$/i', '\1\2ves') + ->plural('/(hive)$/i', '\1s') + ->plural('/([^aeiouy]|qu)y$/i', '\1ies') + ->plural('/(x|ch|ss|sh)$/i', '\1es') + ->plural('/(matr|vert|ind)(?:ix|ex)$/i', '\1ices') + ->plural('/^(m|l)ouse$/i', '\1ice') + ->plural('/^(m|l)ice$/i', '\1ice') + ->plural('/^(ox)$/i', '\1en') + ->plural('/^(oxen)$/i', '\1') + ->plural('/(quiz)$/i', '\1zes') + ->singular('/s$/i', '') + ->singular('/(ss)$/i', '\1') + ->singular('/(n)ews$/i', '\1ews') + ->singular('/([ti])a$/i', '\1um') + ->singular('/((a)naly|(b)a|(d)iagno|(p)arenthe|(p)rogno|(s)ynop|(t)he)(sis|ses)$/i', '\1sis') + ->singular('/(^analy)(sis|ses)$/i', '\1sis') + ->singular('/([^f])ves$/i', '\1fe') + ->singular('/(hive)s$/i', '\1') + ->singular('/(tive)s$/i', '\1') + ->singular('/([lr])ves$/i', '\1f') + ->singular('/([^aeiouy]|qu)ies$/i', '\1y') + ->singular('/(s)eries$/i', '\1eries') + ->singular('/(m)ovies$/i', '\1ovie') + ->singular('/(x|ch|ss|sh)es$/i', '\1') + ->singular('/^(m|l)ice$/i', '\1ouse') + ->singular('/(bus)(es)?$/i', '\1') + ->singular('/(o)es$/i', '\1') + ->singular('/(shoe)s$/i', '\1') + ->singular('/(cris|test)(is|es)$/i', '\1is') + ->singular('/^(a)x[ie]s$/i', '\1xis') + ->singular('/(alias|status)(es)?$/i', '\1') + ->singular('/^(ox)en/i', '\1') + ->singular('/(vert|ind)ices$/i', '\1ex') + ->singular('/(matr)ices$/i', '\1ix') + ->singular('/(quiz)zes$/i', '\1') + ->singular('/(database)s$/i', '\1') + ->irregular('leaf', 'leaves') + ->irregular('loaf', 'loaves') + ->irregular('octopus', 'octopuses') + ->irregular('virus', 'viruses') + ->irregular('person', 'people') + ->irregular('man', 'men') + ->irregular('child', 'children') + ->irregular('sex', 'sexes') + ->irregular('move', 'moves') + ->irregular('zombie', 'zombies') + ->irregular('goose', 'geese') + ->irregular('genus', 'genera') - // http://easenglish.net/Files/Grammar/uncountable%20words.pdf - ->uncountable(explode(' ', 'advice aircraft art baggage butter clothing coal cotton deer equipment experience feedback fish flour food furniture gas homework impatience information jeans knowledge leather love luggage management money moose music news oil patience police polish progress research rice salmon sand series sheep silk sms soap spam species staff sugar swine talent toothpaste traffic travel vinegar weather wood wool work')); -}; -//@codeCoverageIgnoreEnd + // http://easenglish.net/Files/Grammar/uncountable%20words.pdf + ->uncountable(explode(' ', 'advice aircraft art baggage butter clothing coal cotton deer equipment experience feedback fish flour food furniture gas homework impatience information jeans knowledge leather love luggage management money moose music news oil patience police polish progress research rice salmon sand series sheep silk sms soap spam species staff sugar swine talent toothpaste traffic travel vinegar weather wood wool work')); + } +} diff --git a/lib/Inflections/es.php b/lib/Inflections/es.php index 852f0ae..0178efd 100644 --- a/lib/Inflections/es.php +++ b/lib/Inflections/es.php @@ -9,39 +9,46 @@ * file that was distributed with this source code. */ -namespace ICanBoogie; +namespace ICanBoogie\Inflections; + +use ICanBoogie\Inflections; +use ICanBoogie\InflectionsConfigurator; /** * Spanish Inflections. * * @see http://www.studyspanish.com/lessons/plnoun.htm * @see http://spanish.about.com/cs/writing/a/writing_plurals.htm + * + * @codeCoverageIgnore */ -//@codeCoverageIgnoreStart -return function (Inflections $inflect): void { - $inflect - ->plural('/$/', 's') - ->plural('/([^aeéiou])$/i', '\1es') - ->plural('/([aeiou]s)$/i', '\1') - ->plural('/z$/i', 'ces') - ->plural('/á([sn])$/i', 'a\1es') - ->plural('/é([sn])$/i', 'e\1es') - ->plural('/í([sn])$/i', 'i\1es') - ->plural('/ó([sn])$/i', 'o\1es') - ->plural('/ú([sn])$/i', 'u\1es') - ->singular('/s$/', '') - ->singular('/es$/', '') - ->singular('/ces$/', 'z') - ->singular('/iones$/', 'ión') - ->singular('/ereses$/', 'erés') - ->irregular('el', 'los') - ->irregular('lunes', 'lunes') - ->irregular('rompecabezas', 'rompecabezas') - ->irregular('crisis', 'crisis') - ->irregular('papá', 'papás') - ->irregular('mamá', 'mamás') - ->irregular('sofá', 'sofás') - // because 'mes' is considered already a plural - ->irregular('mes', 'meses'); -}; -//@codeCoverageIgnoreEnd +final class es implements InflectionsConfigurator +{ + public static function configure(Inflections $inflections): void + { + $inflections + ->plural('/$/', 's') + ->plural('/([^aeéiou])$/i', '\1es') + ->plural('/([aeiou]s)$/i', '\1') + ->plural('/z$/i', 'ces') + ->plural('/á([sn])$/i', 'a\1es') + ->plural('/é([sn])$/i', 'e\1es') + ->plural('/í([sn])$/i', 'i\1es') + ->plural('/ó([sn])$/i', 'o\1es') + ->plural('/ú([sn])$/i', 'u\1es') + ->singular('/s$/', '') + ->singular('/es$/', '') + ->singular('/ces$/', 'z') + ->singular('/iones$/', 'ión') + ->singular('/ereses$/', 'erés') + ->irregular('el', 'los') + ->irregular('lunes', 'lunes') + ->irregular('rompecabezas', 'rompecabezas') + ->irregular('crisis', 'crisis') + ->irregular('papá', 'papás') + ->irregular('mamá', 'mamás') + ->irregular('sofá', 'sofás') + // because 'mes' is considered already a plural + ->irregular('mes', 'meses'); + } +} diff --git a/lib/Inflections/fr.php b/lib/Inflections/fr.php index 72c49ec..d03bbc7 100644 --- a/lib/Inflections/fr.php +++ b/lib/Inflections/fr.php @@ -9,30 +9,37 @@ * file that was distributed with this source code. */ -namespace ICanBoogie; +namespace ICanBoogie\Inflections; + +use ICanBoogie\Inflections; +use ICanBoogie\InflectionsConfigurator; /** * French Inflections. * * @see http://grammaire.reverso.net/5_5_01_pluriel_des_noms_et_des_adjectifs.shtml + * + * @codeCoverageIgnore */ -//@codeCoverageIgnoreStart -return function (Inflections $inflect): void { - $inflect - ->plural('/$/', 's') - ->singular('/s$/', '') - ->plural('/(bijou|caillou|chou|genou|hibou|joujou|pou|au|eu|eau)$/', '\1x') - ->singular('/(bijou|caillou|chou|genou|hibou|joujou|pou|au|eu|eau)x$/', '\1') - ->plural('/(bleu|émeu|landau|lieu|pneu|sarrau)$/', '\1s') - ->plural('/al$/', 'aux') - ->plural('/ail$/', 'ails') - ->singular('/(journ|chev)aux$/', '\1al') - ->singular('/ails$/', 'ail') - ->plural('/(b|cor|ém|gemm|soupir|trav|vant|vitr)ail$/', '\1aux') - ->singular('/(b|cor|ém|gemm|soupir|trav|vant|vitr)aux$/', '\1ail') - ->plural('/(s|x|z)$/', '\1') - ->irregular('monsieur', 'messieurs') - ->irregular('madame', 'mesdames') - ->irregular('mademoiselle', 'mesdemoiselles'); -}; -//@codeCoverageIgnoreEnd +final class fr implements InflectionsConfigurator +{ + public static function configure(Inflections $inflections): void + { + $inflections + ->plural('/$/', 's') + ->singular('/s$/', '') + ->plural('/(bijou|caillou|chou|genou|hibou|joujou|pou|au|eu|eau)$/', '\1x') + ->singular('/(bijou|caillou|chou|genou|hibou|joujou|pou|au|eu|eau)x$/', '\1') + ->plural('/(bleu|émeu|landau|lieu|pneu|sarrau)$/', '\1s') + ->plural('/al$/', 'aux') + ->plural('/ail$/', 'ails') + ->singular('/(journ|chev)aux$/', '\1al') + ->singular('/ails$/', 'ail') + ->plural('/(b|cor|ém|gemm|soupir|trav|vant|vitr)ail$/', '\1aux') + ->singular('/(b|cor|ém|gemm|soupir|trav|vant|vitr)aux$/', '\1ail') + ->plural('/(s|x|z)$/', '\1') + ->irregular('monsieur', 'messieurs') + ->irregular('madame', 'mesdames') + ->irregular('mademoiselle', 'mesdemoiselles'); + } +} diff --git a/lib/Inflections/nb.php b/lib/Inflections/nb.php index 318ec8f..3f27439 100644 --- a/lib/Inflections/nb.php +++ b/lib/Inflections/nb.php @@ -9,20 +9,29 @@ * file that was distributed with this source code. */ -namespace ICanBoogie; +namespace ICanBoogie\Inflections; + +use ICanBoogie\Inflections; +use ICanBoogie\InflectionsConfigurator; + +use function explode; /** * Norwegian Bokmal Inflections. + * + * @codeCoverageIgnore */ -//@codeCoverageIgnoreStart -return function (Inflections $inflect): void { - $inflect - ->plural('/$/', 'er') - ->plural('/r$/i', 're') - ->plural('/e$/i', 'er') - ->singular('/er$/i', '') - ->singular('/re$/i', 'r') - ->irregular('konto', 'konti') - ->uncountable(explode(' ', 'barn fjell hus')); -}; -//@codeCoverageIgnoreEnd +final class nb implements InflectionsConfigurator +{ + public static function configure(Inflections $inflections): void + { + $inflections + ->plural('/$/', 'er') + ->plural('/r$/i', 're') + ->plural('/e$/i', 'er') + ->singular('/er$/i', '') + ->singular('/re$/i', 'r') + ->irregular('konto', 'konti') + ->uncountable(explode(' ', 'barn fjell hus')); + } +} diff --git a/lib/Inflections/pt.php b/lib/Inflections/pt.php index 33c5a90..116ea07 100644 --- a/lib/Inflections/pt.php +++ b/lib/Inflections/pt.php @@ -9,88 +9,97 @@ * file that was distributed with this source code. */ -namespace ICanBoogie; +namespace ICanBoogie\Inflections; + +use ICanBoogie\Inflections; +use ICanBoogie\InflectionsConfigurator; + +use function explode; /** - * English Inflections. + * Portuguese inflections. + * + * @codeCoverageIgnore */ -//@codeCoverageIgnoreStart -return function (Inflections $inflect): void { - $inflect - ->plural('/$/', 's') - ->plural('/(s)$/i', '\1') - ->plural('/(z|r)$/i', '\1es') - ->plural('/al$/i', 'ais') - ->plural('/el$/i', 'eis') - ->plural('/ol$/i', 'ois') - ->plural('/ul$/i', 'uis') - ->plural('/([^aeou])il$/i', '\1is') - ->plural('/m$/i', 'ns') - ->plural('/^(japon|escoc|ingl|dinamarqu|fregu|portugu)ês$/i', '\1eses') - ->plural('/^(|g)ás$/i', '\1ases') - ->plural('/ão$/i', 'ões') - ->plural('/^(irm|m)ão$/i', '\1ãos') - ->plural('/^(alem|c|p)ão$/i', '\1ães') +final class pt implements InflectionsConfigurator +{ + public static function configure(Inflections $inflections): void + { + $inflections + ->plural('/$/', 's') + ->plural('/(s)$/i', '\1') + ->plural('/(z|r)$/i', '\1es') + ->plural('/al$/i', 'ais') + ->plural('/el$/i', 'eis') + ->plural('/ol$/i', 'ois') + ->plural('/ul$/i', 'uis') + ->plural('/([^aeou])il$/i', '\1is') + ->plural('/m$/i', 'ns') + ->plural('/^(japon|escoc|ingl|dinamarqu|fregu|portugu)ês$/i', '\1eses') + ->plural('/^(|g)ás$/i', '\1ases') + ->plural('/ão$/i', 'ões') + ->plural('/^(irm|m)ão$/i', '\1ãos') + ->plural('/^(alem|c|p)ão$/i', '\1ães') + + # Sem acentos... + ->plural('/ao$/i', 'oes') + ->plural('/^(irm|m)ao$/i', '\1aos') + ->plural('/^(alem|c|p)ao$/i', '\1aes') + ->singular('/([^ê])s$/i', '\1') + ->singular('/^(á|gá)s$/i', '\1s') + ->singular('/(r|z)es$/i', '\1') + ->singular('/([^p])ais$/i', '\1al') + ->singular('/éis$/i', 'el') + ->singular('/eis$/i', 'ei') + ->singular('/ois$/i', 'ol') + ->singular('/uis$/i', 'ul') + ->singular('/(r|t|f|v)is$/i', '\1il') + ->singular('/ns$/i', 'm') + ->singular('/sses$/i', 'sse') + ->singular('/^(.*[^s]s)es$/i', '\1') + ->singular('/(ãe|ão|õe)s$/', 'ão') + ->singular('/(ae|ao|oe)s$/', 'ao') + ->singular('/(japon|escoc|ingl|dinamarqu|fregu|portugu)eses$/i', '\1ês') + ->singular('/^(g|)ases$/i', '\1ás') - # Sem acentos... - ->plural('/ao$/i', 'oes') - ->plural('/^(irm|m)ao$/i', '\1aos') - ->plural('/^(alem|c|p)ao$/i', '\1aes') - ->singular('/([^ê])s$/i', '\1') - ->singular('/^(á|gá)s$/i', '\1s') - ->singular('/(r|z)es$/i', '\1') - ->singular('/([^p])ais$/i', '\1al') - ->singular('/éis$/i', 'el') - ->singular('/eis$/i', 'ei') - ->singular('/ois$/i', 'ol') - ->singular('/uis$/i', 'ul') - ->singular('/(r|t|f|v)is$/i', '\1il') - ->singular('/ns$/i', 'm') - ->singular('/sses$/i', 'sse') - ->singular('/^(.*[^s]s)es$/i', '\1') - ->singular('/(ãe|ão|õe)s$/', 'ão') - ->singular('/(ae|ao|oe)s$/', 'ao') - ->singular('/(japon|escoc|ingl|dinamarqu|fregu|portugu)eses$/i', '\1ês') - ->singular('/^(g|)ases$/i', '\1ás') + ->irregular('abdomen', 'abdomens') + ->irregular('alemão', 'alemães') + ->irregular('artesã', 'artesãos') + ->irregular('álcool', 'álcoois') + ->irregular("árvore", "árvores") + ->irregular('bencão', 'bencãos') + ->irregular('cão', 'cães') + ->irregular('campus', 'campi') + ->irregular("cadáver", "cadáveres") + ->irregular('capelão', 'capelães') + ->irregular('capitão', 'capitães') + ->irregular('chão', 'chãos') + ->irregular('charlatão', 'charlatães') + ->irregular('cidadão', 'cidadãos') + ->irregular('consul', 'consules') + ->irregular('cristão', 'cristãos') + ->irregular('difícil', 'difíceis') + ->irregular('email', 'emails') + ->irregular('escrivão', 'escrivães') + ->irregular('fóssil', 'fósseis') + ->irregular('gás', 'gases') + ->irregular('germens', 'germen') + ->irregular('grão', 'grãos') + ->irregular('hífen', 'hífens') + ->irregular('irmão', 'irmãos') + ->irregular('liquens', 'liquen') + ->irregular('mal', 'males') + ->irregular('mão', 'mãos') + ->irregular('orfão', 'orfãos') + ->irregular('país', 'países') + ->irregular('pai', 'pais') + ->irregular('pão', 'pães') + ->irregular('projétil', 'projéteis') + ->irregular('réptil', 'répteis') + ->irregular('sacristão', 'sacristães') + ->irregular('sotão', 'sotãos') + ->irregular('tabelião', 'tabeliães') - # Irregulares - ->irregular('abdomen', 'abdomens') - ->irregular('alemão', 'alemães') - ->irregular('artesã', 'artesãos') - ->irregular('álcool', 'álcoois') - ->irregular("árvore", "árvores") - ->irregular('bencão', 'bencãos') - ->irregular('cão', 'cães') - ->irregular('campus', 'campi') - ->irregular("cadáver", "cadáveres") - ->irregular('capelão', 'capelães') - ->irregular('capitão', 'capitães') - ->irregular('chão', 'chãos') - ->irregular('charlatão', 'charlatães') - ->irregular('cidadão', 'cidadãos') - ->irregular('consul', 'consules') - ->irregular('cristão', 'cristãos') - ->irregular('difícil', 'difíceis') - ->irregular('email', 'emails') - ->irregular('escrivão', 'escrivães') - ->irregular('fóssil', 'fósseis') - ->irregular('gás', 'gases') - ->irregular('germens', 'germen') - ->irregular('grão', 'grãos') - ->irregular('hífen', 'hífens') - ->irregular('irmão', 'irmãos') - ->irregular('liquens', 'liquen') - ->irregular('mal', 'males') - ->irregular('mão', 'mãos') - ->irregular('orfão', 'orfãos') - ->irregular('país', 'países') - ->irregular('pai', 'pais') - ->irregular('pão', 'pães') - ->irregular('projétil', 'projéteis') - ->irregular('réptil', 'répteis') - ->irregular('sacristão', 'sacristães') - ->irregular('sotão', 'sotãos') - ->irregular('tabelião', 'tabeliães') - ->uncountable(explode(' ', 'tórax tênis ônibus lápis fênix')); -}; -//@codeCoverageIgnoreEnd + ->uncountable(explode(' ', 'tórax tênis ônibus lápis fênix')); + } +} diff --git a/lib/Inflections/tr.php b/lib/Inflections/tr.php index 582af30..4897341 100644 --- a/lib/Inflections/tr.php +++ b/lib/Inflections/tr.php @@ -9,19 +9,26 @@ * file that was distributed with this source code. */ -namespace ICanBoogie; +namespace ICanBoogie\Inflections; + +use ICanBoogie\Inflections; +use ICanBoogie\InflectionsConfigurator; /** * Turkish Inflections. + * + * @codeCoverageIgnore */ -//@codeCoverageIgnoreStart -return function (Inflections $inflect): void { - $inflect - ->plural('/([aoıu][^aoıueöiü]{0,6})$/u', '\1lar') - ->plural('/([eöiü][^aoıueöiü]{0,6})$/u', '\1ler') - ->singular('/l[ae]r$/i', '') - ->irregular('ben', 'biz') - ->irregular('sen', 'siz') - ->irregular('o', 'onlar'); -}; -//@codeCoverageIgnoreEnd +final class tr implements InflectionsConfigurator +{ + public static function configure(Inflections $inflections): void + { + $inflections + ->plural('/([aoıu][^aoıueöiü]{0,6})$/u', '\1lar') + ->plural('/([eöiü][^aoıueöiü]{0,6})$/u', '\1ler') + ->singular('/l[ae]r$/i', '') + ->irregular('ben', 'biz') + ->irregular('sen', 'siz') + ->irregular('o', 'onlar'); + } +} diff --git a/lib/InflectionsConfigurator.php b/lib/InflectionsConfigurator.php new file mode 100644 index 0000000..b43c9a8 --- /dev/null +++ b/lib/InflectionsConfigurator.php @@ -0,0 +1,11 @@ +$property; } - if (class_exists('ICanBoogie\PropertyNotDefined')) { + if (class_exists(PropertyNotDefined::class)) { throw new PropertyNotDefined([ $property, $this ]); } else { throw new InvalidArgumentException("Property not defined: $property"); diff --git a/phpcs.xml b/phpcs.xml index 9fd746e..eb77ed7 100644 --- a/phpcs.xml +++ b/phpcs.xml @@ -12,15 +12,19 @@ */lib/helpers.php - */lib/inflections/* + */lib/Inflections/* */lib/helpers.php - */lib/inflections/* + */lib/Inflections/* - */lib/inflections/* + */lib/Inflections/* + + + + */lib/Inflections/*