I have a precedent for this, which is my own preference. I will often write traits designed to adhere to a particular interface, although since traits cannot directly implement an interface, I will indicate which interface it satisfies in the comment block of the dock code, as well as the prefix of protected and private methods that are not associated with an interface with one underline. This allows you to pretty easily keep track of which methods are provided to satisfy the contract (interface) and which methods support. For instance:
interface Foo { public function bar(array $args = null, array $flags = null); }
The sign below the goal should satisfy the requirements of the Foo interface, but only one of its methods is required for this. For clarity, protected methods are prefixed. Even if they become publicly available later, this still indicates that they are interface-independent and should not be considered relevant.
trait FooTrait { public function bar(array $args = null, array $flags = null) { $this->_handleArgs($args); $this->_handleFlags($flags); } protected function _handleArgs(array $args = null) { if (is_null($args) { return; }
Then you can satisfy the interface by implementing it in the class and using the corresponding attribute without additional work.
final class ConcreteFoo implements Foo { use FooTrait; }
This greatly simplifies communication and allows you to easily integrate with other classes from other libraries or frameworks that require an inheritance chain, without having to collapse your logic using the adapter class group.
My IDE (Netbeans) grumbles about this as a violation of PSR-1. Since PSR-1 does not directly affect execution, and it can be argued that this is a more readable approach or not, I could take care of it less. I am trying to execute all PSRs that directly affect the execution.
source share