21
Follow this topic: @rjsmelo PHP Quality Assurance R I C A R D O M E L O P H P L X M e e t u p - J u l y 2 0 1 4

PHP QA Tools

  • Upload
    rjsmelo

  • View
    383

  • Download
    1

Embed Size (px)

Citation preview

Page 1: PHP QA Tools

Follow this topic:

@rjsmelo

PHP Quality Assurance

R ICARDO MELO

PHPLX Meetup - July 2014

Page 2: PHP QA Tools

@rjsmelo 2

RICARDO MELO

●CTO @ DR I● PHP, Mysql, Linux and lots of other OSS

● ZCE, RHCE, LPI 3, ITIL, etc● +10 years building (and breaking) things

Page 3: PHP QA Tools

@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!

Page 4: PHP QA Tools

1999 - 2014 DRI. Some Rights Reserved. 4

Outline

● Quality Assurance● PHP QA Tools

– Phpcpd, phpmd, pdepend, phploc, phpcs, phpdcd, phpdox– PHPUnit

● Build Servers– Jenkins

Page 5: PHP QA Tools

1999 - 2014 DRI. Some Rights Reserved. 5

Quality Assurance

Credits: https://www.flickr.com/photos/blondinrikard/13035892635

Page 6: PHP QA Tools

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

Page 7: PHP QA Tools

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.

Page 8: PHP QA Tools

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

Page 9: PHP QA Tools

1999 - 2014 DRI. Some Rights Reserved. 9

pdepend – output example

Page 10: PHP QA Tools

1999 - 2014 DRI. Some Rights Reserved. 10

pdepend – output example

Page 11: PHP QA Tools

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 4Files 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%)

Page 12: PHP QA Tools

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--------------------------------------------------------------------------------

Page 13: PHP QA Tools

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

Page 14: PHP QA Tools

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]# phpdoxphpDox %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]

Page 15: PHP QA Tools

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]# phpunitPHPUnit 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%)

Page 16: PHP QA Tools

1999 - 2014 DRI. Some Rights Reserved. 16

Jenkins

Page 17: PHP QA Tools

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

Page 18: PHP QA Tools

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

Page 19: PHP QA Tools

Thank you

Page 20: PHP QA Tools

Follow this topic:

@rjsmelo

QA

Page 21: PHP QA Tools

www.dri-global.com

@rjsmelo

[email protected]