Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Validate checkedExceptionClasses config #3987

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

Open
janedbal wants to merge 4 commits into phpstan:2.1.x
base: 2.1.x
Choose a base branch
Loading
from janedbal:checked-exceptions-validate-config

Conversation

@janedbal
Copy link
Contributor

@janedbal janedbal commented May 12, 2025

No description provided.

{
foreach ($this->checkedExceptionClasses as $checkedExceptionClass) {
if (!$this->reflectionProvider->hasClass($checkedExceptionClass)) {
throw new ShouldNotHappenException('Class ' . $checkedExceptionClass . ' used in \'checkedExceptionClasses\' does not exist.');
Copy link
Contributor Author

@janedbal janedbal May 12, 2025
edited
Loading

Choose a reason for hiding this comment

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

Not sure if this is the preferred way of config validation.

if (!$this->reflectionProvider->hasClass($uncheckedExceptionClass)) {
throw new ShouldNotHappenException('Class ' . $uncheckedExceptionClass . ' used in \'uncheckedExceptionClasses\' does not exist.');
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you want that behind featureFlag / bleedingEdge? I think this will be pretty rare.

- Moved validation from DefaultExceptionTypeResolver constructor to ContainerFactory::validateParameters()
- Added bleeding edge feature flag protection to avoid BC break
- Use InvalidConfigurationException for proper error handling
- Note: The required placement in validateParameters() complicates the code as we cannot use BleedingEdgeToggle::isBleedingEdge() since it's not initialized yet, requiring manual parameter checking
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
Copy link
Member

@ondrejmirtes ondrejmirtes left a comment

Choose a reason for hiding this comment

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

And fix the conflicts please 😊

}

if (array_key_exists('featureToggles', $parameters) && is_array($parameters['featureToggles']) && (bool) $parameters['featureToggles']['bleedingEdge']) {
$this->validateExceptionClasses($parameters);
Copy link
Member

@ondrejmirtes ondrejmirtes Aug 30, 2025

Choose a reason for hiding this comment

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

You can put these conditions right next to:

		$container = $configurator->createContainer()->getByType(Container::class);
		$this->validateParameters($container->getParameters(), $projectConfig['parametersSchema']);

And pass ReflectionProvider properly from $container instead of obtaining it statically.

Copy link
Member

@ondrejmirtes ondrejmirtes Aug 30, 2025

Choose a reason for hiding this comment

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

Meaning do not call validateExceptionClasses from inside validateParameters, but instead from create.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@ondrejmirtes ondrejmirtes ondrejmirtes requested changes

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /