Skip to content

Commit 1b4621a

Browse files
committed
Add snake_case filter - Close #14
1 parent 57057f8 commit 1b4621a

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

src/FilterFactory.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,14 @@ public static function normalizeFilter(callable ...$callables): callable
4141
return $filter;
4242
}
4343

44+
public static function snakeCaseFilter(): callable
45+
{
46+
return self::normalizeFilter(
47+
new Filter\Word\CamelCaseToUnderscore(),
48+
new Filter\StringToLower()
49+
);
50+
}
51+
4452
/**
4553
* Returns a filter for valid class names e.g. AddBuilding
4654
*

tests/FilterFactoryTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,17 @@ public function providerForLabel(): Generator
2525
yield 'html' => ['Add Building<hr id="null"><div style="text-align: left;">- buildingId: string</div><div style="text-align: left;">- name: string</div>'];
2626
}
2727

28+
/**
29+
* @test
30+
* @dataProvider providerForLabel
31+
* @param string $label
32+
*/
33+
public function it_filters_snake_case(string $label): void
34+
{
35+
$filter = FilterFactory::snakeCaseFilter();
36+
$this->assertSame('add_building', ($filter)($label));
37+
}
38+
2839
/**
2940
* @test
3041
* @dataProvider providerForLabel

0 commit comments

Comments
 (0)