SpacesInEmptyLinesReview::process()   B
last analyzed

Complexity

Conditions 5
Paths 8

Size

Total Lines 28
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 30

Importance

Changes 0
Metric Value
dl 0
loc 28
c 0
b 0
f 0
ccs 0
cts 21
cp 0
rs 8.439
cc 5
eloc 16
nc 8
nop 2
crap 30
1
<?php
2
3
  namespace Funivan\Cs\Tools\SpacesInEmptyLines;
4
5
  use Funivan\Cs\Fs\File;
6
  use Funivan\Cs\Report\Report;
7
8
  /**
9
   *
10
   */
11
  class SpacesInEmptyLinesReview extends AbstractSpacesInEmptyLines {
12
13
    const NAME = 'spaces_in_empty_lines_review';
14
15
16
    /**
17
     * @inheritdoc
18
     */
19
    public function getName() {
20
      return self::NAME;
21
    }
22
23
24
    /**
25
     * @return string
26
     */
27
    public function getDescription() {
28
      return 'Check if file contains empty lines with spaces';
29
    }
30
31
32
    /**
33
     * @inheritdoc
34
     */
35
    public function process(File $file, Report $report) {
36
      $collection = \Funivan\PhpTokenizer\Collection::createFromString($file->getContent()->get());
37
38
      $tokens = $this->findTokens($collection);
39
40
      $lastInvalidToken = $this->getLastInvalidToken($collection);
41
      if (null !== $lastInvalidToken) {
42
        $tokens->append($lastInvalidToken);
43
      }
44
45
      if ($tokens->count() === 0) {
46
        return;
47
      }
48
49
      $lines = [];
50
      foreach ($tokens as $token) {
51
        $line = $token->getLine();
52
        $line++; # Our token start in previous line
53
        if (isset($lines[$line])) {
54
          continue;
55
        }
56
57
        $lines[$line] = true;
58
59
        $report->addMessage($file, $this, 'File contains empty lines with spaces.', $line);
60
      }
61
62
    }
63
64
  }