Naming Suffix Conventions
ID |
php.naming_suffix_conventions |
Severity |
info |
Remediation Complexity |
trivial |
Remediation Risk |
medium |
Remediation Effort |
low |
Resource |
Naming Convention |
Language |
Php |
Tags |
naming |
Description
Reports a type whose name advertises a declaration kind that the actual declaration
contradicts: a name ending in Interface that is not an interface, or a name ending in
Trait that is not a trait. The Abstract prefix is not enforced — in PHP it is a base-class
naming convention applied to concrete classes — and the *Exception convention is enforced
separately by php.exception_extension.
Rationale
A suffix that names a kind is a contract with the reader: PaymentInterface
promises an interface and LoggableTrait promises a trait. When the declaration does not
match, the name actively misinforms — callers expect to implements PaymentInterface or
use LoggableTrait and instead find a concrete class. Aligning the kind keyword with the name
removes the trap. Adjective names such as Comparable or Cacheable carry no kind suffix and
are never flagged. The Abstract prefix is a widespread base-class naming convention applied
to concrete classes (for example class AbstractCategory extends Template), so it is not
flagged.
<?php
interface PaymentInterface {} // OK - ends Interface and is an interface
class ShipmentInterface {} // FLAW - ends Interface but is a class
trait LoggableTrait {} // OK - ends Trait and is a trait
class AuditingTrait {} // FLAW - ends Trait but is a class
class AbstractGateway {} // OK - Abstract prefix is not enforced
Remediation
Either change the declaration to the promised kind (declare an interface or a trait), or
rename the type so its suffix no longer claims a kind it is not.