Skip to content
This repository was archived by the owner on Jun 8, 2026. It is now read-only.

Commit 2e7d211

Browse files
committed
readme
1 parent dacf1c5 commit 2e7d211

1 file changed

Lines changed: 26 additions & 10 deletions

File tree

README.md

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,41 @@
22

33
[![Downloads](https://img.shields.io/packagist/dt/tomasvotruba/ctor.svg?style=flat-square)](https://packagist.org/packages/tomasvotruba/ctor/stats)
44

5-
@todo
5+
If you can use constructor instead of setters, use it. These PHPStan rules will help you to find such cases.
66

7-
/**
8-
* Collect instance of `new`,
9-
* which is followed by a method calls on same object
10-
*
11-
* Goal is to find objects, that are created with same set of setters,
12-
* then pass values via constructor instead.
13-
*/
7+
## What It Does?
8+
9+
This tool collects instances of `new object()` followed by a series of method calls on the same object:
10+
11+
```php
12+
$human = new Human();
13+
$human->setName('Tomas');
14+
$human->setAge(35);
15+
```
16+
17+
...and suggests turning them into constructor arguments:
18+
19+
```php
20+
$human = new Human('Tomas', 35);
21+
```
22+
23+
### Why?
24+
25+
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.
1426

1527
<br>
1628

17-
## Install
29+
## Installation
1830

1931
```bash
2032
composer require tomasvotruba/ctor --dev
2133
```
2234

23-
@todo
35+
## Usage
36+
37+
Make use [`phpstan/extension-installer`](https://github.com/phpstan/extension-installer) to load the extension automatically.
38+
39+
Run PHPStan and it will automatically run the rules.
2440

2541
<br>
2642

0 commit comments

Comments
 (0)