Skip to content

Commit 46aa946

Browse files
authored
Merge pull request #13 from php-etl/feature/transform-into-string
Added a new function to transform an integer into a string
2 parents 144504a + 5fa1755 commit 46aa946

File tree

8 files changed

+44
-8
lines changed

8 files changed

+44
-8
lines changed

.github/workflows/phpstan-6.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: PHPStan level 6
22
on: push
33
jobs:
4-
phpstan:
4+
phpstan6:
55
runs-on: ubuntu-latest
66
steps:
77
- uses: actions/checkout@v3

.github/workflows/phpstan-7.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: PHPStan level 7
22
on: push
33
jobs:
4-
phpstan:
4+
phpstan7:
55
runs-on: ubuntu-latest
66
steps:
77
- uses: actions/checkout@v3

.github/workflows/phpstan-8.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: PHPStan level 8
22
on: push
33
jobs:
4-
phpstan:
4+
phpstan8:
55
runs-on: ubuntu-latest
66
steps:
77
- uses: actions/checkout@v3

src/AsFloat.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
<?php declare(strict_types=1);
1+
<?php
2+
3+
declare(strict_types=1);
24

35
namespace Kiboko\Component\StringExpressionLanguage;
46

@@ -18,7 +20,7 @@ public function __construct($name)
1820
private function compile(string $value): string
1921
{
2022
return <<<PHP
21-
((float) $value)
23+
((float) {$value})
2224
PHP;
2325
}
2426

src/AsInteger.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
<?php declare(strict_types=1);
1+
<?php
2+
3+
declare(strict_types=1);
24

35
namespace Kiboko\Component\StringExpressionLanguage;
46

@@ -18,7 +20,7 @@ public function __construct($name)
1820
private function compile(string $value): string
1921
{
2022
return <<<PHP
21-
((int) $value)
23+
((int) {$value})
2224
PHP;
2325
}
2426

src/AsString.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Kiboko\Component\StringExpressionLanguage;
6+
7+
use Symfony\Component\ExpressionLanguage\ExpressionFunction;
8+
9+
final class AsString extends ExpressionFunction
10+
{
11+
public function __construct($name)
12+
{
13+
parent::__construct(
14+
$name,
15+
$this->compile(...)->bindTo($this),
16+
$this->evaluate(...)->bindTo($this)
17+
);
18+
}
19+
20+
private function compile(string $value): string
21+
{
22+
return <<<PHP
23+
((string) {$value})
24+
PHP;
25+
}
26+
27+
private function evaluate(array $context, int|float|string $value): string
28+
{
29+
return (string) $value;
30+
}
31+
}

src/ConvertCharCode.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public function __construct($name)
2020
private function compile(string $text, string $sourceCharCode, string $destinationCharCode): string
2121
{
2222
return <<<"PHP"
23-
iconv($sourceCharCode, $destinationCharCode, $text)
23+
iconv({$sourceCharCode}, {$destinationCharCode}, {$text})
2424
PHP;
2525
}
2626

src/StringExpressionLanguageProvider.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public function getFunctions(): array
3535
new ConvertCharCode('convertCharCode'),
3636
new AsFloat('asFloat'),
3737
new AsInteger('asInteger'),
38+
new AsString('asString'),
3839
];
3940
}
4041
}

0 commit comments

Comments
 (0)