Conditions | 4 |
Paths | 6 |
Total Lines | 53 |
Code Lines | 38 |
Lines | 0 |
Ratio | 0 % |
Changes | 6 | ||
Bugs | 0 | Features | 2 |
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 |
||
70 | public function handle(Args $args, IO $io) |
||
71 | { |
||
72 | $configFileExist = true; |
||
73 | $overwrite = is_string($args->getOption('force')); |
||
74 | |||
75 | try { |
||
76 | $this->configurationLoader->setRootDirectory($args->getOption('config')); |
||
77 | $configuration = $this->configurationLoader->loadConfiguration(); |
||
78 | } catch (ConfigurationLoadingException $e) { |
||
79 | $configFileExist = false; |
||
80 | } |
||
81 | |||
82 | if (!$configFileExist || $overwrite) { |
||
83 | $configuration = [ |
||
84 | 'urls' => [ |
||
85 | 'google' => [ |
||
86 | 'url' => 'https://www.google.fr', |
||
87 | 'method' => 'GET', |
||
88 | 'headers' => [], |
||
89 | 'timeout' => 1, |
||
90 | 'validator' => [], |
||
91 | 'status_code' => 200, |
||
92 | 'metric_uuid' => null, |
||
93 | 'service_uuid' => null, |
||
94 | ], |
||
95 | ], |
||
96 | 'hogosha_portal' => [ |
||
97 | 'username' => '', |
||
98 | 'password' => '', |
||
99 | 'base_uri' => 'http://localhost:8000/api/', |
||
100 | 'metric_update' => false, |
||
101 | 'incident_update' => false, |
||
102 | 'default_failed_incident_message' => 'An error as occured, we are investigating %service_name%', |
||
103 | 'default_resolved_incident_message' => 'The service %service_name% is back to normal', |
||
104 | ], |
||
105 | ]; |
||
106 | |||
107 | // Dump configuration |
||
108 | $content = $this->configurationDumper->dumpConfiguration($configuration); |
||
109 | $this->filesystem->dumpFile( |
||
110 | $this->configurationLoader->getConfigurationFilepath(), |
||
111 | $content |
||
112 | ); |
||
113 | $io->writeLine('<info>Creating monitor file</info>'); |
||
114 | } else { |
||
115 | $io->writeLine( |
||
116 | sprintf( |
||
117 | '<info>You already have a configuration file in</info> "%s"', |
||
118 | $this->configurationLoader->getConfigurationFilepath() |
||
119 | ) |
||
120 | ); |
||
121 | } |
||
122 | } |
||
123 | } |
||
124 |
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: