Skip to content

Commit

Permalink
Merge pull request #21 from Setono/nullable-renderer
Browse files Browse the repository at this point in the history
Allow the renderer argument to be null
  • Loading branch information
loevgaard authored May 14, 2024
2 parents e3f5bc6 + a31b398 commit 5a30419
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);
}
}

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 5a30419

Please sign in to comment.