Skip to content

Commit

Permalink
Allow the renderer argument to be null
Browse files Browse the repository at this point in the history
  • Loading branch information
loevgaard committed May 14, 2024
1 parent e3f5bc6 commit a31b398
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
7 changes: 7 additions & 0 deletions src/Renderer/CompositeRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ final class CompositeRenderer implements RendererInterface
/** @var list<RendererInterface> */
private array $renderers = [];

public function __construct(RendererInterface ...$renderers)
{
foreach ($renderers as $renderer) {

Check warning on line 17 in src/Renderer/CompositeRenderer.php

View workflow job for this annotation

GitHub Actions / Mutation tests (8.3, highest)

Escaped Mutant for Mutator "Foreach_": --- Original +++ New @@ @@ private array $renderers = []; public function __construct(RendererInterface ...$renderers) { - foreach ($renderers as $renderer) { + foreach (array() as $renderer) { $this->add($renderer); } }
$this->add($renderer);

Check warning on line 18 in src/Renderer/CompositeRenderer.php

View check run for this annotation

Codecov / codecov/patch

src/Renderer/CompositeRenderer.php#L18

Added line #L18 was not covered by tests
}
}

public function add(RendererInterface $renderer): void
{
$this->renderers[] = $renderer;
Expand Down
12 changes: 10 additions & 2 deletions src/TagBag.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
use Setono\TagBag\Exception\UnsupportedTagException;
use Setono\TagBag\Generator\FingerprintGeneratorInterface;
use Setono\TagBag\Generator\ValueBasedFingerprintGenerator;
use Setono\TagBag\Renderer\CompositeRenderer;
use Setono\TagBag\Renderer\ContentAwareRenderer;
use Setono\TagBag\Renderer\ElementRenderer;
use Setono\TagBag\Renderer\RendererInterface;
use Setono\TagBag\Storage\StorageInterface;
use Setono\TagBag\Tag\RenderedTag;
Expand All @@ -34,11 +37,16 @@ final class TagBag implements TagBagInterface, LoggerAwareInterface

private ?EventDispatcherInterface $eventDispatcher = null;

private readonly RendererInterface $renderer;

private readonly FingerprintGeneratorInterface $fingerprintGenerator;

public function __construct(private readonly RendererInterface $renderer, FingerprintGeneratorInterface $fingerprintGenerator = null)
{
public function __construct(
RendererInterface $renderer = null,
FingerprintGeneratorInterface $fingerprintGenerator = null,
) {
$this->logger = new NullLogger();
$this->renderer = $renderer ?? new CompositeRenderer(new ElementRenderer(), new ContentAwareRenderer());
$this->fingerprintGenerator = $fingerprintGenerator ?? new ValueBasedFingerprintGenerator();
}

Expand Down

0 comments on commit a31b398

Please sign in to comment.