项目作者: milindsingh

项目描述 :
Ultimate GrumPHP configuration for Magento 2 automated code quality checks
高级语言:
项目地址: git://github.com/milindsingh/magento2-grumphp.git
创建时间: 2020-05-24T04:56:01Z
项目社区:https://github.com/milindsingh/magento2-grumphp

开源协议:MIT License

下载


Magento2 GrumPHP

GrumPHP configuration for Magento 2 Module Automated Quality Check

What is GrumPHP ?

  • GrumPHP has a set of common tasks built-in.

  • GrumPHP will run some tests on the committed code. If the tests fail, you won’t be able to commit your changes.

  • This handy tool will not only improve your codebase, it will also teach your co-workers to write better code following the best practices you’ve determined as a team.

  • GrumPHP can be configured at 2 levels:

    • module level (magento-2-root/app/code/MyVendor/MyModule).

    • project level (magento-2-root).

Setup

  1. Install GrumPHP by running composer require --dev phpro/grumphp or composer global require --dev phpro/grumphp

  2. GrumPHP can monitor each git repository push action by initializing it in the repository.

    Goto the module directory and Run: php vendor/bin/grumphp git:init or grumphp git:init

  3. GrumPHP is a task runner and all task needs to be defined via grumphp.yml file in the module directory (app/code/MyVendor/MyModule) for module level configuration.
    Use the below example to start with:

  1. grumphp:
  2. hide_circumvention_tip: true
  3. process_timeout: 120
  4. tasks:
  5. composer:
  6. file: ./composer.json
  7. no_check_all: true
  8. no_check_lock: false
  9. no_check_publish: false
  10. with_dependencies: false
  11. strict: false
  12. git_blacklist:
  13. keywords:
  14. - "die("
  15. - "var_dump("
  16. - "print_r("
  17. - "exit;"
  18. - "console.log"
  19. - "_objectManager"
  20. - "ObjectManagerInterface"
  21. phpcs:
  22. standard: Magento2
  23. tab_width: 4
  24. severity: 10
  25. error_severity: 10
  26. warning_severity: ~
  27. report: full
  28. triggered_by: [phtml, php]
  29. phpcsfixer2:
  30. allow_risky: ~
  31. cache_file: ~
  32. config: '../../../../.php_cs.dist'
  33. using_cache: ~
  34. verbose: true
  35. config_contains_finder: false
  36. triggered_by: ['php', 'phtml']
  37. # phpmd:
  38. # ruleset: ['%magento_dir%/dev/tests/static/testsuite/Magento/Test/Php/_files/phpmd/ruleset.xml']
  39. # phpstan:
  40. # autoload_file: ~
  41. # configuration: ~
  42. # level: 0
  43. # force_patterns: []
  44. # ignore_patterns: []
  45. # triggered_by: ['php']
  46. # memory_limit: "-1"
  1. Add bin path (magento2-root/vendor/bin) to composer.json:

    1. {
    2. "config": {
    3. "bin-dir": "../../../../vendor/bin"
    4. }
    5. }
  2. Test by running php ../../../../vendor/bin/grumphp run or grumphp run

Dependencies

1. PHPCS

  • Goto Magento2 root run following commands:

  • Install PHP CodeSniffer (skip if already installed) : composer require --dev "squizlabs/php_codesniffer=*"

  • Install Magento2 coding standard :

    composer require --dev magento/magento-coding-standard

  • Set Magento2 Standard in PHP CodeSniffer available standards:

    phpcs --config-set installed_paths ../../magento/magento-coding-standard/

2. PHPCS FIXER 2

3. PHPMD

4. PHPSTAN