| Conditions | 12 |
| Paths | 100 |
| Total Lines | 62 |
| Code Lines | 39 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 5 | ||
| Bugs | 1 | 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 |
||
| 29 | protected function execute(InputInterface $input, OutputInterface $output): int |
||
| 30 | { |
||
| 31 | $this->initConfiguration($input->getOption('configFile')); |
||
| 32 | |||
| 33 | $isDebug = $input->getOption('debug'); |
||
| 34 | |||
| 35 | if ($isDebug) { |
||
| 36 | $logger = new Logger('name'); |
||
| 37 | $logger->pushHandler(new StreamHandler('daemon.log', Logger::DEBUG)); |
||
| 38 | } |
||
| 39 | |||
| 40 | $lastRun = [ |
||
| 41 | 'default' => time() - (24 * 60 * 60), |
||
| 42 | 'remote' => time() - (24 * 60 * 60), |
||
| 43 | 'collect' => time() - (24 * 60 * 60), |
||
| 44 | ]; |
||
| 45 | |||
| 46 | $serverId = $this->getServerId(); |
||
| 47 | $memory = Memory::getInstance(); |
||
| 48 | |||
| 49 | $remoteConnect = new RemoteConnect( |
||
| 50 | $this->config->getInventorioServer(), |
||
| 51 | $serverId, |
||
| 52 | $this->config->getCommands(), |
||
| 53 | $this->config->getSecret() |
||
| 54 | ); |
||
| 55 | |||
| 56 | $remoteEnabled = $this->isRemoteEnabled(); |
||
| 57 | $collectEnabled = $this->isCollectEnabled(); |
||
| 58 | $smartCareEnabled = $this->isSmartCareEnabled(); |
||
| 59 | |||
| 60 | if ($collectEnabled) { |
||
| 61 | $collectReporter = new InventorioCloudReporter(); |
||
| 62 | $collectCollector = new Collector(); |
||
| 63 | } |
||
| 64 | |||
| 65 | while (true) { |
||
| 66 | if ($lastRun['default'] <= time() - $this->intervals['default']) { |
||
| 67 | $this->getApplication()->find('collect')->run($input, $output); |
||
| 68 | $lastRun['default'] = time(); |
||
| 69 | } |
||
| 70 | |||
| 71 | if ($remoteEnabled || $smartCareEnabled) { |
||
| 72 | if ($lastRun['remote'] <= time() - $this->intervals['remote']) { |
||
| 73 | $result = $remoteConnect->run($remoteEnabled, $smartCareEnabled); |
||
| 74 | if ($isDebug && $result) { |
||
| 75 | $logger->debug('Running command: ' . $result); |
||
|
|
|||
| 76 | } |
||
| 77 | $lastRun['remote'] = time(); |
||
| 78 | } |
||
| 79 | } |
||
| 80 | |||
| 81 | if ($collectEnabled) { |
||
| 82 | if ($lastRun['collect'] <= time() - $this->intervals['collect']) { |
||
| 83 | $dataset = $collectCollector->collect(); |
||
| 84 | $memory->addDataSet($dataset); |
||
| 85 | $collectReporter->report($serverId, $dataset); |
||
| 86 | $lastRun['collect'] = time(); |
||
| 87 | } |
||
| 88 | } |
||
| 89 | |||
| 90 | sleep($this->getInterval()); |
||
| 91 | } |
||
| 107 |