Skip to content

Commit

Permalink
Lazy collorize method name
Browse files Browse the repository at this point in the history
  • Loading branch information
staabm committed Mar 9, 2024
1 parent 0bddfd3 commit 02beb92
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
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 prettifiedClassName(): string
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,
);
}
}

0 comments on commit 02beb92

Please sign in to comment.