File tree 3 files changed +36
-1
lines changed
3 files changed +36
-1
lines changed Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ /**
4
+ * @see https://github.com/open-code-modeling/php-filter for the canonical source repository
5
+ * @copyright https://github.com/open-code-modeling/php-filter/blob/master/COPYRIGHT.md
6
+ * @license https://github.com/open-code-modeling/php-filter/blob/master/LICENSE.md MIT License
7
+ */
8
+
9
+ declare (strict_types=1 );
10
+
11
+ namespace OpenCodeModeling \Filter \Filter ;
12
+
13
+ final class UpperToLower extends AbstractFilter
14
+ {
15
+ public function __invoke (string $ value ): string
16
+ {
17
+ $ value = ($ this ->filter )($ value );
18
+
19
+ if (1 === \preg_match ('/^[A-Z]+$/ ' , $ value )) {
20
+ return \strtolower ($ value );
21
+ }
22
+
23
+ return $ value ;
24
+ }
25
+ }
Original file line number Diff line number Diff line change 16
16
use OpenCodeModeling \Filter \Filter \LowerCaseFirst ;
17
17
use OpenCodeModeling \Filter \Filter \NormalizeLabel ;
18
18
use OpenCodeModeling \Filter \Filter \UpperCaseFirst ;
19
+ use OpenCodeModeling \Filter \Filter \UpperToLower ;
19
20
20
21
final class FilterFactory
21
22
{
@@ -93,7 +94,7 @@ public static function propertyNameFilter(): callable
93
94
*/
94
95
public static function methodNameFilter (): callable
95
96
{
96
- return new LowerCaseFirst (self ::normalizeFilter ());
97
+ return new LowerCaseFirst (self ::normalizeFilter (new UpperToLower () ));
97
98
}
98
99
99
100
/**
Original file line number Diff line number Diff line change @@ -36,6 +36,15 @@ public function it_filters_method_name(string $label): void
36
36
$ this ->assertSame ('addBuilding ' , ($ filter )($ label ));
37
37
}
38
38
39
+ /**
40
+ * @test
41
+ */
42
+ public function it_filters_method_name_with_only_upper_letters (): void
43
+ {
44
+ $ filter = FilterFactory::methodNameFilter ();
45
+ $ this ->assertSame ('ny ' , ($ filter )('NY ' ));
46
+ }
47
+
39
48
/**
40
49
* @test
41
50
* @dataProvider providerForLabel
You can’t perform that action at this time.
0 commit comments