devinsays/instant-content — pull request #4 by GaryJones (2013-10-27 03:51:28+00:00)
Title: Refactor all the things.

This commit is a major reworking of the PHP and JS in this plugin, making it practically a rewrite rather than a refactor.

The aim was to split the "God class" in PHP up into smaller classes. It has ended up with one class for each of the four admin pages, and abstract admin class which the four extend, the existing one for the plugin updater (not touched, other than a file and class rename), one main plugin class, and the main plugin file.

Once the classes were split up, the methods could be refactored into smaller methods. This makes the code easier to maintain, and helps make the code more unit testable.

While the JS may be rewritten with Backbone in a future version, I've rewritten it now to make it more modular - clear namespaced binding against named functions inside three named individual objects, all making the code more self-documenting. The ajax calls have been splitted up, so instead of nested anonymous functions for success and failure, it takes advantage of Promises and deferred objects to have clear callbacks. This, along with general refactoring of functions into smaller functions, helped reduce the cyclomatic complexity.

Not done: Rewrite the settings page to use more of the Settings API to generate the output, instead of hard-coding the table layout.
Not done: Some inline docs for PHP, JS, and also contextual help descriptions.
Not done: Whatever I've left marked as `@todo`.

Feel free to post line notes where you have questions.