Skip to content

Commit

Permalink
fix: load all link load options not just selector
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanorosanelli committed Nov 26, 2024
1 parent ffdea16 commit eb206b6
Showing 1 changed file with 29 additions and 4 deletions.
33 changes: 29 additions & 4 deletions src/Command/ImportSitemapCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,18 +177,43 @@ public function execute(Arguments $args, ConsoleIo $io)
* @return array
*/
protected function linkOptions(string $url, array $linkLoadOptions): array
{
$keys = [];
foreach ($linkLoadOptions as $item) {
unset($item['url']);
$keys = array_merge($keys, array_keys($item));
}
$keys = array_unique($keys);

$options = [];
foreach ($keys as $key) {
$options[$key] = $this->linkLoadOption($url, $key, $linkLoadOptions);
}

return $options;
}

/**
* Return option value of $name property
*
* @param string $url The URL
* @param string $name Prop name
* @param array $linkLoadOptions Link load options
* @return string
*/
protected function linkLoadOption(string $url, string $name, array $linkLoadOptions): string
{
$options = array_filter($linkLoadOptions, function ($o) use ($url) {
return $o['url'] === $url;
});
$selector = Hash::get($options, '0.selector');
if (!empty($selector)) {
return compact('selector');
$value = Hash::get($options, sprintf('0.%s', $name));
if (!empty($value)) {
return [$name => $value];

Check failure on line 211 in src/Command/ImportSitemapCommand.php

View workflow job for this annotation

GitHub Actions / stan / Static code analyzer (8.1)

Method Brevia\BEdita\Command\ImportSitemapCommand::linkLoadOption() should return string but returns array<string, mixed>.

Check failure on line 211 in src/Command/ImportSitemapCommand.php

View workflow job for this annotation

GitHub Actions / stan / Static code analyzer (8.2)

Method Brevia\BEdita\Command\ImportSitemapCommand::linkLoadOption() should return string but returns array<string, mixed>.

Check failure on line 211 in src/Command/ImportSitemapCommand.php

View workflow job for this annotation

GitHub Actions / stan / Static code analyzer (8.1)

Method Brevia\BEdita\Command\ImportSitemapCommand::linkLoadOption() should return string but returns array<string, mixed>.

Check failure on line 211 in src/Command/ImportSitemapCommand.php

View workflow job for this annotation

GitHub Actions / stan / Static code analyzer (8.2)

Method Brevia\BEdita\Command\ImportSitemapCommand::linkLoadOption() should return string but returns array<string, mixed>.
}
$options = array_filter($linkLoadOptions, function ($o) use ($url) {
return strpos($url, $o['url']) === 0;
});

return ['selector' => Hash::get($options, '0.selector')];
return (string)Hash::get($options, sprintf('0.%s', $name));
}
}

0 comments on commit eb206b6

Please sign in to comment.