• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
How to improve the quality of your TYPO3 extensions
 

How to improve the quality of your TYPO3 extensions

on

  • 5,608 views

My colleague Mike Zaschka and I talking about how tools like PHP Mess Detection, Copy & Paste Detection and CodeSniffer can help you gaining better software quality in TYPO3 extensions. ...

My colleague Mike Zaschka and I talking about how tools like PHP Mess Detection, Copy & Paste Detection and CodeSniffer can help you gaining better software quality in TYPO3 extensions.

2nd October 2010, TYPO3 Conference Frankfurt

Statistics

Views

Total Views
5,608
Views on SlideShare
5,549
Embed Views
59

Actions

Likes
15
Downloads
84
Comments
2

4 Embeds 59

http://christian-trabold.de 43
http://christian-trabold.blogspot.com 8
http://stuff.lime-flavour.de 7
http://www.techgig.com 1

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel

12 of 2 previous next

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    How to improve the quality of your TYPO3 extensions How to improve the quality of your TYPO3 extensions Presentation Transcript

    • How to improve the quality of your TYPO3 extensions Christian Trabold Mike Zaschka 2nd October 2010, TYPO3 Conference Frankfurt
    • Agenda What‘s the problem? High speed code reviews Tools that help you Questions & Answers
    • Dowloads & Feedback We provide links and further information on http://bit.ly/t3con10-qatalk We are listening to you on twitter #t3con10-qatalk Ask! It‘s okay to ask after each chapter and after the talk :) The installation instructions are available in our paper
    • Who are we? http://www.flickr.com/photos/kevenlaw/2684465429/
    • About us Christian Trabold Senior Developer Web since 1999 TYPO3 since 2004 dkd since 2006 Focus on quality assurance Author of TYPO3 Kochbuch, O‘Reilly E-Mail christian.trabold@dkd.de Twitter @ctrabold
    • About us Mike Zaschka Senior Developer TYPO3 since 2005 Ruby/Rails since 2007 dkd since 2008 eMail mike.zaschka@dkd.de Twitter @mike_zaschka
    • What is our problem?
    • We all want a perfect extension TYPO3 API TYPO3 Security cookbook coding standards
    • We all want a perfect extension BUT
    • High complexity Nobody wants to touch it.
    • No documentation Nobody understands it.
    • Different standard Nobody can read it.
    • How do you monitor the quality of many extensions?
    • Doing high speed reviews Code Reviews PHP Mess Detection Copy & Paste Detection CodeSniffer
    • Code Reviews Quality assurance with talking.
    • C ODE REVIEWS SUCK
    • "Most of the time you sit next to a hairy, unfriendly colleage and argue about line indentions..." Mike http://www.flickr.com/photos/octopushat/403730001/
    • And after a while you don't see code anymore! class Example {{ class Example { class Example private static $ID == 1; private static $ID = 1; private $title ==$ID private static "t3con"; 1; private $title = "t3con"; private $title "t3con"; /* /* /* // Some code II don't want to delete // Some code I don't want to delete // Some code don't want to delete public function addNothing($content) {{ public function addNothing($content) { public function addNothing($content) $content == ""; $content = ""; $content ""; return $content; return $content; }} return $content; */} */ */ public function addYear($year) {{ public function addYear($year) { public function addYear($year) return $this->title .. "" 2010"; return $this->title . " 2010"; return $this->title 2010"; }} }} } }
    • Downsides of code reviews You have to search for errors You have no time Most of the time you discuss less important things No sharing of knowledge I hate my colleagues syndrome Do code reviews really ensure quality?
    • Manual code reviews can cause serious damage to your nerves! You might nd your colleagues dead in front of the computer! None of our developers was harmed for this presentation! http://www.flickr.com/photos/jakub_hlavaty/2164581030/
    • Wouldn‘t it be nice... If a code review could be automated? If I could see the aws before I review? Is it a dream or could it be reality?
    • PHP Mess Checks your code against errors and aws.
    • PHP Mess Detection Rules Code size Unused code Complexity Code length Naming Design Methods Eval Variables Inheritance
    • Use PHP Mess Detector Use it on your console like this: $ phpmd . text codesize,unusedcode,naming Report format Rulesets Source path
    • Example code class Example { private static $ID = 1; private $title = "t3con"; /* An unused method */ private function addNothing($content) { $content = ""; return $content; } public function addYear($year) { return $this->title . " 2010"; } public function add_year_2010($year) { return $this->title . " 2010"; } }
    • Detecting the mess $ phpmd example.php text codesize,unusedcode,naming example.php:4 Avoid unused private fields such as '$ID'. example.php:4 Avoid variables with short names like $ID example.php:8 Avoid unused private methods such as 'addNothing'. example.php:13 Avoid unused parameters such as '$year'. example.php:17 Avoid unused parameters such as '$year'.
    • Fixing the code class Example { private static $ID = 1; // Not used / too short private $title = "t3con"; /* An unused method */ private function addNothing($content) { // Not used $content = ""; return $content; } public function addYear($year) { // Not used return $this->title . " 2010"; } public function add_year_2010($year) { // Not used return $this->title . " 2010"; } }
    • Fixing the code class Example { private $title = "t3con"; public function addYear() { return $this->title . " 2010"; } public function add_year_2010() { return $this->title . " 2010"; } }
    • Copy Paste Checks your code for duplicate code.
    • Duplicate code is not a little something! Unnecessary complexity Issues in architecture Hard maintainable code Multiple changes Error prone
    • Back to the example code class Example { private $title = "t3con"; public function addYear() { return $this->title . " 2010"; } public function add_year_2010() { return $this->title . " 2010"; } }
    • Detecting duplicate code You use it on your console like this: $ phpcpd example.php Found 1 exact clones with 2 duplicated lines in 1 files: - example.php:5-6 example.php:9-10
    • Fixing the code class Example { private $title = "t3con"; public function addYear() { return $this->title . " 2010"; // Duplicate code } public function add_year_2010() { return $this->title . " 2010"; // Duplicate code } }
    • Fixing the code class Example { private $title = "t3con"; public function addYear() { return $this->add_year_2010(); } public function add_year_2010() { return $this->title . " 2010"; } }
    • CodeSniffer Checks your code against a coding standard.
    • Why coding standards? Readable code for you... ... and for others too! Maintainable by others Stop wasting time on reformating the code No more arguing about line indentions
    • TYPO3 coding standards http://forge.typo3.org/projects/team- php_codesniffer Standards for: Naming Documentation Format Control structures and more...
    • Install CodeSniffer The package can install like this: $ pear install PHP_CodeSniffer-alpha Then we register the TYPO3 PEAR Channel, to get the TYPO3 Coding Standard: $ pear channel-discover pear.typo3.org After that you install the TYPO3 Coding Standard like this: $ pear install typo3/PHPCS_TYPO3_SniffPool $ pear install typo3/PHPCS_TYPO3v4_Standard
    • Set default Standard and use it! Set the default standard and default Tab-With: $ phpcs --config-set default_standard TYPO3v4 $ phpcs --config-set tab_width 4 Now you can use the CodeSniffer on the console for your TYPO3-Extensions: $ phpcs example.php
    • One more time our example code class Example { private $title = "t3con"; public function addYear() { return $this->add_year_2010(); } public function add_year_2010() { return $this->title . " 2010"; } }
    • Run CodeSniffer Use CodeSniffer on the console: $ phpcs example.php -------------------------------------------- FOUND 5 ERROR(S) AFFECTING 4 LINE(S) -------------------------------------------- 3 | ERROR | Missing class doc comment 4 | ERROR | Line indented incorrectly;… 6 | ERROR | Missing function doc comment 9 | ERROR | Missing function doc comment 9 | ERROR | Method name not camel caps
    • Fixing the code // Missing comment class Example { private $title = "t3con"; // Wrong indention // Missing comment public function addYear() { return $this->add_year_2010(); } // Missing comment public function add_year_2010() { // Wrong naming return $this->title . " 2010"; } }
    • Fixing the code /** * An example class. * * @author Jon Doe <john.doe@example.com> */ class Example { private $title = "t3con"; /** * Just an example function. * * @return string Some example string */ public function addYear() { return $this->addYear2010(); } …
    • What developers often think: Torture and pain http://www. ickr.com/photos/mhswde/2722217304/
    • What they really are: Freedom and fun http://www. ickr.com/photos/davidspinks/4453498888/
    • Other usage options PHP Tool Integration - Plugin for eclipse http://www.phpsrc.org/
    • Automate checking Automate tasks you do often Use CPU power to help you On a regular basis or on each commit into your version control management system Get reports instead of creating them Use a continuous integration server like Hudson or CruiseControl
    • Get support from the community Register your extension at http://forge.typo3.org/start/createProject
    • What is forge? Integrated social development platform for extension developers. Tools to streamline communication on projects SourceControl-Management Issue tracker Wiki NEW an integrated continuous integration server still in an early status but ready for some real world tests!
    • We do quality tests for you Providing reporting and code metrics on ci.typo3.org What is currently checked? PHP Mess Detection Copy Paste Detection Making code reviews quicker and more fun!
    • How do we solve the „red-light“-shock?
    • What's next CodeSniffer phpUnit-Tests More slaves for Hudson for faster response Your ideas?
    • Conclusion
    • Stop digging through code. Start with an overview. http://www. ickr.com/photos/69er/329057062/
    • Reports are a good start for good quality. http://www. ickr.com/photos/ uzo/97673183/
    • Tell everybody how to use the tools Most important: the youngsters! http://www. ickr.com/photos/kevenlaw/2787879806/
    • Make it a movement Inspiring people to share even better with extensions of higher quality!
    • dkd design kommunikation development thank you.