Archive

Posts Tagged 'refactoring'

PHP Refactoring - Lez. 4: Extraction of code and elimination of temporary variables

Often we find in the methods of a class of code that can be reused in various parts of the same, or we see that put in that position does not give any intuitive meaning.

An improvement in the readability of the object is to extract this group of rows with a common meaning and place in a method that is invoked whenever the need is present.

Another problem is the presence of temporary variables, which do nothing but increase the risk of bugs and can be replaced by self-documenting code, in the form of a private method of the class.

The following is an example to better clarify the concept:

Continue reading ...

PHP Refactoring - Lez. 3: Methods of a class

2 commenti November 12, 2008 Nicholas 2 comments

As regards the methods of a class, also applies in this case, the naming convention outlined above for the properties of the class itself. We repeat them below for convenience:

  • If consists of a single word, all lowercase, for example, currency ();
  • If made ​​of many words the first letter of each, from the second, in uppercase, all lowercase other, for example addElement ();
  • The method name must be self-explanatory.

Continue reading ...

PHP Refactoring - Lez. 2: array property of a class

Today we will discuss the properties consist of a class or property containing an array.

We saw in the previous lesson ( PHP Refactoring - Lez. 1: properties of a class ) how to write simple properties of a class.

With regard to the properties consist of naming conventions, the rules introduced in the previous tutorial, except for methods to access them. Below the standard to follow at the class level.

Continue reading ...