Conditions | 10 |
Paths | 133 |
Total Lines | 58 |
Code Lines | 36 |
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 | <?php |
||
25 | protected function execute(InputInterface $input, OutputInterface $output): int |
||
26 | { |
||
27 | $this->initConfiguration($input->getOption('configFile')); |
||
28 | |||
29 | $debugMode = $input->getOption('debug'); |
||
30 | |||
31 | if (!$this->isInitialized()) { |
||
32 | $output->writeln('<error>System was not initialized. Please run inventorio init.</error>'); |
||
33 | return Command::FAILURE; |
||
34 | } |
||
35 | |||
36 | $this->initCollectors(); |
||
37 | |||
38 | $inventory = []; |
||
39 | |||
40 | $client = new \Startwind\Inventorio\Util\Client(new Client()); |
||
41 | |||
42 | foreach ($this->collectors as $collector) { |
||
43 | if ($collector instanceof InventoryAwareCollector) { |
||
44 | $collector->setInventory($inventory); |
||
45 | } |
||
46 | if ($collector instanceof ClientAwareCollector) { |
||
47 | $collector->setClient($client); |
||
48 | } |
||
49 | |||
50 | if ($debugMode) $start = time(); |
||
51 | $collected = $collector->collect(); |
||
52 | if ($collected) { |
||
53 | $inventory[$collector->getIdentifier()] = $collected; |
||
54 | } else { |
||
55 | $inventory[$collector->getIdentifier()] = self::NOT_APPLICABLE; |
||
56 | } |
||
57 | if ($debugMode) { |
||
58 | $output->writeln('DEBUG: running ' . $collector->getIdentifier() . ' took ' . time() - $start . ' seconds'); |
||
|
|||
59 | } |
||
60 | } |
||
61 | |||
62 | if ($debugMode) { |
||
63 | $output->writeln('DEBUG: collection result:'); |
||
64 | $output->writeln(json_encode($inventory, JSON_PRETTY_PRINT)); |
||
65 | } |
||
66 | |||
67 | Memory::getInstance()->setCollection($inventory); |
||
68 | |||
69 | $reporter = new InventorioGradeReporter($output, $this->config->getInventorioServer(), $this->getServerId(), $this->getUserId()); |
||
70 | |||
71 | try { |
||
72 | $reporter->report($inventory); |
||
73 | } catch (Exception $exception) { |
||
74 | $output->writeln('<error> '); |
||
75 | $output->writeln(' Unable to run reporter. '); |
||
76 | $output->writeln(' </error>'); |
||
77 | $output->writeln(''); |
||
78 | $output->writeln(' <comment>Message: ' . $exception->getMessage() . '</comment>'); |
||
79 | return Command::FAILURE; |
||
80 | } |
||
81 | |||
82 | return Command::SUCCESS; |
||
83 | } |
||
85 |