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

FixerProcessor   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 81
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 81
wmc 13
lcom 1
cbo 5
ccs 0
cts 42
cp 0
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
C process() 0 51 11
A getSaveFiles() 0 3 1
A setSaveFiles() 0 3 1
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
  }