Completed
Push — master ( 7a83e2...2cf7e5 )
by Shcherbak
02:26
created

ReplaceSpacesInEmptyLinesFixer   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 5
c 1
b 0
f 1
lcom 0
cbo 4
dl 0
loc 46
ccs 12
cts 12
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getName() 0 3 1
A getDescription() 0 3 1
A process() 0 18 3
1
<?php
2
3
  namespace Funivan\Cs\Tools\SpacesInEmptyLines;
4
5
  use Funivan\Cs\FileFinder\FileInfo;
6
  use Funivan\Cs\Message\Report;
7
8
  /**
9
   */
10
  class ReplaceSpacesInEmptyLinesFixer extends AbstractSpacesInEmptyLines {
11
12
    const NAME = 'spaces_in_empty_lines_fixes';
13
14
15
    /**
16
     * @codeCoverageIgnore
17
     * @inheritdoc
18
     */
19
    public function getName() {
20
      return self::NAME;
21
    }
22
23
24
    /**
25
     * @codeCoverageIgnore
26
     * @return string
27
     */
28
    public function getDescription() {
29
      return 'Remove spaces in empty lines';
30
    }
31
32
33
    /**
34
     * @inheritdoc
35
     */
36 3
    public function process(FileInfo $file, Report $report) {
37 3
      $stripTokens = $this->findTokens($file);
38
39 3
      if ($stripTokens->count() === 0) {
40 1
        return;
41
      }
42
43 2
      $report->addNotice($file, $this, 'Find empty lines with spaces: ' . $stripTokens->count());
44
45 2
      foreach ($stripTokens as $token) {
46 2
        $value = $token->getValue();
47
48 2
        $value = preg_replace('!\n([ ]+)\n!', "\n\n", $value);
49 2
        $value = preg_replace("!\s+\n$!", "\n", $value);
50 2
        $token->setValue($value);
51 2
      }
52
53 2
    }
54
55
  }
56