PluginProbe ʕ •ᴥ•ʔ
Kubio AI Page Builder / 2.8.6
Kubio AI Page Builder v2.8.6
2.9.0 2.8.6 2.8.5 2.8.4 2.8.3 2.8.2 2.8.1 trunk 1.0.0 1.0.1 1.1.0 1.2.0 1.2.1 1.2.2 1.2.3 1.3.0 1.3.1 1.3.2 1.4.0 1.4.1 1.4.2 1.4.3 1.5.0 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.7.0 1.7.1 1.7.2 1.7.3 1.8.0 1.8.1 1.8.2 1.9.0 2.0.0 2.1.1 2.1.2 2.1.3 2.2.0 2.2.3 2.2.4 2.2.5 2.3.0 2.3.1 2.3.3 2.3.4 2.4.0 2.4.1 2.4.2 2.4.3 2.4.5 2.5.0 2.5.1 2.5.2 2.5.3 2.6.0 2.6.1 2.6.2 2.6.3 2.6.5 2.6.6 2.6.7 2.7.0 2.7.1 2.7.2 2.7.3 2.8.0
kubio / vendor / pragmarx / ia-str / src / Support / Pluralizer.php
kubio / vendor / pragmarx / ia-str / src / Support Last commit date
Traits 1 year ago Arr.php 4 years ago Carbon.php 4 years ago Collection.php 1 year ago Enumerable.php 4 years ago HigherOrderCollectionProxy.php 4 years ago HigherOrderTapProxy.php 4 years ago HtmlString.php 4 years ago LazyCollection.php 4 years ago Optional.php 4 years ago Pluralizer.php 4 years ago Str.php 1 year ago alias.php 4 years ago helpers.php 4 years ago
Pluralizer.php
122 lines
1 <?php
2
3 namespace IlluminateAgnostic\Str\Support;
4
5 use Doctrine\Common\Inflector\Inflector;
6
7 class Pluralizer
8 {
9 /**
10 * Uncountable word forms.
11 *
12 * @var array
13 */
14 public static $uncountable = [
15 'audio',
16 'bison',
17 'cattle',
18 'chassis',
19 'compensation',
20 'coreopsis',
21 'data',
22 'deer',
23 'education',
24 'emoji',
25 'equipment',
26 'evidence',
27 'feedback',
28 'firmware',
29 'fish',
30 'furniture',
31 'gold',
32 'hardware',
33 'information',
34 'jedi',
35 'kin',
36 'knowledge',
37 'love',
38 'metadata',
39 'money',
40 'moose',
41 'news',
42 'nutrition',
43 'offspring',
44 'plankton',
45 'pokemon',
46 'police',
47 'rain',
48 'recommended',
49 'related',
50 'rice',
51 'series',
52 'sheep',
53 'software',
54 'species',
55 'swine',
56 'traffic',
57 'wheat',
58 ];
59
60 /**
61 * Get the plural form of an English word.
62 *
63 * @param string $value
64 * @param int $count
65 * @return string
66 */
67 public static function plural($value, $count = 2)
68 {
69 if ((int) abs($count) === 1 || static::uncountable($value)) {
70 return $value;
71 }
72
73 $plural = Inflector::pluralize($value);
74
75 return static::matchCase($plural, $value);
76 }
77
78 /**
79 * Get the singular form of an English word.
80 *
81 * @param string $value
82 * @return string
83 */
84 public static function singular($value)
85 {
86 $singular = Inflector::singularize($value);
87
88 return static::matchCase($singular, $value);
89 }
90
91 /**
92 * Determine if the given value is uncountable.
93 *
94 * @param string $value
95 * @return bool
96 */
97 protected static function uncountable($value)
98 {
99 return in_array(strtolower($value), static::$uncountable);
100 }
101
102 /**
103 * Attempt to match the case on two strings.
104 *
105 * @param string $value
106 * @param string $comparison
107 * @return string
108 */
109 protected static function matchCase($value, $comparison)
110 {
111 $functions = ['mb_strtolower', 'mb_strtoupper', 'ucfirst', 'ucwords'];
112
113 foreach ($functions as $function) {
114 if ($function($comparison) === $comparison) {
115 return $function($value);
116 }
117 }
118
119 return $value;
120 }
121 }
122