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 Dir filter to implement FlterInterface #216

Merged
merged 1 commit into from
Jan 8, 2025

Conversation

marcelthole
Copy link

Q A
Documentation yes
Bugfix no
BC Break yes
New Feature no
RFC yes
QA no

Description

Move Dir filter also to the implementation via FilterInterface and removed the AbstractFilter

@froschdesign froschdesign added this to the 3.0.0 milestone Jan 3, 2025
@gsteel gsteel mentioned this pull request Jan 6, 2025
54 tasks
@gsteel gsteel self-assigned this Jan 6, 2025
Copy link
Member

@gsteel gsteel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry @marcelthole - reviewed a couple of days ago and never submitted it 🤦‍♂️

{
/**
* Defined by Laminas\Filter\FilterInterface
*
* Returns dirname($value)
*
* @psalm-return ($value is scalar ? string : mixed)
*/
public function filter(mixed $value): mixed
{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you change this conditional to if (! is_string($value) && ! is_numeric($value)) and amend the tests to suit please?

I can nearly see a use case for numeric directory names, but casting bool to string and finding the parent directory? Just weird.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As this is a refactor, test clean up would be appreciated too:

  • Change loops to data providers and include more cases
  • Ensure __invoke is covered

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated the testcase.
For the numeric value i made this filter more strict and only allow strings because i guess that the behavior with numeric values is a little bit strange. https://3v4l.org/5rHL2

i didn't expect to get the value "." as string if i pass 1 as integer value to the filter. If i really want to use that filter for the value i should cast it to a string on my side

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, dirname will return '.' for anything in getcwd, any non-string input and any non-existent directory/file. It's only remotely useful if it receives something that looks like a fully qualified path, existing on disk or not.

As it stands, the Dir filter is not really useful at all as far as I can tell.

Copy link
Member

@gsteel gsteel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @marcelthole :)

self::assertSame($expected, $filter->filter($input));
}

public static function defaultSettingsDataProvider(): array
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For future reference, please annotate data providers with a precise return types:

Suggested change
public static function defaultSettingsDataProvider(): array
/** @return list<array{0: string, 1: string}> */
public static function defaultSettingsDataProvider(): array

This helps document intent, especially when new items are added or when a larger number of arguments are required.

@gsteel gsteel merged commit 736f67a into laminas:3.0.x Jan 8, 2025
16 of 17 checks passed
@marcelthole marcelthole deleted the refactor-dir-filter branch January 8, 2025 18:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants