Skip to content

Commit 81b3d9b

Browse files
committed
Update doctrine/inflector to v2, add proxies for all former methods
1 parent 844fea6 commit 81b3d9b

3 files changed

Lines changed: 76 additions & 18 deletions

File tree

Tests/InflectorTest.php

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -92,20 +92,6 @@ protected function setUp(): void
9292
parent::setUp();
9393

9494
$this->inflector = new Inflector();
95-
DoctrineInflector::reset();
96-
}
97-
98-
/**
99-
* Tears down the fixture, for example, close a network connection.
100-
* This method is called after a test is executed.
101-
*
102-
* @return void
103-
*/
104-
protected function tearDown(): void
105-
{
106-
DoctrineInflector::reset();
107-
108-
parent::tearDown();
10995
}
11096

11197
/**
@@ -214,7 +200,7 @@ public function testIsSingular(string $singular, string $plural)
214200
}
215201
}
216202

217-
private function checkInflectorImplementation(DoctrineInflector $inflector): bool
203+
private function checkInflectorImplementation(Inflector $inflector): bool
218204
{
219205
$reflectionClass = new \ReflectionClass($inflector);
220206

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"symfony/polyfill-mbstring": "^1.31.0"
1212
},
1313
"require-dev": {
14-
"doctrine/inflector": "^1.2",
14+
"doctrine/inflector": "^2.0.10",
1515
"joomla/test": "dev-4.x-dev",
1616
"phpunit/phpunit": "^12.2.6",
1717
"squizlabs/php_codesniffer": "^3.7.2",

src/Inflector.php

Lines changed: 74 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
namespace Joomla\String;
1111

12-
use Doctrine\Common\Inflector\Inflector as DoctrineInflector;
12+
use Doctrine\Inflector\InflectorFactory;
1313

1414
/**
1515
* Joomla Framework String Inflector Class
@@ -19,7 +19,7 @@
1919
* @since 1.0
2020
* @deprecated 5.0 Use doctrine/inflector package as complete replacement instead.
2121
*/
22-
class Inflector extends DoctrineInflector
22+
class Inflector
2323
{
2424
/**
2525
* The inflector rules for countability.
@@ -123,4 +123,76 @@ public function isSingular($word)
123123
{
124124
return static::singularize($word) === $word;
125125
}
126+
127+
/**
128+
* Proxy for Inflector::tableize()
129+
*/
130+
public static function tableize(string $word) : string
131+
{
132+
$inflector = InflectorFactory::create()->build();
133+
134+
return $inflector->tableize($word);
135+
}
136+
137+
/**
138+
* Proxy for Inflector::classify()
139+
*/
140+
public static function classify(string $word) : string
141+
{
142+
$inflector = InflectorFactory::create()->build();
143+
144+
return $inflector->classify($word);
145+
}
146+
147+
/**
148+
* Proxy for Inflector::camelize()
149+
*/
150+
public static function camelize(string $word) : string
151+
{
152+
$inflector = InflectorFactory::create()->build();
153+
154+
return $inflector->camelize($word);
155+
}
156+
157+
/**
158+
* Proxy for Inflector::ucwords()
159+
*/
160+
public static function ucwords(string $string, string $delimiters = " \n\t\r\0\x0B-") : string
161+
{
162+
return ucwords($string, $delimiters);
163+
}
164+
165+
/**
166+
* Empty method to suffice the former interface
167+
*/
168+
public static function reset() : void
169+
{
170+
}
171+
172+
/**
173+
* Empty method to suffice the former interface
174+
*/
175+
public static function rules(string $type, iterable $rules, bool $reset = false) : void
176+
{
177+
}
178+
179+
/**
180+
* Proxy for Inflector::pluralize()
181+
*/
182+
public static function pluralize(string $word) : string
183+
{
184+
$inflector = InflectorFactory::create()->build();
185+
186+
return $inflector->pluralize($word);
187+
}
188+
189+
/**
190+
* Proxy for Inflector::singularize()
191+
*/
192+
public static function singularize(string $word) : string
193+
{
194+
$inflector = InflectorFactory::create()->build();
195+
196+
return $inflector->singularize($word);
197+
}
126198
}

0 commit comments

Comments
 (0)