Code Monkey home page Code Monkey logo

swiss-knife's Introduction

Swiss Knife for Upgrades

Downloads total

Swiss knife in pocket of every upgrade architect!


Install

composer require tomasvotruba/lemonade --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.


5. Dependency tools speed testing

Do you want to test speed of your dependency tools? E.g. if PHPStan or Rector got slower after upgrade?

  1. Prepare a script in composer.json
{
    "scripts": {
        "phpstan": "vendor/bin/phpstan analyse src --level 8"
    }
}
  1. Run past X versions and measure time and memory
vendor/bin/swiss-knife speed-run-tool phpstan/phpstan --script-name phpstan --run-count 5

Happy coding!

swiss-knife's People

Contributors

actions-user avatar samsonasik avatar tomasvotruba avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.