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

Fix matching for '@array@||@null@' #493

Merged
merged 2 commits into from
Oct 7, 2024
Merged

Conversation

GeLoLabs
Copy link
Contributor

@GeLoLabs GeLoLabs commented Oct 3, 2024

Change Log

Added

Fixed

Changed

Removed

Deprecated

Security


Description

This PR fixes #471 by making aware the "OrMatcher" about the "ArrayMatcher".

new Matcher\ChainMatcher(
'array',
$backtrace,
[
$orMatcher,
new Matcher\OrMatcher($backtrace, $orMatchers = clone $scalarMatchers),
Copy link
Member

Choose a reason for hiding this comment

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

have you tried it without a clone?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Deleting the clone works but I added it here for a specific reason. Since the factory describes the following matcher priorities:

// Matchers are registered in order of matching
// 1) all scalars
// 2) json/xml
// 3) array
// 4) or "||"
// 5) full text

I have decided to clone the scalair matchers in order to keep theses priorities on the main matcher.

Copy link
Member

Choose a reason for hiding this comment

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

and without clone that order is changed?

@norberttech
Copy link
Member

in order to fix that static analysis error run composer cs:php:fix

Copy link
Member

@norberttech norberttech left a comment

Choose a reason for hiding this comment

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

So here are two things that need to be clarified/added before this can be merged:

  1. I would love to understand why that cloning is necessary and what are the consequences of not using clone
  2. There needs to be some tests added that would fail before this fix is implemented

@GeLoLabs
Copy link
Contributor Author

GeLoLabs commented Oct 6, 2024

@norberttech I have added a test covering this fix.

For the cloning part, I keep BC strictly according to the documented matcher priorites, if you prefer, I can drop it but the, I would also drop the registering of the original array matcher on the main matcher chain since it would become part of the scalar matcher chain.

By the way, if I don't clone it, the test becomes broken.

@norberttech norberttech merged commit c2303ed into coduo:6.x Oct 7, 2024
12 checks passed
@norberttech
Copy link
Member

By the way, if I don't clone it, the test becomes broken.

This is what I wanted to know, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Not able to match @null@||@array@ (again)
2 participants