LineEndingFixer::process()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 15
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 15
c 0
b 0
f 0
ccs 10
cts 10
cp 1
rs 9.4285
cc 2
eloc 9
nc 2
nop 2
crap 2
1
<?php
2
3
  namespace Funivan\Cs\Tools\LineEnding;
4
5
  use Funivan\Cs\Fs\File;
6
  use Funivan\Cs\Report\Report;
7
8
  /**
9
   * @author Ivan Shcherbak <[email protected]> 2016
10
   */
11
  class LineEndingFixer extends LineEndingAbstract {
12
13
    const NAME = 'line_ending_fixer';
14
15
16
    /**
17
     * @codeCoverageIgnore
18
     * @inheritdoc
19
     */
20
    public function getName() {
21
      return self::NAME;
22
    }
23
24
25
    /**
26
     * @param File $file
27
     * @param Report $report
28
     * @void
29
     */
30 4
    public function process(File $file, Report $report) {
31 4
      $collection = \Funivan\PhpTokenizer\Collection::createFromString($file->getContent()->get());
32 4
      $tokens = $collection->find($this->getFindQuery());
33
34 4
      foreach ($tokens as $token) {
35 2
        $value = $token->getValue();
36 2
        $value = preg_replace(self::REGEX, "\n", $value);
37 2
        $token->setValue($value);
38
39 2
        $report->addMessage($file, $this, 'Replace invalid line ending', $token->getLine());
40
      }
41
42
43 4
      $file->getContent()->set($collection->assemble());
44 4
    }
45
46
  }