Muschamp Rd

Refactoring PHP Code

February 19th, 2011
PHP logo

Is not what I want to be doing now, or ever. I don’t like PHP. I never wanted to program in PHP. I’m just unemployed so I decided to build something and PHP is available on my webhost. Not finding very good examples or code out there I ended up writing a lot of PHP. So much I just started adding features and methods that might be of use to someone someday. I wrote the token tutorial but it hasn’t exactly set the web on fire. Too much work to get all the APIs to function, even building upon all my work for most wannabe web gurus.

Update: my PHP code to make web mashups is online and open source. You can use it to make various things such as a gallery of your favourite CDS.

One of my CD cover gallery web mashups built with PHP

Originally there was albumCollection.php then I decided to make a subclass which I named musicCollection.php but that was mainly an exercise in learning more about PHP than I wanted to know. I think the hierarchy should go mCollection.php -> musicCollection.php -> albumCollection.php

Once I get that sorted out and functioning I plan to make a DVD gallery similar to the CD Cover Gallery I originally wanted to make that took way too much work and resulted in many evenings spent coding PHP and cursing PHP weenies.

My code has been tested quite heavily and this isn’t my first kick at the refactoring can, so I hope to finish this in a timely manner. So far so good, I got the first test gallery to function again in short order. Another advantage I have is when I developed the class(s) I made progressively more involved mashups so I can make sure the mashups I previously made individually function, rather than having to debug all the code at once.

It all went well for the most part. I made some variables protected that probably should remain private. However once I was pretty sure every method was working as well as before, I could add in accessors or helper methods as I like to keep as much private as I can, or at least that is generally good OOP design.

My CD Collection Browser is functioning normally, that just leaves a few more mashups to test. I actually changed one line of the client code for my Random CD Mashup, but that was just to reflect the new class inheritance. My Favourite Songs mashup required the same change to the client code. This final mashup required the most thinking on how best to make it work again, as it used a Static class method to populate the data which it fetched from, I ended up having to make changes to the client as that was easier and involved less code duplication. I also just removed features from the mashup.

Now everything is working, just not as well as I’d like. I have to look at the code that fetches preview tracks, especially from Amazon. I also need to take a closer look at the YouTube API stuff.

Related Posts

One Comment

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Posts on Muskblog © Andrew "Muskie" McKay.
CFA Institute does not endorse, promote or warrant the accuracy or quality of Muskblog. CFA® and Chartered Financial Analyst® are registered trademarks owned by CFA Institute.