rector / swiss-knife
Swiss knife in pocket of every upgrade architect
Fund package maintenance!
tomasvotruba
www.paypal.me/rectorphp
Installs: 266 678
Dependents: 12
Suggesters: 0
Security: 0
Stars: 96
Watchers: 3
Forks: 8
Open Issues: 6
Requires
- php: >=7.2
- dev-main
- 1.0.0
- 0.2.35
- 0.2.34
- 0.2.33
- 0.2.32
- 0.2.31
- 0.2.30
- 0.2.29
- 0.2.28
- 0.2.27
- 0.2.26
- 0.2.25
- 0.2.24
- 0.2.23
- 0.2.22
- 0.2.21
- 0.2.20
- 0.2.19
- 0.2.18
- 0.2.17
- 0.2.16
- 0.2.15
- 0.2.14
- 0.2.13
- 0.2.12
- 0.2.11
- 0.2.10
- 0.2.9
- 0.2.8
- 0.2.7
- 0.2.6
- 0.2.5
- 0.2.4
- 0.2.3
- 0.2.2
- 0.2.1
- 0.2.0
- 0.1.14
- 0.1.13
- 0.1.12
- 0.1.11
- 0.1.10
- 0.1.9
- 0.1.8
- 0.1.7
- 0.1.6
- 0.1.5
- 0.1.4
- 0.1.3
- 0.1.2
- 0.1.1
- 0.1.0
- dev-tv-multiple
- dev-tv-dump-editorconfig
This package is auto-updated.
Last update: 2024-10-29 13:42:20 UTC
README
Swiss knife in pocket of every upgrade architect!
Install
composer require rector/swiss-knife --dev
Usage
1. Check your Code for Git Merge Conflicts
Do you use Git? Then merge conflicts is not what you want in your code ever to see in pushed code:
<<<<<<< HEAD
Add this command to CI to spot these:
vendor/bin/swiss-knife check-conflicts .
Note: The /vendor
directory is excluded by default.
2. Detect Commented Code
Have you ever forgot commented code in your code?
// foreach ($matches as $match) { // $content = str_replace($match[0], $match[2], $content); // }
No more! Add this command to CI to spot these:
vendor/bin/swiss-knife check-commented-code <directory> vendor/bin/swiss-knife check-commented-code packages --line-limit 5
3. Reach full PSR-4
Find multiple classes in single file
To make PSR-4 work properly, each class must be in its own file. This command makes it easy to spot multiple classes in single file:
vendor/bin/swiss-knife find-multi-classes src
Update Namespace to match PSR-4 Root
Is your class in wrong namespace? Make it match your PSR-4 root:
vendor/bin/swiss-knife namespace-to-psr-4 src --namespace-root "App\\"
This will update all files in your /src
directory, to starts with App\\
and follow full PSR-4 path:
# file path: src/Repository/TalkRepository.php -namespace Model; +namespace App\Repository; ...
4. Finalize classes without children
Do you want to finalize all classes that don't have children?
vendor/bin/swiss-knife finalize-classes src tests
Do you use mocks but not bypass final yet?
vendor/bin/swiss-knife finalize-classes src tests --skip-mocked
This will keep mocked classes non-final, so PHPUnit can extend them internally.
Do you want to skip file or two?
vendor/bin/swiss-knife finalize-classes src tests --skip-file src/SpecialProxy.php
5. Privatize local class constants
PHPStan can report unused private class constants, but it skips all the public ones. Do you have lots of class constants, all of them public but want to narrow scope to privates?
vendor/bin/swiss-knife privatize-constants src test
This command will:
- find all class constant usages
- scans classes and constants
- makes those constant used locally
private
That way all the constants not used outside will be made private
safely.
Happy coding!