A new PHPStan extension called 'ctor' detects the anti-pattern of always-called setter methods that should instead be constructor arguments. When setters are called immediately after object instantiation every time, they are effectively required dependencies masquerading as optional configuration. The extension flags these cases and suggests moving them into the constructor, ensuring objects are fully valid from the moment they are created. Install via Composer as a dev dependency and run PHPStan to find hidden constructors in your codebase.
Sort: