Note: This article targets PHP developers specifically, but software developers across domains can likely relate to similar scenarios in their projects.
What is a tool?
Let’s clarify “tools”. Nowadays, nearly every PHP application utilizes phpstan or phan as static analyzers. If your project includes tests, you’ve probably installed phpunit, pest, or a test-runner from phpkg. But what exactly are these packages? What do they do and how do they contribute to your project? Are you actively using any code from these dependencies? Probably not. If you are, especially for the mentioned packages, it might signify a larger issue than what’s discussed here.
These packages aren’t directly tied to your application; as a developer, you utilize them as tools for your project. If you use Composer, you likely categorize them under the dev section to specify that they’re needed only in your development environment, not in production.
So, what’s the issue?
As a busy developer, you likely manage multiple projects, each with at least one of these tools installed. When setting up a development environment, you repeatedly download and install these tools for each application. Even if you work exclusively on one project within a company, your colleagues also need these tools for their respective projects. Consider the cumulative size of these packages and their dependencies, multiplied by the number of projects and developers globally. Reflect on the environmental impact of machines downloading and installing them, and consider the broader implications, including their contribution to global warming. While this might seem disconnected, our coding choices can influence these issues profoundly. If we disregard these concerns, how can we expect governments to address global warming? If environmental concerns don’t motivate you, consider the added complexity that each unnecessary package brings to your application.
What’s the solution?
Why not install these tools once on each machine and utilize them across all your projects? As developers, we have the power to make this a reality. We are the ones who can turn ideas into action.
How can this be achieved?
If you’re using Composer, unfortunately, there’s currently no straightforward solution. However, if you’re using phpkg or considering it, there’s a viable alternative. You don’t need to migrate your project to phpkg immediately; you can use phpkg alongside Composer. Phpkg provides a run command that enables you to execute any library on the fly. You don’t need to embed these libraries in your applications; in fact, you can run libraries without any application context. For instance, concerning the tools issue, you can analyze any project with phpstan immediately using this command:
phpkg run https://github.com/phpstan/phpstan.git phpstan analyze /path/to/project
Conclusion:
If a dependency in your project isn’t actively used, you’ve misunderstood the problem. These dependencies are tools necessary for your work, so why not utilize them efficiently? Stop adding tools to your project dependencies and contribute to saving the world in your own way. At least in PHP applications, now there is a way to do so: utilize phpkg’s run command.