Skip to content

feat(Utils): Add validation to GetConfigurationValue#70

Open
Hipska wants to merge 4 commits intoCombodo:masterfrom
Super-Visions:feature/utils/configurationvalue_validation
Open

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

Conversation

@Hipska
Copy link
Collaborator

@Hipska Hipska commented Mar 6, 2026

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

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

Labels

None yet

Projects

Status: First review needed

Development

Successfully merging this pull request may close these issues.

2 participants