Skip to content
Merged
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
7 changes: 2 additions & 5 deletions src/Parser/HTMLParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,13 @@ public function grabAttributeFrom(string $xpath, string|array $attributes)
return $this->getArgumentsFromNode($nodes->getNode(0), $attributes);
}

/**
* @param string|array<string>|null $attribute
*/
public function grabMultiple(string $xpath, $attribute = null): array
public function grabMultiple(string $xpath, string|array|null $attribute = null): array
{
$result = [];
$nodes = $this->crawler->filterXPath($xpath);

foreach ($nodes as $node) {
$result[] = $attribute !== null ? $this->getArgumentsFromNode($node, $attribute) : $node->textContent;
$result[] = $attribute !== null ? $this->getArgumentsFromNode($node, $attribute) : $node->textContent; // @phpstan-ignore argument.templateType
}

return $result;
Expand Down
10 changes: 8 additions & 2 deletions src/SnapshotFormatters/SimpleSerializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ public function toArray(SEOData $data): array

protected function formatTagCollection(TagCollection $collection): ?array
{
$tags = $collection->toArray();

if ($tags === []) {
return null;
}

return array_map(
function ($item) {
if (is_array($item)) {
Expand All @@ -44,8 +50,8 @@ function ($item) {

return $this->formatIfUrl($item);
},
$collection->toArray(),
) ?: null;
$tags,
);
}

protected function formatIfUrl(?string $url): ?string
Expand Down
4 changes: 4 additions & 0 deletions src/Support/ArrayPluck.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ public function __invoke(string $key, string $value): array
$results = [];

foreach ($array as $item) {
if (! isset($item[$key], $item[$value])) {
continue;
}

$itemValue = $item[$value];
$itemKey = $item[$key];

Expand Down
8 changes: 6 additions & 2 deletions src/TestSEO.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,9 @@ public function assertTitleIs(string $expected): self

public function assertTitleContains(string $expected): self
{
Assert::assertStringContainsString($expected, $this->data->title());
$title = $this->data->title();
Assert::assertNotNull($title, 'Title tag is missing.');
Assert::assertStringContainsString($expected, $title);

return $this;
}
Expand All @@ -92,7 +94,9 @@ public function assertTitleContains(string $expected): self
*/
public function assertTitleEndsWith(string $expected): self
{
Assert::assertStringEndsWith($expected, $this->data->title());
$title = $this->data->title();
Assert::assertNotNull($title, 'Title tag is missing.');
Assert::assertStringEndsWith($expected, $title);

return $this;
}
Expand Down