vimeo/psalm
Psalm is a powerful PHP static analysis tool that finds type errors and bugs before runtime. Install via Composer, configure for your codebase, and run it locally or try the live demo at psalm.dev. Docs and integrations available for teams and CI.
Emitted when a non-final, non-abstract class with no child classes is found.
<?php
class A {}
Non-final classes are bad for multiple reasons:
[@api](https://github.com/api) attribute).final classes.In general, the number of non-final classes in the codebase should be reduced as much as possible, both to speed up code execution and avoid unexpected bugs.
Recommended, make the class final:
<?php
final class A {}
The above can also be automated using vendor/bin/psalm --alter --issues=ClassMustBeFinal.
If inheritance should still be allowed, reduce the surface covered by the backwards compatibility promise by making the class abstract (containing only the logic that should be overridable), and move any non-overridable logic to a new A class:
<?php
abstract class A {}
final class NewA extends A {}
Note: if non-final classes are needed for mocking in unit tests, simply use dg/bypass-finals in your unit tests to allow mocking final classes.
An alternative, not recommended for the above reasons, is to make the class part of the public API of your library with [@api](https://github.com/api).
How can I help you explore Laravel packages today?