DEV Community

Mahmoud Ramadan
Mahmoud Ramadan

Posted on

Using Traits and DocBlocks for Cleaner Architecture 🤵

improve-ide-analysis

I worked on a custom CRUD command that generates a Model, Migration, Views, Controller, Request, and Repository class. I created an Action class responsible for handling all CRUD operations to manage z. However, the class started growing too large — that was the first issue. To address this, I split the logic into multiple traits, and each trait handles a specific part of the process.

These traits relied on global methods and properties defined in the main Action class, which became a major issue for me since I value code readability for myself and other developers in the future. Unfortunately, the IDE couldn’t recognize or analyze these methods properly. To solve this, I used PHP DocBlocks to document the shared methods and properties, which improved code readability and IDE support.

Heroku

Built for developers, by developers.

Whether you're building a simple prototype or a business-critical product, Heroku's fully-managed platform gives you the simplest path to delivering apps quickly — using the tools and languages you already love!

Learn More

Top comments (0)

Billboard image

Create up to 10 Postgres Databases on Neon's free plan.

If you're starting a new project, Neon has got your databases covered. No credit cards. No trials. No getting in your way.

Try Neon for Free →