Skip to content

Import WP_Error class instead of using fully qualified references #128

@galatanovidiu

Description

@galatanovidiu

Summary

Update PHPCS configuration to allow importing WP_Error via use statements instead of requiring fully qualified references (\WP_Error) throughout the codebase.

Background

During PR #123 review, @JasonTheAdams suggested importing WP_Error to drop the root namespace prefix. Investigation revealed that the current SlevomatCodingStandard.Namespaces.FullyQualifiedExceptions rule enforces fully qualified references for classes ending with Error, which includes WP_Error.

However, WP_Error is not an actual exception class (it doesn't extend Exception or Throwable) - it's a WordPress utility class for error handling. The rule's documentation explicitly supports adding such classes to ignoredNames.

Proposed Changes

  1. Update phpcs.xml to add WP_Error to ignoredNames:
<rule ref="SlevomatCodingStandard.Namespaces.FullyQualifiedExceptions">
    <properties>
        <property name="ignoredNames" type="array">
            <element value="WP_Error" />
        </property>
    </properties>
</rule>
  1. Update all namespaced files that use \WP_Error:
    • Add use WP_Error; import statement
    • Replace \WP_Error with WP_Error in code
    • Update PHPDoc @return types from \WP_Error to WP_Error

References

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status

    No status

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions