Skip to content

Commit

Permalink
Replaced jawira/case-converter with symfony/string (#1336)
Browse files Browse the repository at this point in the history
* Replaced jawira/case-converter with symfony/string

* Use snake case instead of a kamel case in tests
  • Loading branch information
norberttech authored Jan 6, 2025
1 parent d6a4106 commit cde543f
Show file tree
Hide file tree
Showing 17 changed files with 232 additions and 461 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
"elasticsearch/elasticsearch": "^7.6|^8.0",
"google/apiclient": "^2.13",
"halaxa/json-machine": "^1.1",
"jawira/case-converter": "^3.4",
"meilisearch/meilisearch-php": "^1.11",
"monolog/monolog": "^2.0||^3.0",
"packaged/thrift": "^0.15.0",
Expand All @@ -38,6 +37,7 @@
"psr/simple-cache": "^1.0 || ^2.0 || ^3.0",
"symfony/console": "^5.4 || ^6.4 || ^7.0",
"symfony/http-foundation": "~5.4.0 || ~6.4.0 || ~7",
"symfony/string": "^5.4 || ^6.4 || ^7.0",
"webmozart/glob": "^3.0 || ^4.0"
},
"require-dev": {
Expand Down
108 changes: 21 additions & 87 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/core/etl/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"flow-php/filesystem": "^0.10.0 || 1.x-dev",
"psr/simple-cache": "^1.0 || ^2.0 || ^3.0",
"webmozart/glob": "^3.0 || ^4.0",
"jawira/case-converter": "^3.4"
"symfony/string": "^5.4 || ^6.4 || ^7.0"
},
"require-dev": {
"ramsey/uuid": "^4.5",
Expand Down
5 changes: 2 additions & 3 deletions src/core/etl/src/Flow/ETL/DataFrame.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
use Flow\ETL\Extractor\FileExtractor;
use Flow\ETL\Filesystem\{SaveMode, ScalarFunctionFilter};
use Flow\ETL\Formatter\AsciiTableFormatter;
use Flow\ETL\Function\{AggregatingFunction, ScalarFunction, WindowFunction};
use Flow\ETL\Function\{AggregatingFunction, ScalarFunction, StyleConverter\StringStyles, WindowFunction};
use Flow\ETL\Join\{Expression, Join};
use Flow\ETL\Loader\SchemaValidationLoader;
use Flow\ETL\Loader\StreamLoader\Output;
Expand All @@ -26,7 +26,6 @@
SortingPipeline,
VoidPipeline};
use Flow\ETL\Row\{Reference, References, Schema, Schema\Definition};
use Flow\ETL\Transformer\StyleConverter\StringStyles;
use Flow\ETL\Transformer\{
AutoCastTransformer,
CallbackRowTransformer,
Expand Down Expand Up @@ -688,7 +687,7 @@ public function renameAllLowerCase() : self
/**
* @lazy
* Rename all entries to given style.
* Please look into \Flow\ETL\Transformer\StyleConverter\StringStyles class for all available styles.
* Please look into \Flow\ETL\Function\StyleConverter\StringStyles class for all available styles.
*/
public function renameAllStyle(StringStyles|string $style) : self
{
Expand Down
3 changes: 1 addition & 2 deletions src/core/etl/src/Flow/ETL/Function/ArrayKeysStyleConvert.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

use Flow\ETL\Function\StyleConverter\StringStyles;
use Flow\ETL\Row;
use Jawira\CaseConverter\Convert;

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

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

return $converter->convert($array);
Expand Down
27 changes: 13 additions & 14 deletions src/core/etl/src/Flow/ETL/Function/StyleConverter/StringStyles.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,21 @@

namespace Flow\ETL\Function\StyleConverter;

use function Symfony\Component\String\u;
use Flow\ETL\Exception\InvalidArgumentException;

enum StringStyles : string
{
case ADA = 'ada';

case CAMEL = 'camel';

case COBOL = 'cobol';

case DOT = 'dot';

case KEBAB = 'kebab';

case LOWER = 'lower';

case MACRO = 'macro';

case PASCAL = 'pascal';

case SENTENCE = 'sentence';

case SNAKE = 'snake';

case TITLE = 'title';

case TRAIN = 'train';

case UPPER = 'upper';

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

throw new InvalidArgumentException("Unrecognized style {$style}, please use one of following: " . \implode(', ', self::all()));
}

public function convert(string $value) : string
{
return match ($this) {
self::CAMEL => u($value)->camel()->toString(),
self::KEBAB => u($value)->kebab()->toString(),
self::LOWER => u($value)->lower()->toString(),
self::SNAKE => u($value)->snake()->toString(),
self::TITLE => u($value)->title()->toString(),
self::UPPER => u($value)->upper()->toString(),
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,19 @@

namespace Flow\ETL\Transformer;

use Flow\ETL\Exception\RuntimeException;
use Flow\ETL\Row\Entry;
use Flow\ETL\Transformer\StyleConverter\StringStyles;
use Flow\ETL\{FlowContext, Row, Rows, Transformer};
use Jawira\CaseConverter\Convert;
use Flow\ETL\{FlowContext, Function\StyleConverter\StringStyles, Row, Rows, Transformer};

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

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

return $row->map($valueMap);
};
Expand Down
Loading

0 comments on commit cde543f

Please sign in to comment.