u/Praemon

▲ 18 r/PHP

Namespaces, interfaces and stutter

Hi all. I wanted to see what the opinion is on the following situation:

Lets say your team targets removing suffixes from interfaces (so no Interface suffix), while also avoiding namespace/class stutter. You then have an example like this:

You have a Payment namespace with a Client interface that drives certain interactions with different payment providers (such as Stripe). Within the Payment namespace you have a Stripe folder that has the payment provider's implementation of the Client interface. To avoid namespace stutter, you end with with this:

namespace App\Payment;

interface Client  
namespace App\Payment\Stripe;

use App\Payment\Client as ClientInterface;

class Client implements ClientInterface  

So the Stripe client is App\Payment\Stripe\Client and not App\Payment\Stripe\StripeClient to reduce namespace stutter.

To avoid collision you have to now alias the interface, which introduces its own readability issues.

Should namespace stutter just be accepted here, or is there a better way of handling it?

reddit.com
u/Praemon — 4 days ago