我一輩子的文章都會放在這裏,個人博客,我但願每一行代碼,每一段文字都能幫助你。 https://github.com/CrazyCodes...
嗨,我是CrazyCodes,小時候作錯事,長輩有沒有訓斥過你呢?今天讓咱們看看PHP的監護者,憤怒的老頭- - grumphpphp
GrumPHP 是經過掛在git hook上的一款PHP代碼檢測工具,他能夠經過編碼人員提交git時進行檢查,檢查經過則提交成功,檢查失敗則終止提交。git
經過composer直接安裝便可,不推薦其餘安裝方式github
composer require --dev phpro/grumphp
這類工具必定要放在dev內,在生產環境使用毫無心義,因此帶參 --dev。shell
安裝結束後會自動在項目根目錄創建grumphp.yml,官方給出的demo以下npm
# grumphp.yml parameters: bin_dir: "./vendor/bin" git_dir: "." hooks_dir: ~ hooks_preset: local git_hook_variables: VAGRANT_HOST_DIR: . VAGRANT_PROJECT_DIR: /var/www EXEC_GRUMPHP_COMMAND: exec stop_on_failure: false ignore_unstaged_changes: false hide_circumvention_tip: false process_async_limit: 10 process_async_wait: 1000 process_timeout: 60 ascii: failed: grumphp-grumpy.txt succeeded: grumphp-happy.txt tasks: ant: ~ atoum: ~ behat: ~ brunch: ~ clover_coverage: ~ codeception: ~ composer: ~ composer_normalize: ~ composer_require_checker: ~ composer_script: ~ deptrac: ~ doctrine_orm: ~ file_size: ~ gherkin: ~ git_blacklist: ~ git_branch_name: ~ git_commit_message: ~ grunt: ~ gulp: ~ infection: ~ jsonlint: ~ kahlan: ~ make: ~ npm_script: ~ paratest: ~ phan: ~ phing: ~ php7cc: ~ phpcpd: ~ phpcs: ~ phpcsfixer: ~ phpcsfixer2: ~ phplint: ~ phpmd: ~ phpmnd: ~ phpparser: ~ phpspec: ~ phpstan: ~ phpunit: ~ phpunitbridge: ~ phpversion: ~ progpilot: ~ psalm: ~ robo: ~ securitychecker: ~ shell: ~ twigcs: ~ xmllint: ~ yamllint: ~ testsuites: [] extensions: []
參數名 | 默認值 | 註釋 |
---|---|---|
bin_dir | ./vendor/bin | 方便找到phpcs這類檢測工具的外部命令,通常不須要修改 |
git_dir | . | 默認git目錄,正常都在根目錄的吧 |
hooks_dir | null | 設置鉤子文件夾,默認會直接找 resources/hooks |
tasks | 用於加載代碼檢測的庫 |
是否是太多了,忽略上面,咱一步一步看。下面是安裝完成後自動生成的配置文件json
parameters: git_dir: . bin_dir: vendor/bin tasks: { }
如今目錄是醬紫的gulp
parameters: git_dir: . bin_dir: vendor/bin tasks: { phpcs : ~ }
新建一個文件easy.php,代碼以下,多一個分號,老頭是必定不會放過你的。php7
echo '召喚憤怒的老頭';;
老頭是醬紫說的,額,其實他是一個紅色的app
GrumPHP detected a pre-commit command. GrumPHP is sniffing your code! Running task 1/1: Phpcs... ✘ ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄ ▄▄▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▌ ▐▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▄ ▐▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▌ ▐▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▌ ▄███▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▌ █▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▌ ▐█▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▌ ▀█▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▌ ▀▀▓▓▓▓▓▓▓▓▓▓▓▓█▀▀▀▀▀▀▀▀▀▀▀▀▀▀████████████▄ ▄███████ ██████████ ███████▀ ▀▀▀▀▀▄ ▄▀▀▀▀▀ █████ ▀ ▐████ ▐██ ▐██ ████▌ ████▌ ███ ▌██▌ ▄▄ ▄▄ ▐███ ███ ▄▄▄▄▄▄▄▄▄▄▄▄ ▐███ ██▄ ▐███████████████████████████ █▀███████████▀ ▀▀███████████ ██████████▄███████▄███████████ ▐█████████████████████████████ █████████████████████████████ ██ █████████████████████▐██▀ ▀ ▐███████████████████▌ ▐▀ ████▀████████▀▐███ ▀█▌ ▐█████ ██▌ ██▀ ▐▀ ██████████████████████████████████ █░░░░░░▀█▀░░░░░░▀█░░░░░░▀█▀░░░░░▀█ █░░▐█▌░░█░░░██░░░█░░██░░░█░░░██░░█ █░░▐█▌░░█░░░██░░░█░░██░░░█░░░██░░█ █░░▐█▌░░█░░░██░░░█░░░░░░▄█░░▄▄▄▄▄█ █░░▐█▌░░█░░░██░░░█░░░░████░░░░░░░█ █░░░█░░░█▄░░░░░░▄█░░░░████▄░░░░░▄█ ██████████████████████████████████ FILE: /Users/crazy/http/app/yield_test/easy.php ---------------------------------------------------------------------- FOUND 1 ERROR AFFECTING 1 LINE ---------------------------------------------------------------------- 2 | ERROR | Missing file doc comment ---------------------------------------------------------------------- Time: 37ms; Memory: 4MB
不單單有憤怒的老頭,GrumPHP還提示了一些其餘內容。composer
此次檢測是說我沒寫註釋。是否是頗有意思?GrumPHP不單單就這點能力哦,想深刻請自行挖掘。
有人問,你爲何要這麼折磨本身呢?其實像類型GrumPHP代碼質量工具,不是僅僅本身拿來玩的,在開發人員略多的技術團隊,能夠經過使用它來達到代碼規範一致,若是每一個人代碼都不同,後果不堪設想。
感謝你看到這裏,但願本篇文章能夠幫到你。