Conditions | 18 |
Paths | 19 |
Total Lines | 75 |
Code Lines | 39 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 1 | Features | 1 |
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 |
||
107 | public static function fileOperator( $operation, $target, $destination = null, $prefix = null ) |
||
108 | { |
||
109 | // 処理結果の初期化 |
||
110 | $retVal = false; |
||
111 | |||
112 | // operationの内容によって、処理を分ける |
||
113 | switch ($operation) { |
||
114 | // make |
||
115 | case 'make': |
||
116 | if (@touch( $target )) { |
||
117 | $retVal = true; |
||
118 | } |
||
119 | break; |
||
120 | |||
121 | // copy |
||
122 | case 'copy': |
||
123 | if (@copy( $target, $destination )) { |
||
124 | $retVal = true; |
||
125 | } |
||
126 | break; |
||
127 | |||
128 | // copy with replace |
||
129 | case 'copy_with_replace': |
||
130 | // ファイルの中身を一度すべて取得 |
||
131 | $text = @file_get_contents( $target ); |
||
132 | |||
133 | // $prefixがセットされていたら置換処理を実施 |
||
134 | if (!empty( $prefix )) { |
||
135 | $text = str_replace( '[[[_PREFIX]]]', $prefix, $text ); |
||
136 | } |
||
137 | |||
138 | // ファイルを出力 |
||
139 | if (@file_put_contents( $destination, $text )) { |
||
140 | $retVal = true; |
||
141 | } |
||
142 | break; |
||
143 | |||
144 | // move |
||
145 | case 'move': |
||
146 | if (@rename( $target, $destination )) { |
||
147 | $retVal = true; |
||
148 | } |
||
149 | break; |
||
150 | |||
151 | // unlink |
||
152 | case 'unlink': |
||
153 | if (@unlink( $target )) { |
||
154 | $retVal = true; |
||
155 | } |
||
156 | break; |
||
157 | |||
158 | // mkdir |
||
159 | case 'mkdir': |
||
160 | if (@mkdir( $target, 0777, true )) { |
||
161 | $retVal = true; |
||
162 | } |
||
163 | break; |
||
164 | |||
165 | // rmdir |
||
166 | case 'rmdir': |
||
167 | if (@rmdir( $target )) { |
||
168 | $retVal = true; |
||
169 | } |
||
170 | break; |
||
171 | |||
172 | // symlink |
||
173 | case 'symlink': |
||
174 | if (@symlink( $target, $destination )) { |
||
175 | $retVal = true; |
||
176 | } |
||
177 | break; |
||
178 | } |
||
179 | |||
180 | return $retVal; |
||
181 | } |
||
182 | |||
183 | } |