Conditions | 1 |
Paths | 5 |
Total Lines | 58 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
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 | var program = require('commander'); |
||
11 | .action(function(enviroment) { |
||
12 | |||
13 | shell.echo('Compile Workspace ('+enviroment+')'); |
||
14 | |||
15 | shell.cd('applications/workspace/'); |
||
16 | |||
17 | fs.readFile('config.php.dist', 'utf8', function (err,data) { |
||
18 | |||
19 | if (err) { |
||
20 | process.stderr.write(chalk.red("Errore in lettura: "+err)); |
||
21 | process.exit(1); |
||
|
|||
22 | } |
||
23 | |||
24 | var result; |
||
25 | if ( enviroment === 'dev' ){ |
||
26 | result = data.replace(/##TYPE##/g, 'sqlite'); |
||
27 | result = result.replace(/##HOST##/g, 'ROOT_PATH.\'/../database/workspace.sqlite\''); |
||
28 | result = result.replace(/##DBNAME##/g, ''); |
||
29 | result = result.replace(/##PASSWORD##/g, ''); |
||
30 | result = result.replace(/##USERNAME##/g, ''); |
||
31 | result = result.replace(/##LOGLEVEL##/g, 'Monolog\Logger::DEBUG'); |
||
32 | } else if ( enviroment === 'vagrant' ){ |
||
33 | result = data.replace(/##TYPE##/g, 'mysql'); |
||
34 | result = result.replace(/##HOST##/g, '\'localhost\''); |
||
35 | result = result.replace(/##DBNAME##/g, 'workspace'); |
||
36 | result = result.replace(/##PASSWORD##/g, 'workspace'); |
||
37 | result = result.replace(/##USERNAME##/g, 'workspace'); |
||
38 | result = result.replace(/##LOGLEVEL##/g, 'Monolog\Logger::DEBUG'); |
||
39 | } else { |
||
40 | // STAGING / PROD |
||
41 | result = data.replace(/##TYPE##/g, 'mysql'); |
||
42 | if ( |
||
43 | !process.env.npm_package_config_database_host || |
||
44 | !process.env.npm_package_config_database_host || |
||
45 | !process.env.npm_package_config_database_dbname || |
||
46 | !process.env.npm_package_config_database_password || |
||
47 | !process.env.npm_package_config_database_username |
||
48 | ) { |
||
49 | process.stderr.write(chalk.red("Errore manca la configurazione in .npmrc")); |
||
50 | process.exit(1); |
||
51 | } |
||
52 | result = result.replace(/##HOST##/g, '\''+process.env.npm_package_config_database_host+'\''); |
||
53 | result = result.replace(/##DBNAME##/g, process.env.npm_package_config_database_dbname); |
||
54 | result = result.replace(/##PASSWORD##/g, process.env.npm_package_config_database_password); |
||
55 | result = result.replace(/##USERNAME##/g, process.env.npm_package_config_database_username); |
||
56 | result = result.replace(/##LOGLEVEL##/g, 'Monolog\Logger::INFO'); |
||
57 | } |
||
58 | |||
59 | |||
60 | fs.writeFile('config.php', result, 'utf8', function (err) { |
||
61 | if (err) { |
||
62 | process.stderr.write(chalk.red("Errore in scrittura: "+err)); |
||
63 | process.exit(1); |
||
64 | } |
||
65 | }); |
||
66 | }); |
||
67 | |||
68 | }) |
||
69 | .parse(process.argv); |
||
79 |