Skip to content

Commit

Permalink
Refine date-selection template types + other minor type inference imp…
Browse files Browse the repository at this point in the history
…rovements

Signed-off-by: George Steel <[email protected]>
  • Loading branch information
gsteel committed Apr 1, 2024
1 parent 781ddab commit d5a49e2
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 90 deletions.
76 changes: 4 additions & 72 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<files psalm-version="5.23.1@8471a896ccea3526b26d082f4461eeea467f10a4">
<file src="src/AbstractDateDropdown.php">
<MixedArgumentTypeCoercion>
<code><![CDATA[$value]]></code>
</MixedArgumentTypeCoercion>
<PossiblyUnusedMethod>
<code><![CDATA[setNullOnAllEmpty]]></code>
<code><![CDATA[setNullOnEmpty]]></code>
</PossiblyUnusedMethod>
<RiskyTruthyFalsyComparison>
<code><![CDATA[empty($value)]]></code>
</RiskyTruthyFalsyComparison>
</file>
<file src="src/AbstractFilter.php">
<DocblockTypeContradiction>
Expand Down Expand Up @@ -325,9 +319,6 @@
</PossiblyInvalidArgument>
</file>
<file src="src/DateTimeSelect.php">
<MixedArgumentTypeCoercion>
<code><![CDATA[$value]]></code>
</MixedArgumentTypeCoercion>
<MixedReturnStatement>
<code><![CDATA[$value]]></code>
</MixedReturnStatement>
Expand Down Expand Up @@ -549,32 +540,6 @@
<code><![CDATA[$shareByDefault]]></code>
</PossiblyUnusedProperty>
</file>
<file src="src/FilterPluginManagerFactory.php">
<DeprecatedClass>
<code><![CDATA[new Config($config['filters'])]]></code>
</DeprecatedClass>
<DeprecatedInterface>
<code><![CDATA[FilterPluginManagerFactory]]></code>
</DeprecatedInterface>
<MissingParamType>
<code><![CDATA[$name]]></code>
<code><![CDATA[$name]]></code>
<code><![CDATA[$requestedName]]></code>
</MissingParamType>
<MissingPropertyType>
<code><![CDATA[$creationOptions]]></code>
</MissingPropertyType>
<MixedArgument>
<code><![CDATA[$config['filters']]]></code>
<code><![CDATA[$this->creationOptions]]></code>
</MixedArgument>
<MoreSpecificImplementedParamType>
<code><![CDATA[$options]]></code>
</MoreSpecificImplementedParamType>
<ParamNameMismatch>
<code><![CDATA[$container]]></code>
</ParamNameMismatch>
</file>
<file src="src/FilterProviderInterface.php">
<UnusedClass>
<code><![CDATA[FilterProviderInterface]]></code>
Expand Down Expand Up @@ -872,23 +837,10 @@
</MixedReturnStatement>
</file>
<file src="src/Word/Service/SeparatorToSeparatorFactory.php">
<DeprecatedInterface>
<code><![CDATA[SeparatorToSeparatorFactory]]></code>
</DeprecatedInterface>
<MissingParamType>
<code><![CDATA[$creationOptions]]></code>
</MissingParamType>
<MissingReturnType>
<code><![CDATA[setCreationOptions]]></code>
</MissingReturnType>
<MixedArgument>
<code><![CDATA[$options['replacement_separator'] ?? '-']]></code>
<code><![CDATA[$options['search_separator'] ?? ' ']]></code>
</MixedArgument>
<PossiblyUnusedMethod>
<code><![CDATA[__construct]]></code>
<code><![CDATA[setCreationOptions]]></code>
</PossiblyUnusedMethod>
<UnusedParam>
<code><![CDATA[$container]]></code>
<code><![CDATA[$requestedName]]></code>
</UnusedParam>
</file>
<file src="src/Word/UnderscoreToStudlyCase.php">
<MissingClosureParamType>
Expand Down Expand Up @@ -1108,26 +1060,6 @@
<code><![CDATA[staticUcaseFilter]]></code>
</PossiblyUnusedMethod>
</file>
<file src="test/FilterPluginManagerFactoryTest.php">
<DeprecatedMethod>
<code><![CDATA[getServiceLocator]]></code>
</DeprecatedMethod>
<MissingClosureParamType>
<code><![CDATA[$container]]></code>
<code><![CDATA[$value]]></code>
<code><![CDATA[$value]]></code>
</MissingClosureParamType>
<MissingClosureReturnType>
<code><![CDATA[static fn($value) => $value]]></code>
<code><![CDATA[static fn($value) => $value]]></code>
</MissingClosureReturnType>
<MissingReturnType>
<code><![CDATA[testFactoryConfiguresPluginManagerUnderServiceManagerV2]]></code>
</MissingReturnType>
<UnusedClosureParam>
<code><![CDATA[$container]]></code>
</UnusedClosureParam>
</file>
<file src="test/HtmlEntitiesTest.php">
<PossiblyUnusedMethod>
<code><![CDATA[returnUnfilteredDataProvider]]></code>
Expand Down
15 changes: 8 additions & 7 deletions src/AbstractDateDropdown.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* @psalm-type InputArray = array<string, string>
* @template TOptions of Options
* @template-extends AbstractFilter<TOptions>
* @template TInput of array
* @template TInput of array<array-key, string>
*/
abstract class AbstractDateDropdown extends AbstractFilter
{
Expand Down Expand Up @@ -99,22 +99,23 @@ public function filter(mixed $value): mixed
// Convert the date to a specific format
if (
$this->isNullOnEmpty()
&& array_reduce($value, [self::class, 'reduce'], false)
&& array_reduce($value, self::reduce(...), false)
) {
return null;
}

if (
$this->isNullOnAllEmpty()
&& array_reduce($value, [self::class, 'reduce'], true)
&& array_reduce($value, self::reduce(...), true)
) {
return null;
}

ksort($value);
$this->filterable($value);
assert(is_array($value));

ksort($value);
/** @psalm-var array<array-key, string> $value Forcing the type here because it has already been asserted */

return vsprintf($this->format, $value);
}

