Skip to content

Commit

Permalink
Remove inheritance chain from DashToSeparator
Browse files Browse the repository at this point in the history
Signed-off-by: ramchale <[email protected]>
  • Loading branch information
ramchale committed Oct 23, 2024
1 parent beb5aee commit 52e9f2d
Showing 1 changed file with 48 additions and 6 deletions.
54 changes: 48 additions & 6 deletions src/Word/DashToSeparator.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@

namespace Laminas\Filter\Word;

use Closure;
use Laminas\Filter\FilterInterface;

use function array_map;
use function is_array;
use function is_scalar;
use function str_replace;

/**
Expand All @@ -14,15 +17,42 @@
* ...
* }
* @template TOptions of Options
* @extends AbstractSeparator<TOptions>
* @implements FilterInterface<mixed>
*/
final class DashToSeparator extends AbstractSeparator
final class DashToSeparator implements FilterInterface
{
protected string $separator = ' ';

/**
* @param Options|string $separator Space by default
*/
public function __construct(string|array $separator = ' ')
{
if (is_array($separator) && isset($separator['separator'])) {
$this->setSeparator($separator['separator']);

return;
}

$this->setSeparator($separator);

Check failure on line 37 in src/Word/DashToSeparator.php

View workflow job for this annotation

GitHub Actions / ci / QA Checks (Psalm [8.1, locked], ubuntu-latest, laminas/laminas-continuous-integration-action@v1, ...

PossiblyInvalidCast

src/Word/DashToSeparator.php:37:29: PossiblyInvalidCast: array{separator?: string, ...<array-key, mixed>} cannot be cast to string (see https://psalm.dev/190)

Check failure on line 37 in src/Word/DashToSeparator.php

View workflow job for this annotation

GitHub Actions / ci / QA Checks (Psalm [8.1, locked], ubuntu-latest, laminas/laminas-continuous-integration-action@v1, ...

PossiblyInvalidArgument

src/Word/DashToSeparator.php:37:29: PossiblyInvalidArgument: Argument 1 of Laminas\Filter\Word\DashToSeparator::setSeparator expects string, but possibly different type array{separator?: string, ...<array-key, mixed>}|string provided (see https://psalm.dev/092)
}

public function __invoke(mixed $value): mixed
{
return $this->filter($value);
}

public function filter(mixed $value): mixed
{
return self::applyFilterOnlyToStringableValuesAndStringableArrayValues(
$value,
Closure::fromCallable([$this, 'filterNormalizedValue'])
if (! is_array($value)) {
if (! is_scalar($value)) {
return $value;
}
return $this->filterNormalizedValue((string) $value);
}

return $this->filterNormalizedValue(
array_map(static fn($item) => is_scalar($item) ? (string) $item : $item, $value)

Check failure on line 55 in src/Word/DashToSeparator.php

View workflow job for this annotation

GitHub Actions / ci / QA Checks (Psalm [8.1, locked], ubuntu-latest, laminas/laminas-continuous-integration-action@v1, ...

MixedArgumentTypeCoercion

src/Word/DashToSeparator.php:55:13: MixedArgumentTypeCoercion: Argument 1 of Laminas\Filter\Word\DashToSeparator::filterNormalizedValue expects array<array-key, string>|string, but parent type array<array-key, mixed|string> provided (see https://psalm.dev/194)
);
}

Expand All @@ -34,4 +64,16 @@ private function filterNormalizedValue($value)
{
return str_replace('-', $this->separator, $value);
}

/** @return $this */
public function setSeparator(string $separator): self
{
$this->separator = $separator;
return $this;
}

public function getSeparator(): string

Check failure on line 75 in src/Word/DashToSeparator.php

View workflow job for this annotation

GitHub Actions / ci / QA Checks (Psalm [8.1, locked], ubuntu-latest, laminas/laminas-continuous-integration-action@v1, ...

PossiblyUnusedMethod

src/Word/DashToSeparator.php:75:21: PossiblyUnusedMethod: Cannot find any calls to method Laminas\Filter\Word\DashToSeparator::getSeparator (see https://psalm.dev/087)
{
return $this->separator;
}
}

0 comments on commit 52e9f2d

Please sign in to comment.