FixCommand::getResultState()   B
last analyzed

Complexity

Conditions 5
Paths 7

Size

Total Lines 29
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 30

Importance

Changes 0
Metric Value
dl 0
loc 29
c 0
b 0
f 0
ccs 0
cts 24
cp 0
rs 8.439
cc 5
eloc 19
nc 7
nop 3
crap 30
1
<?php
2
3
  namespace Funivan\Cs\Console;
4
5
  use Funivan\Cs\Configuration\ConfigurationInterface;
6
  use Funivan\Cs\Configuration\CsConfiguration;
7
  use Funivan\Cs\FileProcessor\FixerProcessor;
8
  use Funivan\Cs\Report\Report;
9
  use Symfony\Component\Console\Input\InputInterface;
10
  use Symfony\Component\Console\Input\InputOption;
11
  use Symfony\Component\Console\Output\OutputInterface;
12
13
  /**
14
   * @author Ivan Shcherbak <[email protected]> 2016
15
   */
16
  class FixCommand extends BaseCommand {
17
18
    /**
19
     * @inheritdoc
20
     */
21
    protected function configure() {
22
      $this->setName('fix');
23
24
      $this->setDescription('Fix code according your code style');
25
      $this->addOption('save', null, InputOption::VALUE_NONE, 'By default we will show info without code modification');
26
      parent::configure();
27
    }
28
29
30
    /**
31
     * @inheritdoc
32
     */
33
    protected function getResultState(InputInterface $input, OutputInterface $output, Report $report) {
34
      $isVerbose = ($output->getVerbosity() === OutputInterface::VERBOSITY_DEBUG);
35
36
      if ($report->count() === 0) {
37
        $output->writeln('<info>✔ Looking good</info>');
38
        return 0;
39
      }
40
41
      $output->writeln('');
42
43
      foreach ($report as $message) {
44
        $output->write('<info>');
45
        $output->writeln('file    : ' . $message->getFile()->getPath() . ':' . $message->getLine());
46
        $output->writeln('tool    : ' . $message->getTool()->getName());
47
        if ($isVerbose) {
48
          $output->writeln('info    : ' . $message->getTool()->getDescription());
49
        }
50
51
        $output->writeln('message : ' . $message->getText());
52
        $output->writeln('</info>');
53
      }
54
55
      if ($input->getOption('save')) {
56
        $output->writeln('<info>✔ Fixed</info>');
57
      } else {
58
        $output->writeln('<comment>✔ Dry run</comment>');
59
      }
60
      return 0;
61
    }
62
63
64
    /**
65
     * @inheritdoc
66
     */
67
    protected function getFileProcessor(InputInterface $input, OutputInterface $output) {
68
      $fixer = new FixerProcessor();
69
      $fixer->setSaveFiles($input->getOption('save'));
70
      return $fixer;
71
    }
72
73
74
    /**
75
     * @return ConfigurationInterface
76
     */
77
    protected function getDefaultConfiguration() {
78
      return CsConfiguration::createFixerConfiguration();
79
    }
80
81
  }
82