AbstractLineAfterOpenTag::canProcess()   A
last analyzed

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 0
Metric Value
dl 0
loc 3
c 0
b 0
f 0
ccs 0
cts 2
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 2
1
<?php
2
3
  namespace Funivan\Cs\Tools\Php\LineAfterOpenTag;
4
5
  use Funivan\Cs\FileTool\FileTool;
6
  use Funivan\Cs\Fs\File;
7
  use Funivan\Cs\Fs\FileFilter;
8
  use Funivan\PhpTokenizer\Collection;
9
10
  /**
11
   *
12
   */
13
  abstract class AbstractLineAfterOpenTag implements FileTool {
14
15
    /**
16
     * @inheritdoc
17
     */
18
    public function canProcess(File $file) {
19
      return (new FileFilter())->notDeleted()->extension(['php'])->isValid($file);
20
    }
21
22
23
    /**
24
     * @param Collection $collection
25
     * @return LineTokenData[]
26
     */
27 13
    protected function getInvalidStartTokens(Collection $collection) {
28
29
30 13
      $data = [];
31
32
33 13
      foreach ($collection as $tag) {
34 13
        if (T_OPEN_TAG !== $tag->getType()) {
35 13
          continue;
36
        }
37
38
39 13
        $value = $tag->getValue();
40 13
        $next = $collection->getNext();
41 13
        $whitespaceToken = null;
42 13
        if ($next->getType() === T_WHITESPACE) {
43 12
          $value = $value . $next->getValue();
44 12
          $whitespaceToken = $next;
45
        }
46
47
48 13
        $num = count(explode("\n", $value));
49 13
        if ($num !== 3) {
50 13
          $data[] = new LineTokenData($num, $tag, $whitespaceToken);
51
        }
52
53
      }
54
55 13
      return $data;
56
    }
57
58
  }