Download the PHP package rector/swiss-knife without Composer
On this page you can find all versions of the php package rector/swiss-knife. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download rector/swiss-knife
More information about rector/swiss-knife
Files in rector/swiss-knife
Package swiss-knife
Short Description Swiss knife in pocket of every upgrade architect
License MIT
Informations about the package swiss-knife
Swiss Knife for Upgrades
Swiss knife in the pocket of every upgrade architect!
Install
Usage
- 1. Check your Code for Git Merge Conflicts
- 2. Detect Commented Code
- 3. Reach full PSR-4
- 4. Finalize classes without children
- 5. Privatize local class constants
- 6. Spots Fake Traits
- 7. Split huge Symfony config to per-package in directory
- 8. Generate Symfony Smoke Tests
- 9. Detect Duplicated Code
1. Check your Code for Git Merge Conflicts
Do you use Git? Then merge conflict markers are the last thing you want to see in pushed code:
Add this command to CI to spot these:
You can skip paths with the --exclude option:
2. Detect Commented Code
Have you ever forgotten commented code in your project?
No more! Add this command to CI to spot these:
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 a single file:
Update Namespace to match PSR-4 Root
Is your class in wrong namespace? Make it match your PSR-4 root:
This will update all files in your /src directory, to starts with App\\ and follow full PSR-4 path:
4. Finalize classes without children
Do you want to finalize all classes that don't have children?
Do you use mocks but not bypass final yet?
This will keep mocked classes non-final, so PHPUnit can extend them internally.
Do you want to skip file or two?
Skip is also support with fnmatch() patterns:
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?
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.
6. Split huge Symfony config to per-package in directory
Do you have a huge Symfony config file that is hard to navigate? Do you want to split it to per-package files?
Before - one huge config/config_dev.php with many extensions in a single file:
Run the command:
After - the original config only imports the per-package files:
And each extension lives in its own file, e.g. config/packages/dev/doctrine.php:
All the extensions will be extracted to separate files in config/packages/dev directory, making them much more readable.
7. Generate Symfony Smoke Tests
Cover your Symfony app with smoke tests in seconds. This command scans your composer.json, picks the matching test templates, and drops them under tests/Unit/Smoke (or your project's equivalent unit-tests directory).
The command will:
- detect your unit tests directory and create a
Smokesub-directory - generate a
ServiceContainerTestthat boots the kernel and instantiates every service to catch container misconfiguration early - add a shared
AbstractContainerTestCasewith a typedgetService()helper - adjust the namespace and
Kernelclass in the templates to match your project (usesApp\Kernel,AppKernel, orKernel, whichever exists)
Existing files are never overwritten, so the command is safe to re-run.
The generated ServiceContainerTest boots the kernel and asserts every service can be instantiated:
8. Detect Duplicated Code
Spot copy-pasted code blocks with a token-based detector, a small clone of phpcpd. Add it to CI to fail when a large copy-pasted block is added:
Options:
--min-linesminimum lines of a reported clone (default5)--min-tokensminimum tokens of a reported clone (default70)--fuzzyignore variable names when matching--skip-filefile paths or masks to skip
Exit code is 1 when clones are found, 0 otherwise.
10. Measure Code Size
Measure lines of code and structure size of your project - files, classes, methods, constants and more:
Options:
--excludepaths to exclude--shortprint short metrics only--longestshow top 10 longest files--allow-vendorallow the/vendordirectory to be scanned--jsonoutput in JSON format
11. Count PHP Features
Count PHP features used in the project, grouped by the PHP version that introduced them. Handy to see how modern your code is before an upgrade:
Options:
--jsonoutput in JSON format
12. Check for Outdated Dependencies in CI
Postponing upgrades leads to large, risky jumps. The breakpoint command catches outdated major packages early, right in your CI pipeline:
↓
If there are more than 5 major outdated packages, the CI will fail.
Options:
--limitraise or lower the bar, e.g.--limit 3--devcheck dev packages only (safer to upgrade first)
13. Open up Next Versions
We know we're behind, but where to start? Instead of guessing, let Composer handle it - open up package versions to the next nearest step:
This opens up 5 versions to their next step, e.g.:
Then run composer update - if no blockers exist, Composer updates packages to their next version.
Options:
--limitnumber of packages to open, e.g.--limit 3--package-prefixupgrade only a group, e.g.--package-prefix symfony--devlow-risk dev packages first--dry-runpreview changes without modifyingcomposer.json
14. Raise to Installed Versions
Sometimes it's the opposite - dependencies are new, but composer.json is outdated:
Here illuminate/container allows 12.0 but we already use 12.14, and symfony/finder allows 6.4 but we use 7.2. Running composer update could pull unnecessary older dependencies.
Raise composer.json to the installed versions:
Options:
--dry-runpreview changes without applying
That's it!
Happy coding!
All versions of swiss-knife with dependencies
ext-tokenizer Version *
composer/semver Version ^3.5
entropy/entropy Version ^0.4.23
nikic/php-parser Version ^5.9
symfony/process Version ^5.4 || ^6.4 || ^7.0 || ^8.1