File tree Expand file tree Collapse file tree 3 files changed +36
-1
lines changed Expand file tree Collapse file tree 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 1616use OpenCodeModeling \Filter \Filter \LowerCaseFirst ;
1717use OpenCodeModeling \Filter \Filter \NormalizeLabel ;
1818use OpenCodeModeling \Filter \Filter \UpperCaseFirst ;
19+ use OpenCodeModeling \Filter \Filter \UpperToLower ;
1920
2021final class FilterFactory
2122{
@@ -93,7 +94,7 @@ public static function propertyNameFilter(): callable
9394 */
9495 public static function methodNameFilter (): callable
9596 {
96- return new LowerCaseFirst (self ::normalizeFilter ());
97+ return new LowerCaseFirst (self ::normalizeFilter (new UpperToLower () ));
9798 }
9899
99100 /**
Original file line number Diff line number Diff line change @@ -36,6 +36,15 @@ public function it_filters_method_name(string $label): void
3636 $ this ->assertSame ('addBuilding ' , ($ filter )($ label ));
3737 }
3838
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+
3948 /**
4049 * @test
4150 * @dataProvider providerForLabel
You can’t perform that action at this time.
0 commit comments