Skip to content

Commit c8670ee

Browse files
committed
feature #30810 [Inflector] remove "internal" marker from the component (nicolas-grekas)
This PR was merged into the 4.3-dev branch. Discussion ---------- [Inflector] remove "internal" marker from the component | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #26903 | License | MIT | Doc PR | - This code works: making it non-internal won't increase the maintenance burden and can help others build on it. Commits ------- 164b45b [Inflector] remove "internal" marker from the component
2 parents 9bcea2e + 164b45b commit c8670ee

File tree

3 files changed

+194
-208
lines changed

3 files changed

+194
-208
lines changed

src/Symfony/Component/Inflector/Inflector.php

+75-82
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,12 @@
1515
* Converts words between singular and plural forms.
1616
*
1717
* @author Bernhard Schussek <bschussek@gmail.com>
18-
*
19-
* @internal
2018
*/
2119
final class Inflector
2220
{
2321
/**
2422
* Map English plural to singular suffixes.
2523
*
26-
* @var array
27-
*
2824
* @see http://english-zone.com/spelling/plurals.html
2925
*/
3026
private static $pluralMap = [
@@ -142,175 +138,178 @@ final class Inflector
142138
/**
143139
* Map English singular to plural suffixes.
144140
*
145-
* @var array
146-
*
147141
* @see http://english-zone.com/spelling/plurals.html
148142
*/
149-
private static $singularMap = array(
143+
private static $singularMap = [
150144
// First entry: singular suffix, reversed
151145
// Second entry: length of singular suffix
152146
// Third entry: Whether the suffix may succeed a vocal
153147
// Fourth entry: Whether the suffix may succeed a consonant
154148
// Fifth entry: plural suffix, normal
155149

156150
// criterion (criteria)
157-
array('airetirc', 8, false, false, 'criterion'),
151+
['airetirc', 8, false, false, 'criterion'],
158152

159153
// nebulae (nebula)
160-
array('aluben', 6, false, false, 'nebulae'),
154+
['aluben', 6, false, false, 'nebulae'],
161155

162156
// children (child)
163-
array('dlihc', 5, true, true, 'children'),
157+
['dlihc', 5, true, true, 'children'],
164158

165159
// prices (price)
166-
array('eci', 3, false, true, 'ices'),
160+
['eci', 3, false, true, 'ices'],
167161

168162
// services (service)
169-
array('ecivres', 7, true, true, 'services'),
163+
['ecivres', 7, true, true, 'services'],
170164

171165
// lives (life), wives (wife)
172-
array('efi', 3, false, true, 'ives'),
166+
['efi', 3, false, true, 'ives'],
173167

174168
// selfies (selfie)
175-
array('eifles', 6, true, true, 'selfies'),
169+
['eifles', 6, true, true, 'selfies'],
176170

177171
// movies (movie)
178-
array('eivom', 5, true, true, 'movies'),
172+
['eivom', 5, true, true, 'movies'],
179173

180174
// lice (louse)
181-
array('esuol', 5, false, true, 'lice'),
175+
['esuol', 5, false, true, 'lice'],
182176

183177
// mice (mouse)
184-
array('esuom', 5, false, true, 'mice'),
178+
['esuom', 5, false, true, 'mice'],
185179

186180
// geese (goose)
187-
array('esoo', 4, false, true, 'eese'),
181+
['esoo', 4, false, true, 'eese'],
188182

189183
// houses (house), bases (base)
190-
array('es', 2, true, true, 'ses'),
184+
['es', 2, true, true, 'ses'],
191185

192186
// geese (goose)
193-
array('esoog', 5, true, true, 'geese'),
187+
['esoog', 5, true, true, 'geese'],
194188

195189
// caves (cave)
196-
array('ev', 2, true, true, 'ves'),
190+
['ev', 2, true, true, 'ves'],
197191

198192
// drives (drive)
199-
array('evird', 5, false, true, 'drives'),
193+
['evird', 5, false, true, 'drives'],
200194

201195
// objectives (objective), alternative (alternatives)
202-
array('evit', 4, true, true, 'tives'),
196+
['evit', 4, true, true, 'tives'],
203197

204198
// moves (move)
205-
array('evom', 4, true, true, 'moves'),
199+
['evom', 4, true, true, 'moves'],
206200

207201
// staves (staff)
208-
array('ffats', 5, true, true, 'staves'),
202+
['ffats', 5, true, true, 'staves'],
209203

210204
// hooves (hoof), dwarves (dwarf), elves (elf), leaves (leaf)
211-
array('ff', 2, true, true, 'ffs'),
205+
['ff', 2, true, true, 'ffs'],
212206

213207
// hooves (hoof), dwarves (dwarf), elves (elf), leaves (leaf)
214-
array('f', 1, true, true, array('fs', 'ves')),
208+
['f', 1, true, true, ['fs', 'ves']],
215209

216210
// arches (arch)
217-
array('hc', 2, true, true, 'ches'),
211+
['hc', 2, true, true, 'ches'],
218212

219213
// bushes (bush)
220-
array('hs', 2, true, true, 'shes'),
214+
['hs', 2, true, true, 'shes'],
221215

222216
// teeth (tooth)
223-
array('htoot', 5, true, true, 'teeth'),
217+
['htoot', 5, true, true, 'teeth'],
224218

225219
// bacteria (bacterium), criteria (criterion), phenomena (phenomenon)
226-
array('mu', 2, true, true, 'a'),
227-
228-
// echoes (echo)
229-
array('ohce', 4, true, true, 'echoes'),
220+
['mu', 2, true, true, 'a'],
230221

231222
// men (man), women (woman)
232-
array('nam', 3, true, true, 'men'),
223+
['nam', 3, true, true, 'men'],
233224

234225
// people (person)
235-
array('nosrep', 6, true, true, array('persons', 'people')),
226+
['nosrep', 6, true, true, ['persons', 'people']],
236227

237228
// bacteria (bacterium), criteria (criterion), phenomena (phenomenon)
238-
array('noi', 3, true, true, 'ions'),
229+
['noi', 3, true, true, 'ions'],
239230

240231
// bacteria (bacterium), criteria (criterion), phenomena (phenomenon)
241-
array('no', 2, true, true, 'a'),
232+
['no', 2, true, true, 'a'],
233+
234+
// echoes (echo)
235+
['ohce', 4, true, true, 'echoes'],
236+
237+
// heroes (hero)
238+
['oreh', 4, true, true, 'heroes'],
242239

243240
// atlases (atlas)
244-
array('salta', 5, true, true, 'atlases'),
241+
['salta', 5, true, true, 'atlases'],
245242

246243
// irises (iris)
247-
array('siri', 4, true, true, 'irises'),
244+
['siri', 4, true, true, 'irises'],
248245

249246
// analyses (analysis), ellipses (ellipsis), neuroses (neurosis)
250247
// theses (thesis), emphases (emphasis), oases (oasis),
251248
// crises (crisis)
252-
array('sis', 3, true, true, 'ses'),
249+
['sis', 3, true, true, 'ses'],
253250

254251
// accesses (access), addresses (address), kisses (kiss)
255-
array('ss', 2, true, false, 'sses'),
252+
['ss', 2, true, false, 'sses'],
256253

257254
// syllabi (syllabus)
258-
array('suballys', 8, true, true, 'syllabi'),
255+
['suballys', 8, true, true, 'syllabi'],
259256

260257
// buses (bus)
261-
array('sub', 3, true, true, 'buses'),
258+
['sub', 3, true, true, 'buses'],
259+
260+
// circuses (circus)
261+
['suc', 3, true, true, 'cuses'],
262262

263263
// fungi (fungus), alumni (alumnus), syllabi (syllabus), radii (radius)
264-
array('su', 2, true, true, 'i'),
264+
['su', 2, true, true, 'i'],
265265

266266
// news (news)
267-
array('swen', 4, true, true, 'news'),
267+
['swen', 4, true, true, 'news'],
268268

269269
// feet (foot)
270-
array('toof', 4, true, true, 'feet'),
270+
['toof', 4, true, true, 'feet'],
271271

272272
// chateaux (chateau), bureaus (bureau)
273-
array('uae', 3, false, true, array('eaus', 'eaux')),
273+
['uae', 3, false, true, ['eaus', 'eaux']],
274274

275275
// oxen (ox)
276-
array('xo', 2, false, false, 'oxen'),
276+
['xo', 2, false, false, 'oxen'],
277277

278278
// hoaxes (hoax)
279-
array('xaoh', 4, true, false, 'hoaxes'),
279+
['xaoh', 4, true, false, 'hoaxes'],
280280

281281
// indices (index)
282-
array('xedni', 5, false, true, array('indicies', 'indexes')),
282+
['xedni', 5, false, true, ['indicies', 'indexes']],
283283

284284
// indexes (index), matrixes (matrix)
285-
array('x', 1, true, false, array('cies', 'xes')),
285+
['x', 1, true, false, ['cies', 'xes']],
286286

287287
// appendices (appendix)
288-
array('xi', 2, false, true, 'ices'),
288+
['xi', 2, false, true, 'ices'],
289289

290290
// babies (baby)
291-
array('y', 1, false, true, 'ies'),
291+
['y', 1, false, true, 'ies'],
292292

293293
// quizzes (quiz)
294-
array('ziuq', 4, true, false, 'quizzes'),
294+
['ziuq', 4, true, false, 'quizzes'],
295295

296296
// waltzes (waltz)
297-
array('z', 1, true, false, 'zes'),
298-
);
297+
['z', 1, true, true, 'zes'],
298+
];
299299

300300
/**
301-
* A list of words which should not be inflected.
302-
*
303-
* @var array
301+
* A list of words which should not be inflected, reversed.
304302
*/
305-
private static $uninflected = array(
306-
'data',
307-
'deer',
308-
'feedback',
309-
'fish',
310-
'moose',
311-
'series',
312-
'sheep',
313-
);
303+
private static $uninflected = [
304+
'atad',
305+
'reed',
306+
'kcabdeef',
307+
'hsif',
308+
'ofni',
309+
'esoom',
310+
'seires',
311+
'peehs',
312+
];
314313

315314
/**
316315
* This class should not be instantiated.
@@ -327,10 +326,7 @@ private function __construct()
327326
*
328327
* @param string $plural A word in plural form
329328
*
330-
* @return string|array The singular form or an array of possible singular
331-
* forms
332-
*
333-
* @internal
329+
* @return string|array The singular form or an array of possible singular forms
334330
*/
335331
public static function singularize(string $plural)
336332
{
@@ -339,7 +335,7 @@ public static function singularize(string $plural)
339335
$pluralLength = \strlen($lowerPluralRev);
340336

341337
// Check if the word is one which is not inflected, return early if so
342-
if (in_array(strtolower($plural), self::$uninflected, true)) {
338+
if (\in_array($lowerPluralRev, self::$uninflected, true)) {
343339
return $plural;
344340
}
345341

@@ -416,19 +412,16 @@ public static function singularize(string $plural)
416412
*
417413
* @param string $singular A word in plural form
418414
*
419-
* @return string|array The plural form or an array of possible plural
420-
* forms
421-
*
422-
* @internal
415+
* @return string|array The plural form or an array of possible plural forms
423416
*/
424417
public static function pluralize(string $singular)
425418
{
426419
$singularRev = strrev($singular);
427420
$lowerSingularRev = strtolower($singularRev);
428-
$singularLength = strlen($lowerSingularRev);
421+
$singularLength = \strlen($lowerSingularRev);
429422

430423
// Check if the word is one which is not inflected, return early if so
431-
if (in_array(strtolower($singular), self::$uninflected, true)) {
424+
if (\in_array($lowerSingularRev, self::$uninflected, true)) {
432425
return $singular;
433426
}
434427

@@ -474,8 +467,8 @@ public static function pluralize(string $singular)
474467
// the singular suffix too
475468
$firstUpper = ctype_upper($singularRev[$j - 1]);
476469

477-
if (is_array($newSuffix)) {
478-
$plurals = array();
470+
if (\is_array($newSuffix)) {
471+
$plurals = [];
479472

480473
foreach ($newSuffix as $newSuffixEntry) {
481474
$plurals[] = $newBase.($firstUpper ? ucfirst($newSuffixEntry) : $newSuffixEntry);

src/Symfony/Component/Inflector/README.md

-7
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,6 @@ Inflector Component
33

44
Inflector converts words between their singular and plural forms (English only).
55

6-
Disclaimer
7-
----------
8-
9-
This component is currently marked as internal. Do not use it in your own code.
10-
Breaking changes may be introduced in the next minor version of Symfony, or the
11-
component itself might even be removed completely.
12-
136
Resources
147
---------
158

0 commit comments

Comments
 (0)