Skip to content

Instantly share code, notes, and snippets.

@allysonsilva
Last active April 26, 2018 13:04
Show Gist options
  • Save allysonsilva/b624c52b9dd53da2c9bd6fab17f9c6ab to your computer and use it in GitHub Desktop.
Save allysonsilva/b624c52b9dd53da2c9bd6fab17f9c6ab to your computer and use it in GitHub Desktop.
⚡️🧠 Examples PHP Static Analysis Tool
# ##########################
# PHP Coding Standards Fixer
# ##########################
php-cs-fixer fix Controller.php --rules=@PSR2 --dry-run --diff -
php-cs-fixer fix Controller.php --rules=@PSR2 -v
php-cs-fixer fix app/Http/Controllers --dry-run --verbose --diff --using-cache=no
php-cs-fixer --dry-run --diff --using-cache=no --rules=@PSR2,@Symfony fix Controller.php
php-cs-fixer --dry-run --diff --using-cache=no --rules=@PSR2,@Symfony fix Controller.php ResponseController.php
# #######################
# PHP CodeSniffer (PHPCS)
# #######################
phpcs --extensions=php --standard=PSR2 --encoding=utf-8 --report=diff Controller.php -v
phpcs --extensions=php --standard=PSR2 --encoding=utf-8 --report=summary Controller.php --colors
phpcs --extensions=php --standard=PSR2 --encoding=utf-8 --report=summary,diff Controller.php --colors
phpcs --extensions=php --standard=PSR2 --report=source Controller.php --colors
phpcs --extensions=php --standard=PSR2 --report=source -n app/Http/Controllers/ --colors
phpcs --extensions=php --standard=PSR2 -n --extensions=php,php7 --tab-width=4 --encoding=utf-8 -d memory_limit=32M app/Http/Controllers/ --colors
phpcs --extensions=php --standard=PSR2 -n --extensions=php,php7 --tab-width=4 --encoding=utf-8 -d memory_limit=32M app/Http/Controllers/ --colors -s --report=source --report-full -vv -q -show-progress
phpcs --extensions=php --standard=PSR2 -n --extensions=php,php7 --tab-width=4 --encoding=utf-8 -d memory_limit=32M app/Http/Controllers/ --colors -s --report=source --report-full --report-width=auto
phpcs --report=checkstyle -d memory_limit=32M -n -s --extensions=php,php5,php7 --colors --encoding=utf-8 --tab-width=4 --standard=PSR2 Controller.php
phpcs --standard=PSR2 -n -s --colors --report-full --report-width=auto --ignore=*blade.php*,*twig.php* --tab-width=4 --encoding=utf-8 --extensions=php,php5,php7 -d memory_limit=32M app/Http/
phpcs --standard=PSR2 -ns -sp --colors --report=full --report-width=auto --ignore='*blade.php*,*twig.php*' --tab-width=4 --encoding=utf-8 --extensions=php,php5,php7 -d memory_limit=32M app/Http/Controllers/
phpcs --standard=PSR2 -nsp -v --report=full --report-width=auto --ignore='*blade.php*,*twig.php*' --tab-width=4 --encoding=utf-8 --extensions=php,php5,php7 -d memory_limit=32M app/Http/Controllers/
phpcs --standard=PSR2 -n --report=full --report-width=auto --ignore='*blade.php*,*twig.php*' --tab-width=4 --encoding=utf-8 --extensions=php,php5,php7 -d memory_limit=32M app/Http/Controllers/IndexController.php | grep '| ERROR |'
phpcs --standard=PSR2 -ns --colors --error-severity=1 --report=full --report-width=auto --ignore='*blade.php*,*twig.php*' --tab-width=4 --encoding=utf-8 --extensions=php,php5,php7 -d memory_limit=32M app/Http/Controllers
# GLOBAL CONFIG
phpcs -i
phpcs --config-show
phpcs --config-set default_standard PSR2
phpcs --config-set tab_width 4
phpcs --config-set show_progress 1
phpcs --config-set encoding utf-8
phpcs --config-set colors 1
phpcs --config-show
# ######################################
# PHP Code Beautifier and Fixer (PHPCBF)
# ######################################
phpcbf --standard=PSR2 --tab-width=4 --encoding=utf-8 --report=source -sp Controller.php
phpcbf --standard=PSR2 --tab-width=4 --encoding=utf-8 --report=summary -sp Controller.php
phpcbf --standard=PSR2 --tab-width=4 --encoding=utf-8 --report=diff -vv -sp -n -d memory_limit=32M app/Http/Controllers
# #########################
# PHPMD - PHP Mess Detector
# #########################
phpmd IndexController.php,ResponseController.php text cleancode,codesize,controversial,design,naming,unusedcode
phpmd IndexController.php,ResponseController.php text cleancode,codesize,controversial,design,naming,unusedcode --reportfile messdetector.html
phpmd IndexController.php,ResponseController.php html cleancode,codesize,controversial,design,naming,unusedcode --reportfile messdetector.html --exclude tests
# ################################
# PHP Copy/Paste Detector (PHPCPD)
# ################################
phpcpd --progress -n --min-lines 4 --min-tokens 40 app/Http/Controllers
phpcpd --progress --min-lines 2 --suffixes php,php7 --min-tokens 40 app/Http/Controllers
phpcpd --no-interaction --ansi --min-tokens=2 IndexController.php ResponseController.php
# ########
# PHP LINT
# ########
php -l -d display_errors=On IndexController.php | grep '^Errors parsing'
php -l -d display_errors=On IndexController.php | head -1
php -l -d display_errors=On IndexController.php | grep '^Parse error'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment