php qa tools - kurakin · 2014-09-09 · php lint - syntax check checks php code for syntax errors...
TRANSCRIPT
![Page 1: PHP QA TOOLS - Kurakin · 2014-09-09 · PHP Lint - syntax check Checks PHP code for syntax errors Built-in into PHP binary $ php -l path/to/file.php](https://reader030.vdocuments.site/reader030/viewer/2022040611/5ed7075262136e72fb7bb2ed/html5/thumbnails/1.jpg)
PHP QA TOOLSPHP Code Quality
Sergej Kurakin
![Page 2: PHP QA TOOLS - Kurakin · 2014-09-09 · PHP Lint - syntax check Checks PHP code for syntax errors Built-in into PHP binary $ php -l path/to/file.php](https://reader030.vdocuments.site/reader030/viewer/2022040611/5ed7075262136e72fb7bb2ed/html5/thumbnails/2.jpg)
Why?
● New project● Clean modern code base● Many developers● New challenge
![Page 3: PHP QA TOOLS - Kurakin · 2014-09-09 · PHP Lint - syntax check Checks PHP code for syntax errors Built-in into PHP binary $ php -l path/to/file.php](https://reader030.vdocuments.site/reader030/viewer/2022040611/5ed7075262136e72fb7bb2ed/html5/thumbnails/3.jpg)
What?
● PSR Code Style● Minimize Copy/Paste● Reduce Code Complexity● Tests...
![Page 4: PHP QA TOOLS - Kurakin · 2014-09-09 · PHP Lint - syntax check Checks PHP code for syntax errors Built-in into PHP binary $ php -l path/to/file.php](https://reader030.vdocuments.site/reader030/viewer/2022040611/5ed7075262136e72fb7bb2ed/html5/thumbnails/4.jpg)
T_PAAMAYIM_NEKUDOTAYIM
![Page 5: PHP QA TOOLS - Kurakin · 2014-09-09 · PHP Lint - syntax check Checks PHP code for syntax errors Built-in into PHP binary $ php -l path/to/file.php](https://reader030.vdocuments.site/reader030/viewer/2022040611/5ed7075262136e72fb7bb2ed/html5/thumbnails/5.jpg)
PHP Lint - syntax check
● Checks PHP code for syntax errors● Built-in into PHP binary
$ php -l path/to/file.php
![Page 6: PHP QA TOOLS - Kurakin · 2014-09-09 · PHP Lint - syntax check Checks PHP code for syntax errors Built-in into PHP binary $ php -l path/to/file.php](https://reader030.vdocuments.site/reader030/viewer/2022040611/5ed7075262136e72fb7bb2ed/html5/thumbnails/6.jpg)
Code Style
![Page 7: PHP QA TOOLS - Kurakin · 2014-09-09 · PHP Lint - syntax check Checks PHP code for syntax errors Built-in into PHP binary $ php -l path/to/file.php](https://reader030.vdocuments.site/reader030/viewer/2022040611/5ed7075262136e72fb7bb2ed/html5/thumbnails/7.jpg)
![Page 8: PHP QA TOOLS - Kurakin · 2014-09-09 · PHP Lint - syntax check Checks PHP code for syntax errors Built-in into PHP binary $ php -l path/to/file.php](https://reader030.vdocuments.site/reader030/viewer/2022040611/5ed7075262136e72fb7bb2ed/html5/thumbnails/8.jpg)
![Page 9: PHP QA TOOLS - Kurakin · 2014-09-09 · PHP Lint - syntax check Checks PHP code for syntax errors Built-in into PHP binary $ php -l path/to/file.php](https://reader030.vdocuments.site/reader030/viewer/2022040611/5ed7075262136e72fb7bb2ed/html5/thumbnails/9.jpg)
PHP Code Sniffer
● Detects coding standard violations● https://github.
com/squizlabs/PHP_CodeSniffer● Composer/PEAR
Interesting side project: http://squizlabs.github.io/PHP_CodeSniffer/analysis/
![Page 10: PHP QA TOOLS - Kurakin · 2014-09-09 · PHP Lint - syntax check Checks PHP code for syntax errors Built-in into PHP binary $ php -l path/to/file.php](https://reader030.vdocuments.site/reader030/viewer/2022040611/5ed7075262136e72fb7bb2ed/html5/thumbnails/10.jpg)
PHP Code Sniffer: Run
$ phpcs path/to/file.php
$ phpcs path/to/dir
$ phpcs -h
$ phpcs -i
![Page 11: PHP QA TOOLS - Kurakin · 2014-09-09 · PHP Lint - syntax check Checks PHP code for syntax errors Built-in into PHP binary $ php -l path/to/file.php](https://reader030.vdocuments.site/reader030/viewer/2022040611/5ed7075262136e72fb7bb2ed/html5/thumbnails/11.jpg)
PHP Code Sniffer: Keys
--sniffs=<sniffs>
--encoding=<encoding>
--extensions=<extensions>
--ignore=<patterns>
--standard=<standard>
![Page 12: PHP QA TOOLS - Kurakin · 2014-09-09 · PHP Lint - syntax check Checks PHP code for syntax errors Built-in into PHP binary $ php -l path/to/file.php](https://reader030.vdocuments.site/reader030/viewer/2022040611/5ed7075262136e72fb7bb2ed/html5/thumbnails/12.jpg)
PHP Code Sniffer: Standards
● PEAR● PHPCS● PSR1● PSR2● Squiz● Zend
![Page 13: PHP QA TOOLS - Kurakin · 2014-09-09 · PHP Lint - syntax check Checks PHP code for syntax errors Built-in into PHP binary $ php -l path/to/file.php](https://reader030.vdocuments.site/reader030/viewer/2022040611/5ed7075262136e72fb7bb2ed/html5/thumbnails/13.jpg)
PHP Code Sniffer: Reports
● full● xml● checkstyle● csv● json● emacs
● source● summary● svnblame● gitblame● hgblame● notifysend
![Page 14: PHP QA TOOLS - Kurakin · 2014-09-09 · PHP Lint - syntax check Checks PHP code for syntax errors Built-in into PHP binary $ php -l path/to/file.php](https://reader030.vdocuments.site/reader030/viewer/2022040611/5ed7075262136e72fb7bb2ed/html5/thumbnails/14.jpg)
Copy & Paste
![Page 15: PHP QA TOOLS - Kurakin · 2014-09-09 · PHP Lint - syntax check Checks PHP code for syntax errors Built-in into PHP binary $ php -l path/to/file.php](https://reader030.vdocuments.site/reader030/viewer/2022040611/5ed7075262136e72fb7bb2ed/html5/thumbnails/15.jpg)
![Page 16: PHP QA TOOLS - Kurakin · 2014-09-09 · PHP Lint - syntax check Checks PHP code for syntax errors Built-in into PHP binary $ php -l path/to/file.php](https://reader030.vdocuments.site/reader030/viewer/2022040611/5ed7075262136e72fb7bb2ed/html5/thumbnails/16.jpg)
![Page 17: PHP QA TOOLS - Kurakin · 2014-09-09 · PHP Lint - syntax check Checks PHP code for syntax errors Built-in into PHP binary $ php -l path/to/file.php](https://reader030.vdocuments.site/reader030/viewer/2022040611/5ed7075262136e72fb7bb2ed/html5/thumbnails/17.jpg)
PHP Copy/Paste Detector
● CPD - Copy/Paste (code) Detector● https://github.
com/sebastianbergmann/phpcpd● Composer/PHAR
![Page 18: PHP QA TOOLS - Kurakin · 2014-09-09 · PHP Lint - syntax check Checks PHP code for syntax errors Built-in into PHP binary $ php -l path/to/file.php](https://reader030.vdocuments.site/reader030/viewer/2022040611/5ed7075262136e72fb7bb2ed/html5/thumbnails/18.jpg)
PHP Copy/Paste Detector: Run
$ phpcpd path/to/file.php path/to/other/file.php$ phpcpd path/to/dir
$phpcpd -h
![Page 19: PHP QA TOOLS - Kurakin · 2014-09-09 · PHP Lint - syntax check Checks PHP code for syntax errors Built-in into PHP binary $ php -l path/to/file.php](https://reader030.vdocuments.site/reader030/viewer/2022040611/5ed7075262136e72fb7bb2ed/html5/thumbnails/19.jpg)
PHP Copy/Paste Detector: Keys
--names=<names>--names-exclude=<names-exclude>--exclude=<exclude>--log-pmd--min-lines=<5>--min-tokens=<70>
![Page 20: PHP QA TOOLS - Kurakin · 2014-09-09 · PHP Lint - syntax check Checks PHP code for syntax errors Built-in into PHP binary $ php -l path/to/file.php](https://reader030.vdocuments.site/reader030/viewer/2022040611/5ed7075262136e72fb7bb2ed/html5/thumbnails/20.jpg)
Mess
![Page 21: PHP QA TOOLS - Kurakin · 2014-09-09 · PHP Lint - syntax check Checks PHP code for syntax errors Built-in into PHP binary $ php -l path/to/file.php](https://reader030.vdocuments.site/reader030/viewer/2022040611/5ed7075262136e72fb7bb2ed/html5/thumbnails/21.jpg)
![Page 22: PHP QA TOOLS - Kurakin · 2014-09-09 · PHP Lint - syntax check Checks PHP code for syntax errors Built-in into PHP binary $ php -l path/to/file.php](https://reader030.vdocuments.site/reader030/viewer/2022040611/5ed7075262136e72fb7bb2ed/html5/thumbnails/22.jpg)
PHP Mess Detector
● Source Code Analyzer● http://phpmd.org/● Composer
![Page 23: PHP QA TOOLS - Kurakin · 2014-09-09 · PHP Lint - syntax check Checks PHP code for syntax errors Built-in into PHP binary $ php -l path/to/file.php](https://reader030.vdocuments.site/reader030/viewer/2022040611/5ed7075262136e72fb7bb2ed/html5/thumbnails/23.jpg)
PHP Mess Detector: Run
$ phpmd path/to/dir text cleancode,codesize,controversial,design,naming,unusedcode
$ phpmd path/to/dir text path/to/ruleset.xml
![Page 24: PHP QA TOOLS - Kurakin · 2014-09-09 · PHP Lint - syntax check Checks PHP code for syntax errors Built-in into PHP binary $ php -l path/to/file.php](https://reader030.vdocuments.site/reader030/viewer/2022040611/5ed7075262136e72fb7bb2ed/html5/thumbnails/24.jpg)
PHP Mess Detector: Reports
● xml● text● html
![Page 25: PHP QA TOOLS - Kurakin · 2014-09-09 · PHP Lint - syntax check Checks PHP code for syntax errors Built-in into PHP binary $ php -l path/to/file.php](https://reader030.vdocuments.site/reader030/viewer/2022040611/5ed7075262136e72fb7bb2ed/html5/thumbnails/25.jpg)
PHP Mess Detector: Rulesets
● cleancode● codesize● controversial● design● naming● unusedcode
![Page 26: PHP QA TOOLS - Kurakin · 2014-09-09 · PHP Lint - syntax check Checks PHP code for syntax errors Built-in into PHP binary $ php -l path/to/file.php](https://reader030.vdocuments.site/reader030/viewer/2022040611/5ed7075262136e72fb7bb2ed/html5/thumbnails/26.jpg)
Unused Code
![Page 27: PHP QA TOOLS - Kurakin · 2014-09-09 · PHP Lint - syntax check Checks PHP code for syntax errors Built-in into PHP binary $ php -l path/to/file.php](https://reader030.vdocuments.site/reader030/viewer/2022040611/5ed7075262136e72fb7bb2ed/html5/thumbnails/27.jpg)
![Page 28: PHP QA TOOLS - Kurakin · 2014-09-09 · PHP Lint - syntax check Checks PHP code for syntax errors Built-in into PHP binary $ php -l path/to/file.php](https://reader030.vdocuments.site/reader030/viewer/2022040611/5ed7075262136e72fb7bb2ed/html5/thumbnails/28.jpg)
PHP Dead Code Detector
● Unused/Dead Code Detector● https://github.
com/sebastianbergmann/phpdcd● Composer/PHAR
![Page 29: PHP QA TOOLS - Kurakin · 2014-09-09 · PHP Lint - syntax check Checks PHP code for syntax errors Built-in into PHP binary $ php -l path/to/file.php](https://reader030.vdocuments.site/reader030/viewer/2022040611/5ed7075262136e72fb7bb2ed/html5/thumbnails/29.jpg)
PHP Dead Code Detector
$ phpdcd path/to/file.php
$ phpdcd path/to/dir
$phpdcd -h
![Page 30: PHP QA TOOLS - Kurakin · 2014-09-09 · PHP Lint - syntax check Checks PHP code for syntax errors Built-in into PHP binary $ php -l path/to/file.php](https://reader030.vdocuments.site/reader030/viewer/2022040611/5ed7075262136e72fb7bb2ed/html5/thumbnails/30.jpg)
Code Statistics
![Page 31: PHP QA TOOLS - Kurakin · 2014-09-09 · PHP Lint - syntax check Checks PHP code for syntax errors Built-in into PHP binary $ php -l path/to/file.php](https://reader030.vdocuments.site/reader030/viewer/2022040611/5ed7075262136e72fb7bb2ed/html5/thumbnails/31.jpg)
![Page 32: PHP QA TOOLS - Kurakin · 2014-09-09 · PHP Lint - syntax check Checks PHP code for syntax errors Built-in into PHP binary $ php -l path/to/file.php](https://reader030.vdocuments.site/reader030/viewer/2022040611/5ed7075262136e72fb7bb2ed/html5/thumbnails/32.jpg)
phploc
● Size and Analytics● https://github.
com/sebastianbergmann/phploc● Composer/PHAR
![Page 33: PHP QA TOOLS - Kurakin · 2014-09-09 · PHP Lint - syntax check Checks PHP code for syntax errors Built-in into PHP binary $ php -l path/to/file.php](https://reader030.vdocuments.site/reader030/viewer/2022040611/5ed7075262136e72fb7bb2ed/html5/thumbnails/33.jpg)
phploc: Run
$ phploc path/to/dir
$ phploc -h
![Page 34: PHP QA TOOLS - Kurakin · 2014-09-09 · PHP Lint - syntax check Checks PHP code for syntax errors Built-in into PHP binary $ php -l path/to/file.php](https://reader030.vdocuments.site/reader030/viewer/2022040611/5ed7075262136e72fb7bb2ed/html5/thumbnails/34.jpg)
phploc: Keys
--names
--names-exclude
--git-repository
--log-csv=<path/to/file.csv>
--log-xml=<path/to/file.xml>
![Page 35: PHP QA TOOLS - Kurakin · 2014-09-09 · PHP Lint - syntax check Checks PHP code for syntax errors Built-in into PHP binary $ php -l path/to/file.php](https://reader030.vdocuments.site/reader030/viewer/2022040611/5ed7075262136e72fb7bb2ed/html5/thumbnails/35.jpg)
![Page 36: PHP QA TOOLS - Kurakin · 2014-09-09 · PHP Lint - syntax check Checks PHP code for syntax errors Built-in into PHP binary $ php -l path/to/file.php](https://reader030.vdocuments.site/reader030/viewer/2022040611/5ed7075262136e72fb7bb2ed/html5/thumbnails/36.jpg)
PHP Depend
● Software Metrics● http://pdepend.org/● http://pdepend.org/documentation/software-
metrics/index.html● Composer/PHAR/PEAR
![Page 37: PHP QA TOOLS - Kurakin · 2014-09-09 · PHP Lint - syntax check Checks PHP code for syntax errors Built-in into PHP binary $ php -l path/to/file.php](https://reader030.vdocuments.site/reader030/viewer/2022040611/5ed7075262136e72fb7bb2ed/html5/thumbnails/37.jpg)
PHP Depend: Run
$ pdepend \
--summary-xml=/tmp/summary.xml \
--jdepend-chart=/tmp/jdepend.svg \
--overview-pyramid=/tmp/pyramid.svg \
path/to/dir
![Page 38: PHP QA TOOLS - Kurakin · 2014-09-09 · PHP Lint - syntax check Checks PHP code for syntax errors Built-in into PHP binary $ php -l path/to/file.php](https://reader030.vdocuments.site/reader030/viewer/2022040611/5ed7075262136e72fb7bb2ed/html5/thumbnails/38.jpg)
Tests...
![Page 39: PHP QA TOOLS - Kurakin · 2014-09-09 · PHP Lint - syntax check Checks PHP code for syntax errors Built-in into PHP binary $ php -l path/to/file.php](https://reader030.vdocuments.site/reader030/viewer/2022040611/5ed7075262136e72fb7bb2ed/html5/thumbnails/39.jpg)
![Page 40: PHP QA TOOLS - Kurakin · 2014-09-09 · PHP Lint - syntax check Checks PHP code for syntax errors Built-in into PHP binary $ php -l path/to/file.php](https://reader030.vdocuments.site/reader030/viewer/2022040611/5ed7075262136e72fb7bb2ed/html5/thumbnails/40.jpg)
Testing Frameworks
● PHPUnit - http://phpunit.de/● Behat - http://behat.org/● Spec - http://www.phpspec.net/● JFGI
![Page 41: PHP QA TOOLS - Kurakin · 2014-09-09 · PHP Lint - syntax check Checks PHP code for syntax errors Built-in into PHP binary $ php -l path/to/file.php](https://reader030.vdocuments.site/reader030/viewer/2022040611/5ed7075262136e72fb7bb2ed/html5/thumbnails/41.jpg)
Weapon of choice
![Page 42: PHP QA TOOLS - Kurakin · 2014-09-09 · PHP Lint - syntax check Checks PHP code for syntax errors Built-in into PHP binary $ php -l path/to/file.php](https://reader030.vdocuments.site/reader030/viewer/2022040611/5ed7075262136e72fb7bb2ed/html5/thumbnails/42.jpg)
Other stuff
![Page 43: PHP QA TOOLS - Kurakin · 2014-09-09 · PHP Lint - syntax check Checks PHP code for syntax errors Built-in into PHP binary $ php -l path/to/file.php](https://reader030.vdocuments.site/reader030/viewer/2022040611/5ed7075262136e72fb7bb2ed/html5/thumbnails/43.jpg)
PhpStorm
Preferences > PHP >Code SnifferMess Detector
Preferences > Inspections
Code > Inspect Code
![Page 44: PHP QA TOOLS - Kurakin · 2014-09-09 · PHP Lint - syntax check Checks PHP code for syntax errors Built-in into PHP binary $ php -l path/to/file.php](https://reader030.vdocuments.site/reader030/viewer/2022040611/5ed7075262136e72fb7bb2ed/html5/thumbnails/44.jpg)
php-cs-fixer
● Fixes coding standards● http://cs.sensiolabs.org/● Composer/PHAR● PSR1 and PSR2 only
$ php-cs-fixer fix path/to/dir --level=all
![Page 45: PHP QA TOOLS - Kurakin · 2014-09-09 · PHP Lint - syntax check Checks PHP code for syntax errors Built-in into PHP binary $ php -l path/to/file.php](https://reader030.vdocuments.site/reader030/viewer/2022040611/5ed7075262136e72fb7bb2ed/html5/thumbnails/45.jpg)
You can find more at http://phpqatools.org/
Big big thanks to Sebastian Bergmann for the work over PHP QA tools collection.
![Page 46: PHP QA TOOLS - Kurakin · 2014-09-09 · PHP Lint - syntax check Checks PHP code for syntax errors Built-in into PHP binary $ php -l path/to/file.php](https://reader030.vdocuments.site/reader030/viewer/2022040611/5ed7075262136e72fb7bb2ed/html5/thumbnails/46.jpg)
Questions?
Sergej Kurakin
Email: [email protected]: @zaza_lt
Special thanks to authors of all pictures used in this presentation.