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

[Transform] Check str_contains * before fnmatch() early on AddAllowDynamicPropertiesAttributeRector #4991

Merged
merged 2 commits into from
Sep 11, 2023
Merged
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -139,16 +139,18 @@ private function addAllowDynamicPropertiesAttribute(Class_ $class): Class_

private function shouldSkip(Class_ $class): bool
{
if ($this->transformOnNamespaces !== []) {
$className = (string) $this->nodeNameResolver->getName($class);
foreach ($this->transformOnNamespaces as $transformOnNamespace) {
if ($this->nodeNameResolver->isStringName($className, $transformOnNamespace)) {
continue;
}

$className = (string) $this->nodeNameResolver->getName($class);
foreach ($this->transformOnNamespaces as $transformOnNamespace) {
if (str_contains($transformOnNamespace, '*')) {
if (! fnmatch($transformOnNamespace, $className, FNM_NOESCAPE)) {
return true;
Comment on lines +144 to 146
Copy link
Member Author

Choose a reason for hiding this comment

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

@TomasVotruba @staabm this conditions seems need to be on last resort to check because it returns true on negation early, I will create separate PR to cover too late check.

}

continue;
}

if ($this->nodeNameResolver->isStringName($className, $transformOnNamespace)) {
continue;
Copy link
Contributor

Choose a reason for hiding this comment

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

this needs to be return true ?

Copy link
Contributor

Choose a reason for hiding this comment

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

hmm actually I am not sure. is this area covered by tests?

Copy link
Member Author

Choose a reason for hiding this comment

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

I am going to add new fixture to cover this

Copy link
Member Author

Choose a reason for hiding this comment

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

it's not, it need to be processed as exists

}
}

Expand Down