8 Code organization

 

This chapter covers

  • Organizing code for scalability
  • Best practices in code layouts
  • Best practices in Object oriented programming
  • How to better adhere to S.O.L.I.D principles

In today's world of software development, where complexity and scale are increasing at an unprecedented rate, it is becoming more important than ever to adopt effective code organization practices. This is particularly true in the case of PHP, which is a widely used server-side scripting language for developing web applications.

Code organization refers to structuring and managing code to make it easier to understand, maintain, and scale. It involves breaking down the code into smaller, reusable components, grouping related components together, and keeping them organized logically and consistently. Effective code organization not only helps developers to work more efficiently but also improves the overall quality of the codebase and makes it more robust and scalable.

This chapter will explore best practices for organizing PHP code, including namespaces, classes, and functions. We will discuss the benefits of these practices and how they can help improve your codebase's readability, maintainability, and scalability. We will also cover some common pitfalls developers may encounter when organizing their code and how to avoid them.

8.1 Having all classes in the root namespace

8.2 Installing third-party packages manually without Composer

8.3 Creating classes that do too much.

8.4 Using global data

8.5 Reinventing the wheel

8.6 Creating a class that is dependent on another

8.7 Depending on classes instead of interfaces

8.8 Installing dependencies globally instead of as part of the codebase

8.9 Summary