Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lazy collorize method name #5728

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 14 additions & 10 deletions src/Event/Value/Test/TestDox.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,21 @@
*
* @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit
*/
final readonly class TestDox
final class TestDox
{
private string $prettifiedClassName;
private string $prettifiedMethodName;
private string $prettifiedAndColorizedMethodName;
private readonly string $prettifiedClassName;

public function __construct(string $prettifiedClassName, string $prettifiedMethodName, string $prettifiedAndColorizedMethodName)
/** @var callable */
private $prettifiedMethodNameCallable;

/** @var callable */
private $prettifiedAndColorizedMethodNameCallable;

public function __construct(string $prettifiedClassName, callable $prettifiedMethodNameCallable, callable $prettifiedAndColorizedMethodNameCallable)
{
$this->prettifiedClassName = $prettifiedClassName;
$this->prettifiedMethodName = $prettifiedMethodName;
$this->prettifiedAndColorizedMethodName = $prettifiedAndColorizedMethodName;
$this->prettifiedClassName = $prettifiedClassName;
$this->prettifiedMethodNameCallable = $prettifiedMethodNameCallable;
$this->prettifiedAndColorizedMethodNameCallable = $prettifiedAndColorizedMethodNameCallable;
}

public function prettifiedClassName(): string
Expand All @@ -35,9 +39,9 @@
public function prettifiedMethodName(bool $colorize = false): string
{
if ($colorize) {
return $this->prettifiedAndColorizedMethodName;
return ($this->prettifiedAndColorizedMethodNameCallable)();

Check failure on line 42 in src/Event/Value/Test/TestDox.php

View workflow job for this annotation

GitHub Actions / Type Checker

ImpureFunctionCall

src/Event/Value/Test/TestDox.php:42:20: ImpureFunctionCall: Cannot call an impure function from a mutation-free context (see https://psalm.dev/202)

Check failure on line 42 in src/Event/Value/Test/TestDox.php

View workflow job for this annotation

GitHub Actions / Type Checker

ImpureFunctionCall

src/Event/Value/Test/TestDox.php:42:21: ImpureFunctionCall: Cannot call an impure function from a mutation-free context (see https://psalm.dev/202)
}

return $this->prettifiedMethodName;
return ($this->prettifiedMethodNameCallable)();

Check failure on line 45 in src/Event/Value/Test/TestDox.php

View workflow job for this annotation

GitHub Actions / Type Checker

ImpureFunctionCall

src/Event/Value/Test/TestDox.php:45:16: ImpureFunctionCall: Cannot call an impure function from a mutation-free context (see https://psalm.dev/202)

Check failure on line 45 in src/Event/Value/Test/TestDox.php

View workflow job for this annotation

GitHub Actions / Type Checker

ImpureFunctionCall

src/Event/Value/Test/TestDox.php:45:17: ImpureFunctionCall: Cannot call an impure function from a mutation-free context (see https://psalm.dev/202)
}
}
8 changes: 4 additions & 4 deletions src/Event/Value/Test/TestDoxBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ public static function fromTestCase(TestCase $testCase): TestDox

return new TestDox(
$prettifier->prettifyTestClassName($testCase::class),
$prettifier->prettifyTestCase($testCase, false),
$prettifier->prettifyTestCase($testCase, true),
static fn () => $prettifier->prettifyTestCase($testCase, false),
static fn () => $prettifier->prettifyTestCase($testCase, true),
);
}

Expand All @@ -40,8 +40,8 @@ public static function fromClassNameAndMethodName(string $className, string $met

return new TestDox(
$prettifier->prettifyTestClassName($className),
$prettifiedMethodName,
$prettifiedMethodName,
static fn () => $prettifiedMethodName,
static fn () => $prettifiedMethodName,
);
}
}
Loading