|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Created by PhpStorm. |
|
4
|
|
|
* User: alex |
|
5
|
|
|
* Date: 9/05/20 |
|
6
|
|
|
* Time: 4:00 AM |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
namespace POData; |
|
10
|
|
|
|
|
11
|
|
|
use Doctrine\Inflector\Inflector; |
|
|
|
|
|
|
12
|
|
|
use Doctrine\Inflector\InflectorFactory; |
|
|
|
|
|
|
13
|
|
|
|
|
14
|
|
|
class Pluralizer |
|
15
|
|
|
{ |
|
16
|
|
|
/** |
|
17
|
|
|
* Uncountable word forms. |
|
18
|
|
|
* |
|
19
|
|
|
* @var array |
|
20
|
|
|
*/ |
|
21
|
|
|
public static $uncountable = [ |
|
22
|
|
|
'audio', |
|
23
|
|
|
'bison', |
|
24
|
|
|
'cattle', |
|
25
|
|
|
'chassis', |
|
26
|
|
|
'compensation', |
|
27
|
|
|
'coreopsis', |
|
28
|
|
|
'data', |
|
29
|
|
|
'deer', |
|
30
|
|
|
'education', |
|
31
|
|
|
'emoji', |
|
32
|
|
|
'equipment', |
|
33
|
|
|
'evidence', |
|
34
|
|
|
'feedback', |
|
35
|
|
|
'firmware', |
|
36
|
|
|
'fish', |
|
37
|
|
|
'furniture', |
|
38
|
|
|
'gold', |
|
39
|
|
|
'hardware', |
|
40
|
|
|
'information', |
|
41
|
|
|
'jedi', |
|
42
|
|
|
'kin', |
|
43
|
|
|
'knowledge', |
|
44
|
|
|
'love', |
|
45
|
|
|
'metadata', |
|
46
|
|
|
'money', |
|
47
|
|
|
'moose', |
|
48
|
|
|
'news', |
|
49
|
|
|
'nutrition', |
|
50
|
|
|
'offspring', |
|
51
|
|
|
'plankton', |
|
52
|
|
|
'pokemon', |
|
53
|
|
|
'police', |
|
54
|
|
|
'rain', |
|
55
|
|
|
'recommended', |
|
56
|
|
|
'related', |
|
57
|
|
|
'rice', |
|
58
|
|
|
'series', |
|
59
|
|
|
'sheep', |
|
60
|
|
|
'software', |
|
61
|
|
|
'species', |
|
62
|
|
|
'swine', |
|
63
|
|
|
'traffic', |
|
64
|
|
|
'wheat', |
|
65
|
|
|
]; |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* Get the plural form of an English word. |
|
69
|
|
|
* |
|
70
|
|
|
* @param string $value |
|
71
|
|
|
* @param int $count |
|
72
|
|
|
* @return string |
|
73
|
|
|
*/ |
|
74
|
|
|
public static function plural($value, $count = 2) |
|
75
|
|
|
{ |
|
76
|
|
|
if ((int) abs($count) === 1 || static::uncountable($value)) { |
|
77
|
|
|
return $value; |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
$inflec = InflectorFactory::create()->build(); |
|
81
|
|
|
|
|
82
|
|
|
$plural = $inflec->pluralize($value); |
|
83
|
|
|
|
|
84
|
|
|
return static::matchCase($plural, $value); |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
/** |
|
88
|
|
|
* Get the singular form of an English word. |
|
89
|
|
|
* |
|
90
|
|
|
* @param string $value |
|
91
|
|
|
* @return string |
|
92
|
|
|
*/ |
|
93
|
|
|
public static function singular($value) |
|
94
|
|
|
{ |
|
95
|
|
|
$singular = Inflector::singularize($value); |
|
96
|
|
|
|
|
97
|
|
|
return static::matchCase($singular, $value); |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
/** |
|
101
|
|
|
* Determine if the given value is uncountable. |
|
102
|
|
|
* |
|
103
|
|
|
* @param string $value |
|
104
|
|
|
* @return bool |
|
105
|
|
|
*/ |
|
106
|
|
|
protected static function uncountable($value) |
|
107
|
|
|
{ |
|
108
|
|
|
return in_array(strtolower($value), static::$uncountable); |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
/** |
|
112
|
|
|
* Attempt to match the case on two strings. |
|
113
|
|
|
* |
|
114
|
|
|
* @param string $value |
|
115
|
|
|
* @param string $comparison |
|
116
|
|
|
* @return string |
|
117
|
|
|
*/ |
|
118
|
|
|
protected static function matchCase($value, $comparison) |
|
119
|
|
|
{ |
|
120
|
|
|
$functions = ['mb_strtolower', 'mb_strtoupper', 'ucfirst', 'ucwords']; |
|
121
|
|
|
|
|
122
|
|
|
foreach ($functions as $function) { |
|
123
|
|
|
if (call_user_func($function, $comparison) === $comparison) { |
|
124
|
|
|
return call_user_func($function, $value); |
|
125
|
|
|
} |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
|
return $value; |
|
129
|
|
|
} |
|
130
|
|
|
|
|
131
|
|
|
} |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths