Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor Inflector Filter #220

Merged
merged 3 commits into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from 2 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
402 changes: 162 additions & 240 deletions docs/book/v3/inflector.md

Large diffs are not rendered by default.

30 changes: 30 additions & 0 deletions docs/book/v3/migration/v2-to-v3.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,36 @@ The following methods have been removed:

The constructor now only accepts an associative array of [documented options](../standard-filters.md#denylist).

#### `Inflector`

The following methods have been removed:

- `getPluginManager`
- `setPluginManager`
- `setOptions`
- `setThrowTargetExceptionsOn`
- `isThrowTargetExceptionsOn`
- `setTargetReplacementIdentifier`
- `getTargetReplacementIdentifier`
- `setTarget`
- `getTarget`
- `setTargetReference`
- `setRules`
- `addRules`
- `getRules`
- `getRule`
- `clearRules`
- `setFilterRule`
- `addFilterRule`
- `setStaticRule`
- `setStaticRuleReference`

The constructor now only accepts an associative array of [documented options](../inflector.md) and requires a `FilterPluginManager` instance as its first argument.

The ability to pass in references to be used as the inflection target, or as a static rule is no longer possible.

It is now possible to use an object as the filter input.

#### `MonthSelect`

The following methods have been removed:
Expand Down
144 changes: 0 additions & 144 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -218,99 +218,6 @@
<code><![CDATA[(string) $value]]></code>
</RedundantCastGivenDocblockType>
</file>
<file src="src/Inflector.php">
<ArgumentTypeCoercion>
<code><![CDATA[$options['pluginManager']]]></code>
</ArgumentTypeCoercion>
<DeprecatedClass>
<code><![CDATA[AbstractFilter]]></code>
</DeprecatedClass>
<InvalidArgument>
<code><![CDATA[array_values($processedParts)]]></code>
</InvalidArgument>
<InvalidArrayAccess>
<code><![CDATA[$spec[0]]]></code>
</InvalidArrayAccess>
<InvalidArrayOffset>
<code><![CDATA[$value[ltrim($sourceName, ':')]]]></code>
</InvalidArrayOffset>
<MixedArgument>
<code><![CDATA[$options['pluginManager']]]></code>
<code><![CDATA[$options['rules']]]></code>
<code><![CDATA[$options['target']]]></code>
<code><![CDATA[$options['targetReplacementIdentifier']]]></code>
<code><![CDATA[$options['throwTargetExceptionsOn']]]></code>
<code><![CDATA[$processedPart]]></code>
<code><![CDATA[$rule]]></code>
<code><![CDATA[$rules[$spec]]]></code>
<code><![CDATA[$spec]]></code>
<code><![CDATA[$value[$ruleName]]]></code>
</MixedArgument>
<MixedArgumentTypeCoercion>
<code><![CDATA[$sourceName]]></code>
<code><![CDATA[$spec]]></code>
</MixedArgumentTypeCoercion>
<MixedArrayAssignment>
<code><![CDATA[$this->rules[$spec][]]]></code>
</MixedArrayAssignment>
<MixedAssignment>
<code><![CDATA[$processedPart]]></code>
<code><![CDATA[$processedPart]]></code>
<code><![CDATA[$rule]]></code>
<code><![CDATA[$ruleFilter]]></code>
<code><![CDATA[$ruleValue]]></code>
<code><![CDATA[$sourceValue]]></code>
<code><![CDATA[$temp['rules']]]></code>
<code><![CDATA[$temp['target']]]></code>
<code><![CDATA[$temp['targetReplacementIdentifier']]]></code>
<code><![CDATA[$temp['throwTargetExceptionsOn']]]></code>
<code><![CDATA[$value[ltrim($sourceName, ':')]]]></code>
</MixedAssignment>
<MixedFunctionCall>
<code><![CDATA[$ruleFilter($processedPart)]]></code>
</MixedFunctionCall>
<MixedInferredReturnType>
<code><![CDATA[FilterInterface|callable(mixed): mixed]]></code>
<code><![CDATA[FilterInterface|false]]></code>
<code><![CDATA[array|false]]></code>
</MixedInferredReturnType>
<MixedMethodCall>
<code><![CDATA[new $options['pluginManager']()]]></code>
</MixedMethodCall>
<MixedReturnStatement>
<code><![CDATA[$this->getPluginManager()->get($rule)]]></code>
<code><![CDATA[$this->getPluginManager()->get($rule)]]></code>
<code><![CDATA[$this->rules[$spec]]]></code>
<code><![CDATA[$this->rules[$spec][$index]]]></code>
</MixedReturnStatement>
<MixedStringOffsetAssignment>
<code><![CDATA[$value[ltrim($sourceName, ':')]]]></code>
</MixedStringOffsetAssignment>
<MoreSpecificImplementedParamType>
<code><![CDATA[$value]]></code>
</MoreSpecificImplementedParamType>
<PossiblyUnusedReturnValue>
<code><![CDATA[self]]></code>
</PossiblyUnusedReturnValue>
<PropertyNotSetInConstructor>
<code><![CDATA[$pluginManager]]></code>
<code><![CDATA[$target]]></code>
</PropertyNotSetInConstructor>
<RedundantCast>
<code><![CDATA[(string) $targetReplacementIdentifier]]></code>
</RedundantCast>
<RedundantCastGivenDocblockType>
<code><![CDATA[(bool) $throwTargetExceptionsOn]]></code>
<code><![CDATA[(string) $rule]]></code>
<code><![CDATA[(string) $spec]]></code>
<code><![CDATA[(string) $target]]></code>
<code><![CDATA[(string) $value]]></code>
</RedundantCastGivenDocblockType>
<UnusedParam>
<code><![CDATA[$reference]]></code>
<code><![CDATA[$target]]></code>
</UnusedParam>
</file>
<file src="src/Module.php">
<UnusedClass>
<code><![CDATA[Module]]></code>
Expand Down Expand Up @@ -393,55 +300,4 @@
<code><![CDATA[setQuoteStyle]]></code>
</DeprecatedMethod>
</file>
<file src="test/InflectorTest.php">
<DocblockTypeContradiction>
<code><![CDATA[assertNull]]></code>
<code><![CDATA[assertSame]]></code>
</DocblockTypeContradiction>
<InvalidCast>
<code><![CDATA[$rule]]></code>
<code><![CDATA[$rule]]></code>
</InvalidCast>
<MissingParamType>
<code><![CDATA[$inflector]]></code>
</MissingParamType>
<MissingReturnType>
<code><![CDATA[_testOptions]]></code>
</MissingReturnType>
<MixedArgument>
<code><![CDATA[$options['rules'][':action']]]></code>
<code><![CDATA[$options['rules'][':controller']]]></code>
<code><![CDATA[$rules['controller']]]></code>
<code><![CDATA[$rules['controller']]]></code>
</MixedArgument>
<MixedArgumentTypeCoercion>
<code><![CDATA[$rule]]></code>
<code><![CDATA[$rule]]></code>
</MixedArgumentTypeCoercion>
<MixedAssignment>
<code><![CDATA[$filtered]]></code>
<code><![CDATA[$filtered]]></code>
<code><![CDATA[$filtered]]></code>
<code><![CDATA[$rules]]></code>
</MixedAssignment>
<MixedMethodCall>
<code><![CDATA[getPluginManager]]></code>
<code><![CDATA[getRules]]></code>
<code><![CDATA[getTarget]]></code>
<code><![CDATA[getTargetReplacementIdentifier]]></code>
<code><![CDATA[isThrowTargetExceptionsOn]]></code>
</MixedMethodCall>
<MixedOperand>
<code><![CDATA[$rule]]></code>
</MixedOperand>
<PossiblyFalseArgument>
<code><![CDATA[$rules]]></code>
<code><![CDATA[$rules]]></code>
</PossiblyFalseArgument>
<UnusedVariable>
<code><![CDATA[$filtered]]></code>
<code><![CDATA[$rule]]></code>
<code><![CDATA[$target]]></code>
</UnusedVariable>
</file>
</files>
2 changes: 1 addition & 1 deletion src/FilterPluginManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ final class FilterPluginManager extends AbstractPluginManager
ForceUriScheme::class => InvokableFactory::class,
HtmlEntities::class => InvokableFactory::class,
ImmutableFilterChain::class => ImmutableFilterChainFactory::class,
Inflector::class => InvokableFactory::class,
Inflector::class => InflectorFactory::class,
ToFloat::class => InvokableFactory::class,
MonthSelect::class => InvokableFactory::class,
UpperCaseWords::class => InvokableFactory::class,
Expand Down
Loading
Loading