Skip to content

Commit cde543f

Browse files
authored
Replaced jawira/case-converter with symfony/string (#1336)
* Replaced jawira/case-converter with symfony/string * Use snake case instead of a kamel case in tests
1 parent d6a4106 commit cde543f

File tree

17 files changed

+232
-461
lines changed

17 files changed

+232
-461
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
"elasticsearch/elasticsearch": "^7.6|^8.0",
2828
"google/apiclient": "^2.13",
2929
"halaxa/json-machine": "^1.1",
30-
"jawira/case-converter": "^3.4",
3130
"meilisearch/meilisearch-php": "^1.11",
3231
"monolog/monolog": "^2.0||^3.0",
3332
"packaged/thrift": "^0.15.0",
@@ -38,6 +37,7 @@
3837
"psr/simple-cache": "^1.0 || ^2.0 || ^3.0",
3938
"symfony/console": "^5.4 || ^6.4 || ^7.0",
4039
"symfony/http-foundation": "~5.4.0 || ~6.4.0 || ~7",
40+
"symfony/string": "^5.4 || ^6.4 || ^7.0",
4141
"webmozart/glob": "^3.0 || ^4.0"
4242
},
4343
"require-dev": {

composer.lock

Lines changed: 21 additions & 87 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/core/etl/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"flow-php/filesystem": "^0.10.0 || 1.x-dev",
1818
"psr/simple-cache": "^1.0 || ^2.0 || ^3.0",
1919
"webmozart/glob": "^3.0 || ^4.0",
20-
"jawira/case-converter": "^3.4"
20+
"symfony/string": "^5.4 || ^6.4 || ^7.0"
2121
},
2222
"require-dev": {
2323
"ramsey/uuid": "^4.5",

src/core/etl/src/Flow/ETL/DataFrame.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
use Flow\ETL\Extractor\FileExtractor;
1212
use Flow\ETL\Filesystem\{SaveMode, ScalarFunctionFilter};
1313
use Flow\ETL\Formatter\AsciiTableFormatter;
14-
use Flow\ETL\Function\{AggregatingFunction, ScalarFunction, WindowFunction};
14+
use Flow\ETL\Function\{AggregatingFunction, ScalarFunction, StyleConverter\StringStyles, WindowFunction};
1515
use Flow\ETL\Join\{Expression, Join};
1616
use Flow\ETL\Loader\SchemaValidationLoader;
1717
use Flow\ETL\Loader\StreamLoader\Output;
@@ -26,7 +26,6 @@
2626
SortingPipeline,
2727
VoidPipeline};
2828
use Flow\ETL\Row\{Reference, References, Schema, Schema\Definition};
29-
use Flow\ETL\Transformer\StyleConverter\StringStyles;
3029
use Flow\ETL\Transformer\{
3130
AutoCastTransformer,
3231
CallbackRowTransformer,
@@ -688,7 +687,7 @@ public function renameAllLowerCase() : self
688687
/**
689688
* @lazy
690689
* Rename all entries to given style.
691-
* Please look into \Flow\ETL\Transformer\StyleConverter\StringStyles class for all available styles.
690+
* Please look into \Flow\ETL\Function\StyleConverter\StringStyles class for all available styles.
692691
*/
693692
public function renameAllStyle(StringStyles|string $style) : self
694693
{

src/core/etl/src/Flow/ETL/Function/ArrayKeysStyleConvert.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
use Flow\ETL\Function\StyleConverter\StringStyles;
88
use Flow\ETL\Row;
9-
use Jawira\CaseConverter\Convert;
109

1110
final class ArrayKeysStyleConvert extends ScalarFunctionChain
1211
{
@@ -25,7 +24,7 @@ public function eval(Row $row) : mixed
2524
}
2625

2726
$converter = (new StyleConverter\ArrayKeyConverter(
28-
fn (string $key) : string => (string) \call_user_func([new Convert($key), 'to' . \ucfirst($this->style->value)])
27+
fn (string $key) : string => $this->style->convert($key)
2928
));
3029

3130
return $converter->convert($array);

src/core/etl/src/Flow/ETL/Function/StyleConverter/StringStyles.php

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,34 +4,21 @@
44

55
namespace Flow\ETL\Function\StyleConverter;
66

7+
use function Symfony\Component\String\u;
78
use Flow\ETL\Exception\InvalidArgumentException;
89

910
enum StringStyles : string
1011
{
11-
case ADA = 'ada';
12-
1312
case CAMEL = 'camel';
1413

15-
case COBOL = 'cobol';
16-
17-
case DOT = 'dot';
18-
1914
case KEBAB = 'kebab';
2015

2116
case LOWER = 'lower';
2217

23-
case MACRO = 'macro';
24-
25-
case PASCAL = 'pascal';
26-
27-
case SENTENCE = 'sentence';
28-
2918
case SNAKE = 'snake';
3019

3120
case TITLE = 'title';
3221

33-
case TRAIN = 'train';
34-
3522
case UPPER = 'upper';
3623

3724
/**
@@ -61,4 +48,16 @@ public static function fromString(string $style) : self
6148

6249
throw new InvalidArgumentException("Unrecognized style {$style}, please use one of following: " . \implode(', ', self::all()));
6350
}
51+
52+
public function convert(string $value) : string
53+
{
54+
return match ($this) {
55+
self::CAMEL => u($value)->camel()->toString(),
56+
self::KEBAB => u($value)->kebab()->toString(),
57+
self::LOWER => u($value)->lower()->toString(),
58+
self::SNAKE => u($value)->snake()->toString(),
59+
self::TITLE => u($value)->title()->toString(),
60+
self::UPPER => u($value)->upper()->toString(),
61+
};
62+
}
6463
}

src/core/etl/src/Flow/ETL/Transformer/EntryNameStyleConverterTransformer.php

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,19 @@
44

55
namespace Flow\ETL\Transformer;
66

7-
use Flow\ETL\Exception\RuntimeException;
87
use Flow\ETL\Row\Entry;
9-
use Flow\ETL\Transformer\StyleConverter\StringStyles;
10-
use Flow\ETL\{FlowContext, Row, Rows, Transformer};
11-
use Jawira\CaseConverter\Convert;
8+
use Flow\ETL\{FlowContext, Function\StyleConverter\StringStyles, Row, Rows, Transformer};
129

1310
final class EntryNameStyleConverterTransformer implements Transformer
1411
{
1512
public function __construct(private readonly StringStyles $style)
1613
{
17-
if (!\class_exists(Convert::class)) {
18-
throw new RuntimeException("Jawira\CaseConverter\Convert class not found, please add jawira/case-converter dependency to the project first.");
19-
}
2014
}
2115

2216
public function transform(Rows $rows, FlowContext $context) : Rows
2317
{
2418
$rowTransformer = function (Row $row) : Row {
25-
$valueMap = fn (Entry $entry) : Entry => $entry->rename(
26-
(string) \call_user_func([new Convert($entry->name()), 'to' . \ucfirst($this->style->value)])
27-
);
19+
$valueMap = fn (Entry $entry) : Entry => $entry->rename($this->style->convert($entry->name()));
2820

2921
return $row->map($valueMap);
3022
};

0 commit comments

Comments
 (0)