| Conditions | 8 |
| Paths | 64 |
| Total Lines | 156 |
| Code Lines | 95 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 8 | ||
| 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 |
||
| 109 | public function startSystem(): bool |
||
| 110 | { |
||
| 111 | $system = new System(); |
||
| 112 | // Is the configuration default? |
||
| 113 | // Try restore config... |
||
| 114 | if($system->isDefaultConf() && !file_exists('/offload/livecd')){ |
||
| 115 | $this->echoStartMsg(' - Try restore backup of settings... '); |
||
| 116 | $system->tryRestoreConf(); |
||
| 117 | $this->echoResultMsg(); |
||
| 118 | } |
||
| 119 | |||
| 120 | // Check if the system is running on T2SDELinux |
||
| 121 | $itIsT2SDELinux = Util::isT2SdeLinux(); |
||
| 122 | |||
| 123 | // Mark the registry as booting |
||
| 124 | $this->di->getShared(RegistryProvider::SERVICE_NAME)->booting = true; |
||
| 125 | |||
| 126 | // Start the ACPID daemon |
||
| 127 | $this->echoStartMsg(PHP_EOL); |
||
| 128 | $this->echoStartMsg(' - Start acpid daemon...'); |
||
| 129 | $ACPIDConf = new ACPIDConf(); |
||
| 130 | $ACPIDConf->reStart(); |
||
| 131 | $this->echoResultMsg(); |
||
| 132 | |||
| 133 | // Start the Beanstalkd daemon |
||
| 134 | $this->echoStartMsg(' - Start beanstalkd daemon...'); |
||
| 135 | $beanstalkConf = new BeanstalkConf(); |
||
| 136 | $beanstalkConf->reStart(); |
||
| 137 | $this->echoResultMsg(); |
||
| 138 | |||
| 139 | // Start the Redis daemon |
||
| 140 | $this->echoStartMsg(' - Start redis daemon...'); |
||
| 141 | $redisConf = new RedisConf(); |
||
| 142 | $redisConf->reStart(); |
||
| 143 | $this->echoResultMsg(); |
||
| 144 | |||
| 145 | // Configure Sentry error logger |
||
| 146 | $this->echoStartMsg(' - Configuring sentry error logger ...'); |
||
| 147 | $sentryConf = new SentryConf(); |
||
| 148 | $sentryConf->configure(); |
||
| 149 | $this->echoResultMsg(); |
||
| 150 | |||
| 151 | // Configure the system timezone |
||
| 152 | $this->echoStartMsg(' - Configuring timezone...'); |
||
| 153 | $system::timezoneConfigure(); |
||
| 154 | $this->echoResultMsg(); |
||
| 155 | |||
| 156 | // Mount the storage disk |
||
| 157 | $storage = new Storage(); |
||
| 158 | if($itIsT2SDELinux){ |
||
| 159 | // Do not need to set on Docker or Debian linux |
||
| 160 | $storage->saveFstab(); |
||
| 161 | } |
||
| 162 | $storage->configure(); |
||
| 163 | $this->echoStartMsg(' - Mount storage disk...'); |
||
| 164 | $this->echoResultMsg(); |
||
| 165 | |||
| 166 | // Additional tasks for T2SDELinux |
||
| 167 | if($itIsT2SDELinux) { |
||
| 168 | $this->echoStartMsg(' - Connect swap...'); |
||
| 169 | Processes::mwExecBg('/etc/rc/connect-swap'); |
||
| 170 | $this->echoResultMsg(); |
||
| 171 | } |
||
| 172 | |||
| 173 | // Start the syslogd daemon |
||
| 174 | $this->echoStartMsg(' - Start syslogd daemon...'); |
||
| 175 | $syslogConf = new SyslogConf(); |
||
| 176 | $syslogConf->reStart(); |
||
| 177 | $this->echoResultMsg(); |
||
| 178 | |||
| 179 | // Update the database structure |
||
| 180 | $dbUpdater = new UpdateDatabase(); |
||
| 181 | $dbUpdater->updateDatabaseStructure(); |
||
| 182 | |||
| 183 | // Create directories required by modules after DB upgrade |
||
| 184 | $this->echoStartMsg(' - Create modules links and folders...'); |
||
| 185 | $storage->createWorkDirsAfterDBUpgrade(); |
||
| 186 | $this->echoResultMsg(); |
||
| 187 | |||
| 188 | // Update the system configuration and applications |
||
| 189 | $this->echoStartMsg(' - Update configs and applications...'.PHP_EOL); |
||
| 190 | $confUpdate = new UpdateSystemConfig(); |
||
| 191 | $confUpdate->updateConfigs(); |
||
| 192 | $this->echoStartMsg(' - Update configs...'); |
||
| 193 | $this->echoResultMsg(); |
||
| 194 | |||
| 195 | // Configure VM tools |
||
| 196 | $this->echoStartMsg(' - Configuring VM tools...'); |
||
| 197 | $vmwareTools = new VmToolsConf(); |
||
| 198 | $resultVMTools = $vmwareTools->configure(); |
||
| 199 | $this->echoResultMsg($resultVMTools); |
||
|
|
|||
| 200 | |||
| 201 | // Configure the system hostname |
||
| 202 | $this->echoStartMsg(' - Configuring hostname...'); |
||
| 203 | $network = new Network(); |
||
| 204 | $network->hostnameConfigure(); |
||
| 205 | $this->echoResultMsg(); |
||
| 206 | |||
| 207 | // Generate resolv.conf |
||
| 208 | $this->echoStartMsg(' - Configuring resolv.conf...'); |
||
| 209 | $network->resolvConfGenerate(); |
||
| 210 | $this->echoResultMsg(); |
||
| 211 | |||
| 212 | // Configure LAN interface |
||
| 213 | $this->echoStartMsg(' - Configuring LAN interface...'); |
||
| 214 | if ($this->isDocker){ |
||
| 215 | $network->configureLanInDocker(); |
||
| 216 | } else { |
||
| 217 | $network->lanConfigure(); |
||
| 218 | } |
||
| 219 | $this->echoResultMsg(); |
||
| 220 | |||
| 221 | // SSL rehash |
||
| 222 | $this->echoStartMsg(' - SSL rehash...'); |
||
| 223 | System::sslRehash(); |
||
| 224 | $this->echoResultMsg(); |
||
| 225 | |||
| 226 | // Configure the firewall |
||
| 227 | $this->echoStartMsg(' - Configuring Firewall...'); |
||
| 228 | $firewall = new IptablesConf(); |
||
| 229 | $firewall->applyConfig(); |
||
| 230 | $this->echoResultMsg(); |
||
| 231 | |||
| 232 | // Configure NTP |
||
| 233 | $this->echoStartMsg(' - Configuring ntpd...'); |
||
| 234 | NTPConf::configure(); |
||
| 235 | $this->echoResultMsg(); |
||
| 236 | |||
| 237 | // Do not need to set Debian SSH service |
||
| 238 | if(!Util::isSystemctl()){ |
||
| 239 | $this->echoStartMsg(' - Configuring SSH console...'); |
||
| 240 | $sshConf = new SSHConf(); |
||
| 241 | $resSsh = $sshConf->configure(); |
||
| 242 | $this->echoResultMsg($resSsh); |
||
| 243 | } |
||
| 244 | |||
| 245 | // Start cloud provisioning |
||
| 246 | if (!$this->isDocker) { |
||
| 247 | $this->echoStartMsg(' - Cloud provisioning...'."\n"); |
||
| 248 | CloudProvisioning::start(); |
||
| 249 | $this->echoResultMsg(); |
||
| 250 | |||
| 251 | // Connect storage in a cloud if needed |
||
| 252 | $this->echoStartMsg(' - Auto connect storage for a cloud ..."\n"'); |
||
| 253 | $connectResult = Storage::connectStorageInCloud(); |
||
| 254 | $this->echoResultMsg($connectResult); |
||
| 255 | } |
||
| 256 | |||
| 257 | // Update external IP if needed |
||
| 258 | $this->echoStartMsg(' - Update external IP...'); |
||
| 259 | $network->updateExternalIp(); |
||
| 260 | $this->echoResultMsg(); |
||
| 261 | |||
| 262 | $this->di->getShared(RegistryProvider::SERVICE_NAME)->booting = false; |
||
| 263 | |||
| 264 | return true; |
||
| 265 | } |
||
| 332 | } |