PR #2688 updates the WordPress.Arrays.ArrayDeclarationSpacing sniff to use "arrays with explicit keys" instead of "associative arrays" in its error messages. As part of that change, @jrfnl suggested deprecating the allow_single_item_single_line_associative_arrays property in favor of a new name in a separate PR, keeping both properties until the 4.0 release.
As far as I could check, this would be the first public property deprecation since WPCS 2.0, so I'd like to discuss the best approach before implementing it.
Previous approach
Before WPCS 2.0, two public properties were deprecated with a backwards compatibility layer:
EscapeOutputSniff::$customSanitizingFunctions became $customEscapingFunctions (78791a6)
ValidVariableNameSniff::$customVariablesWhitelist became $customPropertiesWhitelist (be11bc2)
The pattern used was:
- Keep the old property public, mark as
@deprecated in the docblock.
- Check if the old property was changed from its default (using
! empty() for array properties).
- If changed, merge the old property's value into the new one and issue a deprecation notice via
$phpcsFile->addWarning() at line 0.
- Both properties were removed in the 2.0 release (405f264).
Questions
- Is the
addWarning() approach from the pre-2.0 era still the preferred way to handle this? Or is there a better alternative?
- For a boolean property (default
true), the detection would check true !== $this->old_property_name to catch any non-default value. However, this approach won't trigger the deprecation notice when the old property is explicitly set to its default value (hopefully an edge case). As far as I could find, there is no way to check whether the user explicitly set a property. Is there a better way to handle this?
PR #2688 updates the
WordPress.Arrays.ArrayDeclarationSpacingsniff to use "arrays with explicit keys" instead of "associative arrays" in its error messages. As part of that change, @jrfnl suggested deprecating theallow_single_item_single_line_associative_arraysproperty in favor of a new name in a separate PR, keeping both properties until the 4.0 release.As far as I could check, this would be the first public property deprecation since WPCS 2.0, so I'd like to discuss the best approach before implementing it.
Previous approach
Before WPCS 2.0, two public properties were deprecated with a backwards compatibility layer:
EscapeOutputSniff::$customSanitizingFunctionsbecame$customEscapingFunctions(78791a6)ValidVariableNameSniff::$customVariablesWhitelistbecame$customPropertiesWhitelist(be11bc2)The pattern used was:
@deprecatedin the docblock.! empty()for array properties).$phpcsFile->addWarning()at line 0.Questions
addWarning()approach from the pre-2.0 era still the preferred way to handle this? Or is there a better alternative?true), the detection would checktrue !== $this->old_property_nameto catch any non-default value. However, this approach won't trigger the deprecation notice when the old property is explicitly set to its default value (hopefully an edge case). As far as I could find, there is no way to check whether the user explicitly set a property. Is there a better way to handle this?