Expand All @@ -141,8 +142,8 @@ protected function filterable(array $value): void
/**
* Reduce to a single value
*/
private static function reduce(string $soFar, string|null $value): bool
private static function reduce(bool $soFar, string|null $value): bool
{
return $soFar || empty($value);
return $soFar || ($value === null || $value === '');
}
}
6 changes: 3 additions & 3 deletions src/DateSelect.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
* ...
* }
* @psalm-type InputArray = array{
* year: numeric,
* month: numeric,
* day: numeric,
* year: numeric-string,
* month: numeric-string,
* day: numeric-string,
* }
* @template TOptions of Options
* @template-extends AbstractDateDropdown<TOptions, InputArray>
Expand Down
12 changes: 6 additions & 6 deletions src/DateTimeSelect.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
* ...
* }
* @psalm-type InputArray = array{
* year: numeric,
* month: numeric,
* day: numeric,
* hour: numeric,
* minute: numeric,
* second: numeric
* year: numeric-string,
* month: numeric-string,
* day: numeric-string,
* hour: numeric-string,
* minute: numeric-string,
* second: numeric-string,
* }
* @template TOptions of Options
* @template-extends AbstractDateDropdown<TOptions, InputArray>
Expand Down
4 changes: 2 additions & 2 deletions src/MonthSelect.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
* ...
* }
* @psalm-type InputArray = array{
* year: numeric,
* month: numeric,
* year: numeric-string,
* month: numeric-string,
* }
* @template TOptions of Options
* @template-extends AbstractDateDropdown<TOptions, InputArray>
Expand Down

0 comments on commit d5a49e2

Please sign in to comment.