CodeIgniter Forums
Restructuring/code clean up - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: General (https://forum.codeigniter.com/forumdisplay.php?fid=1)
+--- Forum: Lounge (https://forum.codeigniter.com/forumdisplay.php?fid=3)
+--- Thread: Restructuring/code clean up (/showthread.php?tid=67291)



Restructuring/code clean up - ignitedcms - 02-05-2017

OK so you got some code and it works pretty nicely except, it is all sort of over the place and not really organised.

You want to structure it in a way that is organised because it is something everyone has the potential to see and use and possibly amend.

This includes a logical and sensible file structure, organised logical string of methods, and tidy html views and css js files.

Where do you start?

I looked at using html/css beautifiers to dump out better view files. Tried to keep consistent naming of methods and spacing, might use a PHP beautifier on it too. File structure is pretty much own preference at the minute.

What do you do, this question is specifically aimed at github users who have clean readable code.


RE: Restructuring/code clean up - ignitedcms - 02-07-2017

Anyone?


RE: Restructuring/code clean up - Diederik - 02-07-2017

If I created a module and consider it finished (feature wise working order) I start refactoring it, moving code from controller to models to make more sense and document every method.

You can setup your editor to use PHP_CodeSniffer. This could help you to force you to code (php) following a certain style guide. Most editors support this (Sublime, Atom, Php storm) to auto format your code on file save for example or with a shortkey.

You can use PSR-2, the CodeIgniter style guide or your personal preference. The most important thing is readability.

Same applies for html/css, just indent every new element the same way.


RE: Restructuring/code clean up - ignitedcms - 02-07-2017

Thanks, I'm on sublime and I'm going to try this.

https://github.com/akalongman/sublimetext-codeformatter

I have a bit of a problem with my github code as the PHP seems all over the place, could this be because I need to convert tabs to spaces?


RE: Restructuring/code clean up - Diederik - 02-07-2017

(02-07-2017, 06:00 AM)Diederik Wrote: If I created a module and consider it finished (feature wise working order) I start refactoring it, moving code from controller to models to make more sense and document every method.
Forgot to add that during the refactoring stage I try to put all visible content into language files.