Conditions | 10 |
Paths | 6 |
Total Lines | 44 |
Lines | 0 |
Ratio | 0 % |
Changes | 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 |
||
18 | public static function factory($config) |
||
19 | { |
||
20 | switch ($config['save.handler']) { |
||
21 | case 'file': |
||
22 | return new Xhgui_Saver_File( |
||
23 | $config['save.handler.filename'], |
||
24 | $config['save.handler.separate_meta'] |
||
25 | ); |
||
26 | |||
27 | case 'upload': |
||
28 | $timeout = 3; |
||
29 | if (isset($config['save.handler.upload.timeout'])) { |
||
30 | $timeout = $config['save.handler.upload.timeout']; |
||
31 | } |
||
32 | return new Xhgui_Saver_Upload( |
||
33 | $config['save.handler.upload.uri'], |
||
34 | $timeout |
||
35 | ); |
||
36 | |||
37 | case 'pdo': |
||
38 | return new Xhgui_Saver_PDO( |
||
39 | $config['db.dsn'], |
||
40 | (!empty($config['db.user'])) ? $config['db.user'] : null, |
||
41 | (!empty($config['db.password'])) ? $config['db.password'] : null, |
||
42 | $config['db.options'] |
||
43 | ); |
||
44 | break; |
||
|
|||
45 | |||
46 | case 'mongodb': |
||
47 | default: |
||
48 | $mongo = new MongoClient( |
||
49 | $config['db.host'], |
||
50 | $config['db.options'] + |
||
51 | [ |
||
52 | 'username' => (!empty($config['db.user'])) ? $config['db.user'] : null, |
||
53 | 'password' => (!empty($config['db.password'])) ? $config['db.password'] : null, |
||
54 | ] |
||
55 | ); |
||
56 | |||
57 | $collection = $mongo->{$config['db.db']}->results; |
||
58 | $collection->findOne(); |
||
59 | return new Xhgui_Saver_Mongo($collection); |
||
60 | } |
||
61 | } |
||
62 | |||
76 |
The break statement is not necessary if it is preceded for example by a return statement:
If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.