Skip to content

Commit 7b7bd1b

Browse files
committed
Updated First-class Callable Syntax
1 parent e1286f6 commit 7b7bd1b

File tree

6 files changed

+20
-13
lines changed

6 files changed

+20
-13
lines changed

src/DateTime.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ public function __construct($name)
1212
{
1313
parent::__construct(
1414
$name,
15-
\Closure::fromCallable($this->compile(...))->bindTo($this),
16-
\Closure::fromCallable($this->evaluate(...))->bindTo($this)
15+
$this->compile(...)->bindTo($this),
16+
$this->evaluate(...)->bindTo($this)
1717
);
1818
}
1919

20-
private function compile(string $date, string $format, string $timezone = null)
20+
private function compile(string $date, string $format, string $timezone = null): string
2121
{
2222
return <<<"PHP"
2323
\\DateTimeImmutable::createFromFormat({$format}, {$date}, {$timezone} !== null ? new \\DateTimeZone({$timezone}) : null)

src/FileName.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ public function __construct($name)
1212
{
1313
parent::__construct(
1414
$name,
15-
\Closure::fromCallable($this->compile(...))->bindTo($this),
16-
\Closure::fromCallable($this->evaluate(...))->bindTo($this)
15+
$this->compile(...)->bindTo($this),
16+
$this->evaluate(...)->bindTo($this)
1717
);
1818
}
1919

20-
private function compile($file)
20+
private function compile($file): string
2121
{
2222
return <<<COMPILED
2323
(!is_string({$file}) ? null : pathinfo({$file}, PATHINFO_FILENAME))

src/FormatDate.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ public function __construct($name)
1212
{
1313
parent::__construct(
1414
$name,
15-
\Closure::fromCallable($this->compile(...))->bindTo($this),
16-
\Closure::fromCallable($this->evaluate(...))->bindTo($this)
15+
$this->compile(...)->bindTo($this),
16+
$this->evaluate(...)->bindTo($this)
1717
);
1818
}
1919

20-
private function compile(string $dateTime, string $format)
20+
private function compile(string $dateTime, string $format): string
2121
{
2222
return <<<"PHP"
2323
{$dateTime}->format({$format})

src/Now.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ public function __construct($name)
1212
{
1313
parent::__construct(
1414
$name,
15-
\Closure::fromCallable($this->compile(...))->bindTo($this),
16-
\Closure::fromCallable($this->evaluate(...))->bindTo($this)
15+
$this->compile(...)->bindTo($this),
16+
$this->evaluate(...)->bindTo($this)
1717
);
1818
}
1919

20-
private function compile(string $timezone = null)
20+
private function compile(string $timezone = null): string
2121
{
2222
return <<<PHP
2323
(new \\DateTime('now', {$timezone} !== null ? new \\DateTimeZone({$timezone}) : null))

src/TruncateFileName.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public function __construct($name)
1717
);
1818
}
1919

20-
private function compile(string $filename, string $length)
20+
private function compile(string $filename, string $length): string
2121
{
2222
return <<<PHP
2323
(

tests/functional/StringExpressionLanguageProviderTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,11 @@ public function testFormatExpression(): void
1414

1515
$this->assertEquals('SKU_000001', $interpreter->evaluate('format("SKU_%06d", 1)'));
1616
}
17+
18+
public function testExpression(): void
19+
{
20+
$interpreter = new ExpressionLanguage(null, [new StringExpressionLanguageProvider()]);
21+
22+
$this->assertEquals('SKU_000001', $interpreter->evaluate('fileName("SKU_000001")'));
23+
}
1724
}

0 commit comments

Comments
 (0)