Skip to content

N°9661 - feat(Utils): Add validation to GetConfigurationValue - #70

Draft
Hipska wants to merge 4 commits into
Combodo:masterfrom
Super-Visions:feature/utils/configurationvalue_validation
Draft

N°9661 - feat(Utils): Add validation to GetConfigurationValue#70
Hipska wants to merge 4 commits into
Combodo:masterfrom
Super-Visions:feature/utils/configurationvalue_validation

Conversation

@Hipska

@Hipska Hipska commented Mar 6, 2026

Copy link
Copy Markdown
Collaborator

Base information

Question Answer
Related to a SourceForge thread / Another PR / Combodo ticket? N/A
Type of change? Enhancement

Objective

When retrieving settings, you sometimes need to additional type checking validation. The objective is to reduce this as much as possible.

Before:

$sStopOnError = Utils::GetConfigurationValue('stop_on_synchro_error', 'no');
if (($sStopOnError != 'yes') && ($sStopOnError != 'no')) {
	Utils::Log(LOG_WARNING, "Unexpected value '$sStopOnError' for the parameter 'stop_on_synchro_error'. Will NOT stop on error. The expected values for this parameter are 'yes' or 'no'.");
}
$bStopOnError = ($sStopOnError == 'yes');

After:

$bStopOnError = Utils::GetConfigurationValue('stop_on_synchro_error', 'no', FILTER_VALIDATE_BOOLEAN);

Proposed solution

Use php's integrated functionality to filter/validate variables by adding an optional filter flag to the GetConfigurationValue method. Current behaviour is not altered.

Checklist before requesting a review

  • I have performed a self-review of my code, and that it's compliant with Combodo's guidelines
  • I have tested all changes I made on an iTop instance
  • I have added a unit test, otherwise I have explained why I couldn't
  • I have made sure the PR is clear and detailled enough so anyone can understand the real purpose without digging in the code

@github-project-automation github-project-automation Bot moved this to First review needed in Combodo PRs dashboard Mar 6, 2026
@jf-cbd jf-cbd moved this from First review needed to Pending review in Combodo PRs dashboard Apr 13, 2026
@jf-cbd

jf-cbd commented Jun 5, 2026

Copy link
Copy Markdown
Member

Hey @Hipska, thanks for this PR and its associated tests :) in case of invalid value, it doesn't seem to be error thrown (or logs), is it on purpose ?

@Hipska

Hipska commented Jun 5, 2026

Copy link
Copy Markdown
Collaborator Author

No, it returns the default value or null if default is left out or invalid.

Do you want it to log something when this happens? (didn't seem necessary to me)

@jf-cbd

jf-cbd commented Jun 5, 2026

Copy link
Copy Markdown
Member

Thank you for your answer. If a user set a filter, he'll probably expect that an error is thrown in case of invalid value - rather than making a fallback on default value (not only a silent log) - and a log would also be appreciated.

@Hipska

Hipska commented Jun 5, 2026

Copy link
Copy Markdown
Collaborator Author

Okay, so throw exception on invalid value and only return default if no value set?

@jf-cbd jf-cbd changed the title feat(Utils): Add validation to GetConfigurationValue N°9661 - feat(Utils): Add validation to GetConfigurationValue Jun 5, 2026
@jf-cbd

jf-cbd commented Jun 5, 2026

Copy link
Copy Markdown
Member

Yep that's it (exception + log in case of invalid value) :)

@Hipska
Hipska marked this pull request as draft July 22, 2026 14:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Pending review

Development

Successfully merging this pull request may close these issues.

3 participants