tomasvotruba/ctor 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

tomasvotruba/ctor

最新稳定版本:2.2.1

Composer 安装命令:

composer require tomasvotruba/ctor

包简介

Prefer constructor over always called setters

README 文档

README

Downloads

If you can use constructor instead of setters, use it. These PHPStan rules will help you to find such cases.


What It Does?

This tool collects instances of new object() followed by a series of method calls on the same object:

$human = new Human();
$human->setName('Tomas');
$human->setAge(35);

...and suggests turning them into constructor arguments:

$human = new Human('Tomas', 35);

Why?

Such chained setters often indicate implicit required dependencies. By moving them to the constructor, you make the object state explicit, safer, and easier to reason about — and even easier to test.


Installation

composer require tomasvotruba/ctor --dev

Usage

Make use phpstan/extension-installer to load the extension automatically.

Run PHPStan and it will automatically run the rules.


Happy coding!

统计信息

  • 总下载量: 14.06k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 10
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 10
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-07-09