Skip to content
Open
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion src/Umbraco.Core/PropertyEditors/ConfigurationEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public virtual IEnumerable<ValidationResult> Validate(IDictionary<string, object
=> Fields
.SelectMany(field =>
configuration.TryGetValue(field.Key, out var value)
? field.Validators.SelectMany(validator => validator.Validate(value, null, null, PropertyValidationContext.Empty()))
? field.Validators.SelectMany(validator => validator.Validate(value, null, null, PropertyValidationContext.Empty(), field))
: Enumerable.Empty<ValidationResult>())
.ToArray();

Expand Down
18 changes: 18 additions & 0 deletions src/Umbraco.Core/PropertyEditors/IValueValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,22 @@
/// </para>
/// </remarks>
IEnumerable<ValidationResult> Validate(object? value, string? valueType, object? dataTypeConfiguration, PropertyValidationContext validationContext);

/// <summary>
/// Validates a value.
/// </summary>
/// <param name="value">The value to validate.</param>
/// <param name="valueType">The value type.</param>
/// <param name="dataTypeConfiguration">A datatype configuration.</param>
/// <param name="validationContext">The context in which the value is being validated.</param>
/// <param name="configurationField">The configuration field being validated.</param>
/// <returns>Validation results.</returns>
/// <remarks>
/// <para>
/// The value can be a string, a Json structure (JObject, JArray...)... corresponding to what was posted by an
/// editor.
/// </para>
/// </remarks>
IEnumerable<ValidationResult> Validate(object? value, string? valueType, object? dataTypeConfiguration, PropertyValidationContext validationContext, ConfigurationField configurationField)
=> throw new NotImplementedException();

Check warning on line 43 in src/Umbraco.Core/PropertyEditors/IValueValidator.cs

View check run for this annotation

CodeScene Delta Analysis / CodeScene Code Health Review (main)

❌ New issue: Excess Number of Function Arguments

Validate has 5 arguments, max arguments = 4. This function has too many arguments, indicating a lack of encapsulation. Avoid adding more arguments.
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,17 @@
protected BlockEditorMinMaxValidatorBase(ILocalizedTextService textService) => TextService = textService;

/// <summary>
/// Gets the <see cref="ILocalizedTextService"/>
/// Gets the <see cref="ILocalizedTextService"/>.
/// </summary>
protected ILocalizedTextService TextService { get; }

/// <inheritdoc/>
public abstract IEnumerable<ValidationResult> Validate(object? value, string? valueType, object? dataTypeConfiguration, PropertyValidationContext validationContext);

/// <inheritdoc/>
public virtual IEnumerable<ValidationResult> Validate(object? value, string? valueType, object? dataTypeConfiguration, PropertyValidationContext validationContext, ConfigurationField configurationField)
=> throw new NotImplementedException();

Check warning on line 34 in src/Umbraco.Infrastructure/PropertyEditors/BlockEditorMinMaxValidatorBase.cs

View check run for this annotation

CodeScene Delta Analysis / CodeScene Code Health Review (main)

❌ New issue: Excess Number of Function Arguments

Validate has 5 arguments, max arguments = 4. This function has too many arguments, indicating a lack of encapsulation. Avoid adding more arguments.

/// <summary>
/// Validates the number of blocks are within the configured minimum and maximum values.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,22 @@
public ColorListValidator(IConfigurationEditorJsonSerializer configurationEditorJsonSerializer)
=> _configurationEditorJsonSerializer = configurationEditorJsonSerializer;

public IEnumerable<ValidationResult> Validate(object? value, string? valueType, object? dataTypeConfiguration, PropertyValidationContext validationContext)
public IEnumerable<ValidationResult> Validate(
object? value,
string? valueType,
object? dataTypeConfiguration,
PropertyValidationContext validationContext)
=> ValidateInternal(value, "items");

public IEnumerable<ValidationResult> Validate(
object? value,
string? valueType,
object? dataTypeConfiguration,
PropertyValidationContext validationContext,
ConfigurationField field)
=> ValidateInternal(value, field.Key);

Check warning on line 42 in src/Umbraco.Infrastructure/PropertyEditors/ColorPickerConfigurationEditor.cs

View check run for this annotation

CodeScene Delta Analysis / CodeScene Code Health Review (main)

❌ New issue: Excess Number of Function Arguments

Validate has 5 arguments, max arguments = 4. This function has too many arguments, indicating a lack of encapsulation. Avoid adding more arguments.

private IEnumerable<ValidationResult> ValidateInternal(object? value, string fieldName)
{
var stringValue = value?.ToString();
if (stringValue.IsNullOrWhiteSpace())
Expand All @@ -46,15 +61,15 @@

if (items is null)
{
yield return new ValidationResult($"The configuration value {stringValue} is not a valid color picker configuration", new[] { "items" });
yield return new ValidationResult($"The configuration value {stringValue} is not a valid color picker configuration", [fieldName]);
yield break;
}

foreach (ColorPickerConfiguration.ColorPickerItem item in items)
{
if (Regex.IsMatch(item.Value, "^([0-9a-f]{3}|[0-9a-f]{6})$", RegexOptions.IgnoreCase) == false)
{
yield return new ValidationResult($"The value {item.Value} is not a valid hex color", new[] { "items" });
yield return new ValidationResult($"The value {item.Value} is not a valid hex color", [fieldName]);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,22 @@
public ValueListUniqueValueValidator(IConfigurationEditorJsonSerializer configurationEditorJsonSerializer)
=> _configurationEditorJsonSerializer = configurationEditorJsonSerializer;

public IEnumerable<ValidationResult> Validate(object? value, string? valueType, object? dataTypeConfiguration, PropertyValidationContext validationContext)
public IEnumerable<ValidationResult> Validate(
object? value,
string? valueType,
object? dataTypeConfiguration,
PropertyValidationContext validationContext)
=> ValidateInternal(value, "items");

public IEnumerable<ValidationResult> Validate(
object? value,
string? valueType,
object? dataTypeConfiguration,
PropertyValidationContext validationContext,
ConfigurationField field)
=> ValidateInternal(value, field.Key);

Check warning on line 34 in src/Umbraco.Infrastructure/PropertyEditors/ValueListUniqueValueValidator.cs

View check run for this annotation

CodeScene Delta Analysis / CodeScene Code Health Review (main)

❌ New issue: Excess Number of Function Arguments

Validate has 5 arguments, max arguments = 4. This function has too many arguments, indicating a lack of encapsulation. Avoid adding more arguments.

private IEnumerable<ValidationResult> ValidateInternal(object? value, string fieldName)
{
if (value is null)
{
Expand All @@ -40,7 +55,7 @@

if (items is null)
{
yield return new ValidationResult($"The configuration value {value} is not a valid value list configuration", ["items"]);
yield return new ValidationResult($"The configuration value {value} is not a valid value list configuration", [fieldName]);
yield break;
}

Expand All @@ -53,7 +68,7 @@

foreach (var duplicateValue in duplicateValues)
{
yield return new ValidationResult($"The value \"{duplicateValue}\" must be unique", new[] { "items" });
yield return new ValidationResult($"The value \"{duplicateValue}\" must be unique", [fieldName]);
}
}
}
Loading