Conditions | 1 |
Paths | 1 |
Total Lines | 64 |
Code Lines | 47 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
66 | public function getColumnDefinition() |
||
67 | { |
||
68 | return [ |
||
69 | [ |
||
70 | 'Field' => 'id', |
||
71 | 'Type' => 'int(10) unsigned', |
||
72 | 'Null' => 'NO', |
||
73 | 'Key' => 'PRI', |
||
74 | 'Default' => null, |
||
75 | 'Extra' => 'auto_increment', |
||
76 | 'Comment' => '', |
||
77 | 'CharacterSet' => null, |
||
78 | 'Collation' => null |
||
79 | ],[ |
||
80 | 'Field'=> 'created_by', |
||
81 | 'Type'=> 'varchar(40)', |
||
82 | 'Null'=> 'YES', |
||
83 | 'Key'=> '', |
||
84 | 'Default'=> null, // MySQL 5.1 - 5.7 sends: null |
||
85 | 'Extra' => '', |
||
86 | 'Comment' => 'Creator name', |
||
87 | 'CharacterSet' => 'utf8', |
||
88 | 'Collation'=> 'utf8_unicode_ci' |
||
89 | ], |
||
90 | // Mariadb since 10.2.7, see https://jira.mariadb.org/browse/MDEV-13341 |
||
91 | [ |
||
92 | 'Field' => 'updated_at', |
||
93 | 'Type' => 'datetime', |
||
94 | 'Null' => 'YES', |
||
95 | 'Key' => '', |
||
96 | 'Default' => 'NULL', // MariaDB 10.2.7 return 'NULL' |
||
97 | 'Extra' => '', |
||
98 | 'Comment' => 'Record last update timestamp', |
||
99 | 'CharacterSet' => null, |
||
100 | 'Collation' => null |
||
101 | ], |
||
102 | // Mariadb 10.2 test with defaults that could be |
||
103 | // ambiguous (see text_1 and text_2 Default) |
||
104 | [ |
||
105 | 'Field' => 'text_1', |
||
106 | 'Type' => 'varchar(50)', |
||
107 | 'Null' => 'YES', |
||
108 | 'Key' => '', |
||
109 | 'Default' => "'NULL'", |
||
110 | 'Extra' => '', |
||
111 | 'Comment' => '', |
||
112 | 'CharacterSet' => 'utf8', |
||
113 | 'Collation'=> 'utf8_unicode_ci' |
||
114 | ],[ |
||
115 | 'Field' => 'text_2', |
||
116 | 'Type' => 'varchar(50)', |
||
117 | 'Null' => 'YES', |
||
118 | 'Key' => '', |
||
119 | 'Default' => 'NULL', |
||
120 | 'Extra' => '', |
||
121 | 'Comment' => '', |
||
122 | 'CharacterSet' => 'utf8', |
||
123 | 'Collation'=> 'utf8_unicode_ci' |
||
124 | ], |
||
125 | |||
126 | |||
127 | ]; |
||
128 | |||
129 | } |
||
130 | |||
162 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: