Completed
Push — master ( d7f072...e80481 )
by Shcherbak
05:37
created

FixerProcessor::process()   C

Complexity

Conditions 11
Paths 39

Size

Total Lines 51
Code Lines 26

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 132

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 51
ccs 0
cts 36
cp 0
rs 5.7333
cc 11
eloc 26
nc 39
nop 2
crap 132

How to fix   Long Method    Complexity   

Long Method

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:

1
<?php
2
3
  namespace Funivan\Cs\FileProcessor;
4
5
  use Funivan\Cs\FileFinder\FileInfoCollection;
6
  use Funivan\Cs\Report\Report;
7
8
  /**
9
   * @author Ivan Shcherbak <[email protected]> 2016
10
   */
11
  class FixerProcessor extends BaseFileProcessor {
12
13
    /**
14
     * @var bool
15
     */
16
    private $saveFiles = false;
17
18
19
    /**
20
     * @param FileInfoCollection $files
21
     * @param Report $report
22
     */
23
    public function process(FileInfoCollection $files, Report $report) {
24
25
      if (empty($this->getTools())) {
26
        $this->getOutput()->writeln('<comment>Empty tools list</comment>');
27
        return;
28
      }
29
30
      $message = '✘ dry run  ';
31
      if ($this->saveFiles) {
32
        $message = '✔ fixed    ';
33
      }
34
35
      foreach ($files as $file) {
36
37
        $fixed = false;
38
39
        foreach ($this->getTools() as $tool) {
40
41
          if ($this->getOutput()->isDebug()) {
42
            $this->getOutput()->writeln('process : (' . $tool->getName() . ') ' . $file->getPath());
43
          }
44
45
          if (!$tool->canProcess($file)) {
46
            continue;
47
          }
48
49
          $tool->process($file, $report);
50
51
          $fileChanged = $file->getContent()->isChanged();
52
          if ($fileChanged === false) {
53
            continue;
54
          }
55
56
          $fixed = true;
57
58
          $filePathInfo = '';
59
          if ($this->saveFiles === false) {
60
            $filePathInfo = ' ## ' . $file->getPath();
61
          }
62
63
          $this->getOutput()->writeln('<info>' . $message . ': ' . $tool->getDescription() . $filePathInfo . '</info>');
64
        }
65
66
        if ($fixed and $this->saveFiles) {
67
          $file->save();
68
          $this->getOutput()->writeln('<info>' . '✔ saved    : ' . $file->getPath() . '</info>');
69
        }
70
71
      }
72
73
    }
74
75
76
    /**
77
     * @return boolean
78
     */
79
    public function getSaveFiles() {
80
      return $this->saveFiles;
81
    }
82
83
84
    /**
85
     * @param boolean $saveFiles
86
     */
87
    public function setSaveFiles($saveFiles) {
88
      $this->saveFiles = $saveFiles;
89
    }
90
91
  }