back to basics - php_codesniffer

Download Back to basics - PHP_Codesniffer

If you can't read please download the document

Upload: sebastian-marek

Post on 16-Apr-2017

2.211 views

Category:

Technology


1 download

TRANSCRIPT

School Presentation Template

Back to basics

PHP_Codesniffer

Sebastian Marek

Control your code

Keep it clean & tidy

Avoid duplications

Minimize bugs numbers

Minimize complexity

Increase performance

Right tools for the job

Keep it clean & tidy (PHP_Codesniffer)

Avoid duplications (phpcpd)

Minimize bugs numbers (PHPUnit)

Minimize complexity (pdepend)

Increase performance (phpmd)

PHP_Codesniffer

Static code analysis

parse the code without executing it

syntax checks

coding standards

Tokenizer

http://uk2.php.net/manual/en/book.tokenizer.php

Tokenize the code

T_OPEN_TAG

Changing reporting format to checkstyle report

Quick user guide

#> phpcs --standard=Zend --report=svnblame library/Zend/Auth.php

PHP CODE SNIFFER SVN BLAME SUMMARY--------------------------------------------------------------------------------AUTHOR (Author %) (Overall %) COUNT--------------------------------------------------------------------------------darby (1.91) (50) 3bkarwin (0) (33.33) 2ralph (16.67) (16.67) 1--------------------------------------------------------------------------------A TOTAL OF 6 SNIFF VIOLATION(S) WERE COMMITTED BY 3 AUTHOR(S)--------------------------------------------------------------------------------

Time: 3 seconds, Memory: 4.25Mb

Changing reporting format to svnblame report

Understanding the sniffs

CodeSniffer - Standards - Zend - Sniffs - NamingConventions - ValidVariableNameSniff.php - Files - ClosingTagSniff.php - Debug - CodeAnalyzerSniff.php

Including existing sniffs

CodeSniffer/Standards/Zend/Sniffs/ruleset.xml

A coding standard based on an early Zend Framework coding standard. Note that this standard is out of date.

Overriding sniffs options

CodeSniffer/Standards/Zend/Sniffs/ruleset.xml

A coding standard based on an early Zend Framework coding standard. Note that this standard is out of date.

Customizing sniffs

CodeSniffer/Standards/Zend/Sniffs/ruleset.xml

A coding standard based on an early Zend Framework coding standard. Note that this standard is out of date.

Ten komentarz wymaga dalszych zmian: %s 3

Closure Linter support

Closure Linter installation

#> sudo easy_install http://closure-linter.googlecode.com/files/closure_linter-latest.tar.gz

PHP_Codesniffer integration

#> phpcs --config-set gjslint_path /usr/local/bin/gjslint#> phpcs --standard=Squiz ~/git/LegacyCodebase/data/mis/doc_root/latest/assets/bookmark.js

FILE: /Volumes/git/LegacyCodebase/data/mis/doc_root/latest/assets/bookmark.js--------------------------------------------------------------------------------FOUND 6 ERROR(S) AFFECTING 5 LINE(S)-------------------------------------------------------------------------------- 1 | ERROR | Missing file doc comment 1 | ERROR | Equals sign not aligned with surrounding assignments; expected 3 | | spaces but found 1 space 4 | ERROR | Opening brace should be on a new line 5 | ERROR | Operator == prohibited; use === instead 7 | ERROR | Operator == prohibited; use === instead 12 | ERROR | Expected 1 blank line before closing function brace; 0 found--------------------------------------------------------------------------------

Time: 0 seconds, Memory: 8.25Mb

PHPUnderControl integration

PHP CodeBrowser integration

Hudson integration

Sonar integration

Resources

Squiz Labs blog - http://www.squizlabs.com/php-codesniffer

PHP_CodeSniffer homepage - http://pear.php.net/package/PHP_CodeSniffer

Closure Linter - http://code.google.com/closure/utilities/docs/linter_howto.html

PHP CodeBrowser - https://github.com/mayflowergmbh/PHP_CodeBrowser

PHPUnderControl - http://phpundercontrol.org/

Hudson - http://hudson-ci.org/

Sonar - http://docs.codehaus.org/display/SONAR/PHP+Plugin

Q&A

?