News Feed
Sections




News Archive
Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

NetTuts.com:
Refactoring Legacy Code Part 6 - Attacking Complex Methods
June 27, 2014 @ 13:17:37

The NetTuts.com site has posted the sixth part in their "Refactoring Legacy Code" series, this time with a focus on the more complex methods. They look at simplifying their contents and testing their various parts (better code coverage). The post is based completely on the contents of the previous five in the series, so if you haven't read up on those do that before starting.

In our previous five lessons we invested quite a lot of time in understanding our legacy system, in writing tests for whatever testable piece of code we could find. We reached a point to where we have quite a few tested methods but we still avoided the complex, hard to understand logic. It's now time for some serious coding.

The start with one of the more complex methods (roll) and work through it line-by-line to figure out what it's being given, how it's handling the data and what kinds of things it might return or modify inside. The break it down into to "parts" and figure out the right tests to write for each. With the method fully tested, they then start in on the refactor, teasing out various parts of the method into other methods and property changes. There's also a section at the end talking about pair programming and how it relates to good testing practices.

0 comments voice your opinion now!
refactor series tutorial part6 complex method unittest phpunit

Link: http://code.tutsplus.com/tutorials/refactoring-legacy-code-part-6-attacking-complex-methods--cms-21522

blog comments powered by Disqus

Similar Posts

Alexander Netkachev's Blog: Automatic testing of MVC applications created with Zend Framework

Experts Round Table: HTTP Headers and the PHP header() Function

DevShed: Constructing Multi-Line PDF Documents with PHP 5

Raymond Kolbe's Blog: DOMPDF in ZF2

Developer Tutorials Blog: The ultimate PHP web development environment, part 2


Community Events





Don't see your event here?
Let us know!


api community zendserver voicesoftheelephpant deployment laravel framework tips symfony threedevsandamaybe series introduction podcast language release interview code list bugfix conference

All content copyright, 2014 PHPDeveloper.org :: info@phpdeveloper.org - Powered by the Solar PHP Framework