Follow this topic:
@rjsmelo
PHP Quality Assurance
RICARDO MELO
PHPLX Meetup - July 2014
@rjsmelo 2
RICARDO MELO
●
CTO @ DRI
●
PHP, Mysql, Linux and lots of other
OSS
●
ZCE, RHCE, LPI 3, ITIL, etc
●
+10 years bu...
@rjsmelo 3
About
●
14 Year old academic spin-off
●
Pragmatic OSS Orientation
●
PHP, Mysql, SugarCRM, Drupal,
JavaScript, L...
1999 - 2014 DRI. Some Rights Reserved. 4
Outline
●
Quality Assurance
●
PHP QA Tools
– Phpcpd, phpmd, pdepend, phploc, phpc...
1999 - 2014 DRI. Some Rights Reserved. 5
Quality Assurance
Credits: https://www.flickr.com/photos/blondinrikard/13035892635
1999 - 2014 DRI. Some Rights Reserved. 6
phpcpd
●
phpcpd is a Copy/Paste Detector (CPD) for PHP code. It
scans a PHP proje...
1999 - 2014 DRI. Some Rights Reserved. 7
phpmd
●
phpmd scans PHP source code and looks for potential
problems such as poss...
1999 - 2014 DRI. Some Rights Reserved. 8
pdepend
●
pdepend can generate a large set of software metrics from
a given code ...
1999 - 2014 DRI. Some Rights Reserved. 9
pdepend – output example
1999 - 2014 DRI. Some Rights Reserved. 10
pdepend – output example
1999 - 2014 DRI. Some Rights Reserved. 11
phploc
●
phploc is a tool for quickly measuring the size of a PHP
project.
[vagr...
1999 - 2014 DRI. Some Rights Reserved. 12
phpcs
●
phpcs tokenizes PHP, JavaScript and CSS files and
detects violations of ...
1999 - 2014 DRI. Some Rights Reserved. 13
phpdcd
●
phpdcd is a Dead Code Detector (DCD) for PHP code. It
scans a PHP proje...
1999 - 2014 DRI. Some Rights Reserved. 14
phpdox
●
phpDox is the documentation generator for PHP projects.
This includes, ...
1999 - 2014 DRI. Some Rights Reserved. 15
PHPUnit
●
PHPUnit is the de-facto standard for unit testing in PHP
projects. It ...
1999 - 2014 DRI. Some Rights Reserved. 16
Jenkins
1999 - 2014 DRI. Some Rights Reserved. 17
Quick How-To
●
http://jenkins-php.org/
– Install plugins
– Orchestrate the tools...
1999 - 2014 DRI. Some Rights Reserved. 18
Jenkins Demo
●
Demo
●
Vagrant box with PHP QA tools installed available at
https...
Thank you
Follow this topic:
@rjsmelo
QA
www.dri-global.com
@rjsmelo
ricardo.melo@dri-global.com
Próxima SlideShare
Cargando en…5
×

PHP QA Tools

1.494 visualizaciones

Publicado el

Doing Quality Assurance in PHP projects sometimes looks like a dark art! Picking the right tools, making all tools work together, analysing your code and even then deliver all the required features of the software project can be quite challenging.

This talks aims to help lowering the entry barrier for doing QA on your project, sharing the experience, knowledge and some tricks that brings QA back from the dark arts to the every day of a PHP programmer.

We will review tools like Jenkins, PHPUnit, phpcs, pdepend, phpcpd, etc and how we can chain them together to make sure we are building a great software.

Publicado en: Tecnología
1 comentario
4 recomendaciones
Estadísticas
Notas
Sin descargas
Visualizaciones
Visualizaciones totales
1.494
En SlideShare
0
De insertados
0
Número de insertados
4
Acciones
Compartido
0
Descargas
20
Comentarios
1
Recomendaciones
4
Insertados 0
No insertados

No hay notas en la diapositiva.

PHP QA Tools

  1. 1. Follow this topic: @rjsmelo PHP Quality Assurance RICARDO MELO PHPLX Meetup - July 2014
  2. 2. @rjsmelo 2 RICARDO MELO ● CTO @ DRI ● PHP, Mysql, Linux and lots of other OSS ● ZCE, RHCE, LPI 3, ITIL, etc ● +10 years building (and breaking) things
  3. 3. @rjsmelo 3 About ● 14 Year old academic spin-off ● Pragmatic OSS Orientation ● PHP, Mysql, SugarCRM, Drupal, JavaScript, Linux, etc. ● Crafters, Integrators ● Always looking for software developers – Yes, right now!
  4. 4. 1999 - 2014 DRI. Some Rights Reserved. 4 Outline ● Quality Assurance ● PHP QA Tools – Phpcpd, phpmd, pdepend, phploc, phpcs, phpdcd, phpdox – PHPUnit ● Build Servers – Jenkins
  5. 5. 1999 - 2014 DRI. Some Rights Reserved. 5 Quality Assurance Credits: https://www.flickr.com/photos/blondinrikard/13035892635
  6. 6. 1999 - 2014 DRI. Some Rights Reserved. 6 phpcpd ● phpcpd is a Copy/Paste Detector (CPD) for PHP code. It scans a PHP project for duplicated code. [root@localhost sut]# phpcpd wordpress/ phpcpd 2.0.1 by Sebastian Bergmann. Found 46 exact clones with 1571 duplicated lines in 26 files: - /vagrant/sut/wordpress/wp-admin/includes/class-ftp-pure.php:103-118 /vagrant/sut/wordpress/wp-admin/includes/class-ftp-sockets.php:123-138 - /vagrant/sut/wordpress/wp-admin/includes/class-wp-filesystem-ftpext.php:37-60 /vagrant/sut/wordpress/wp-admin/includes/class-wp-filesystem-ftpsockets.php:31-54 - /vagrant/sut/wordpress/wp-admin/includes/class-wp-filesystem-ftpext.php:184-212 /vagrant/sut/wordpress/wp-admin/includes/class-wp-filesystem-ftpsockets.php:190-218 - /vagrant/sut/wordpress/wp-admin/includes/class-wp-filesystem-direct.php:347-383 /vagrant/sut/wordpress/wp-admin/includes/class-wp-filesystem-ssh2.php:354-390
  7. 7. 1999 - 2014 DRI. Some Rights Reserved. 7 phpmd ● phpmd scans PHP source code and looks for potential problems such as possible bugs, dead code, suboptimal code, and overcomplicated expressions [root@localhost sut]# phpmd wp-admin text cleancode,codesize,controversial,design,naming,unusedcode /dev/shm/workpress/wordpress/wp-admin/comment.php:40 The function comment_footer_die() contains an exit expression. /dev/shm/workpress/wordpress/wp-admin/credits.php:23 The variable $wp_version is not named in camelCase. /dev/shm/workpress/wordpress/wp-admin/credits.php:23 The variable $wp_version is not named in camelCase. /dev/shm/workpress/wordpress/wp-admin/credits.php:23 The variable $wp_version is not named in camelCase. /dev/shm/workpress/wordpress/wp-admin/custom-background.php:53 Avoid excessively long variable names like $admin_header_callback. Keep variable name length under 20. /dev/shm/workpress/wordpress/wp-admin/custom-background.php:53 Avoid excessively long variable names like $admin_image_div_callback. Keep variable name length under 20. /dev/shm/workpress/wordpress/wp-admin/custom-background.php:85 The method admin_load is not named in camelCase. /dev/shm/workpress/wordpress/wp-admin/custom-background.php:112 The method take_action() has a Cyclomatic Complexity of 13. The configured cyclomatic complexity threshold is 10. /dev/shm/workpress/wordpress/wp-admin/custom-background.php:112 The method take_action() has an NPath complexity of 864. The configured NPath complexity threshold is 200.
  8. 8. 1999 - 2014 DRI. Some Rights Reserved. 8 pdepend ● pdepend can generate a large set of software metrics from a given code base. These values can be used to measure the quality of a software project and they help to identify the parts of an application where a code refactoring should be applied. pdepend --summary-xml=/tmp/summary.xml --jdepend-chart=/tmp/jdepend.svg --overview-pyramid=/tmp/pyramid.svg wp-admin PDepend 2.0.0 Parsing source files: ............................................................ 60 ............................................................ 120 ......................................................... 177 Calculating Cyclomatic Complexity metrics: ............................................................ 1200 ........................ 1695 Calculating Node Loc metrics: ............................................................ 1200 .................. 1579
  9. 9. 1999 - 2014 DRI. Some Rights Reserved. 9 pdepend – output example
  10. 10. 1999 - 2014 DRI. Some Rights Reserved. 10 pdepend – output example
  11. 11. 1999 - 2014 DRI. Some Rights Reserved. 11 phploc ● phploc is a tool for quickly measuring the size of a PHP project. [vagrant@localhost wordpress]$ phploc wp-admin/ phploc 2.0.6 by Sebastian Bergmann. Directories 4 Files 177 Size Lines of Code (LOC) 72137 Comment Lines of Code (CLOC) 16702 (23.15%) Non-Comment Lines of Code (NCLOC) 55435 (76.85%) Logical Lines of Code (LLOC) 21517 (29.83%) Classes 6804 (31.62%) Average Class Length 133 Average Method Length 9 Functions 8134 (37.80%) Average Function Length 11 Not in classes or functions 6579 (30.58%)
  12. 12. 1999 - 2014 DRI. Some Rights Reserved. 12 phpcs ● phpcs tokenizes PHP, JavaScript and CSS files and detects violations of a defined set of coding standards. It is an essential development tool that ensures your code remains clean and consistent. It can also help prevent some common semantic errors made by developers. $ phpcs src/ FILE: /vagrant/sut/phpunit/src/Extensions/GroupTestSuite.php -------------------------------------------------------------------------------- FOUND 7 ERROR(S) AND 2 WARNING(S) AFFECTING 8 LINE(S) -------------------------------------------------------------------------------- 44 | WARNING | PHP version not specified 44 | ERROR | Missing @category tag in file comment 52 | ERROR | There must be exactly one blank line before the tags in class | | comments 65 | ERROR | Missing @category tag in class comment 68 | ERROR | Missing function doc comment 74 | WARNING | Line exceeds 85 characters; contains 91 characters 79 | ERROR | Multi-line function call not indented correctly; expected 12 | | spaces but found 10 80 | ERROR | Multi-line function call not indented correctly; expected 12 | | spaces but found 10 86 | ERROR | Multi-line function call not indented correctly; expected 20 | | spaces but found 18 --------------------------------------------------------------------------------
  13. 13. 1999 - 2014 DRI. Some Rights Reserved. 13 phpdcd ● phpdcd is a Dead Code Detector (DCD) for PHP code. It scans a PHP project for code that is no longer used. $ phpdcd src/ phpdcd 1.0.2 by Sebastian Bergmann. - PHPUnit_Extensions_GroupTestSuite::__construct() LOC: 31, declared in /vagrant/sut/phpunit/src/Extensions/GroupTestSuite.php:68 - PHPUnit_Extensions_PhptTestCase::count() LOC: 4, declared in /vagrant/sut/phpunit/src/Extensions/PhptTestCase.php:120 - PHPUnit_Extensions_PhptTestCase::getName() LOC: 4, declared in /vagrant/sut/phpunit/src/Extensions/PhptTestCase.php:194 - PHPUnit_Extensions_PhptTestCase::run() LOC: 57, declared in /vagrant/sut/phpunit/src/Extensions/PhptTestCase.php:131
  14. 14. 1999 - 2014 DRI. Some Rights Reserved. 14 phpdox ● phpDox is the documentation generator for PHP projects. This includes, but is not limited to, API documentation. [root@localhost phpunit]# phpdox phpDox %development% - Copyright (C) 2010 - 2014 by Arne Blankerts [23.07.2014 - 19:03:23] Using config file './phpdox.xml.dist' [23.07.2014 - 19:03:23] Registered enricher 'build' [23.07.2014 - 19:03:23] Registered enricher 'git' [23.07.2014 - 19:03:23] Registered enricher 'checkstyle' [23.07.2014 - 19:03:23] Registered enricher 'pmd' [23.07.2014 - 19:03:23] Registered enricher 'phpunit' [23.07.2014 - 19:03:23] Registered enricher 'phploc' [23.07.2014 - 19:03:23] Registered output engine 'xml' [23.07.2014 - 19:03:23] Registered output engine 'html' [23.07.2014 - 19:03:23] Starting to process project 'PHPUnit' [23.07.2014 - 19:03:23] Starting collector [23.07.2014 - 19:03:23] Scanning directory 'src' for files to process ..................................................[50] ..................................................[100] ................... [119]
  15. 15. 1999 - 2014 DRI. Some Rights Reserved. 15 PHPUnit ● PHPUnit is the de-facto standard for unit testing in PHP projects. It provides both a framework that makes the writing of tests easy as well as the functionality to easily run the tests and analyze their results. [root@localhost phpunit]# phpunit PHPUnit 4.3-ge243de0 by Sebastian Bergmann. Configuration read from /vagrant/sut/phpunit/phpunit.xml.dist ............................................................. 61 / 1295 ( 4%) ............................................................. 122 / 1295 ( 9%) ............................................................. 183 / 1295 ( 14%) ............................................................. 244 / 1295 ( 18%) ............................................................. 305 / 1295 ( 23%) ............................................................. 366 / 1295 ( 28%)
  16. 16. 1999 - 2014 DRI. Some Rights Reserved. 16 Jenkins
  17. 17. 1999 - 2014 DRI. Some Rights Reserved. 17 Quick How-To ● http://jenkins-php.org/ – Install plugins – Orchestrate the tools – Configure the tools – Create a Job
  18. 18. 1999 - 2014 DRI. Some Rights Reserved. 18 Jenkins Demo ● Demo ● Vagrant box with PHP QA tools installed available at https://github.com/rjsmelo/vagrant-phpqa
  19. 19. Thank you
  20. 20. Follow this topic: @rjsmelo QA
  21. 21. www.dri-global.com @rjsmelo ricardo.melo@dri-global.com

×