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

ReplaceSpacesInEmptyLinesFixer::getName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 3
ccs 0
cts 0
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 2
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