Completed
Push — master ( bfc368...43106f )
by Shcherbak
02:26
created

AbstractLineAfterOpenTag::getInvalidStartTokens()   B

Complexity

Conditions 5
Paths 6

Size

Total Lines 29
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 29
rs 8.439
cc 5
eloc 16
nc 6
nop 1
1
<?php
2
3
  namespace Funivan\Cs\Tools\Php\LineAfterOpenTag;
4
5
  use Funivan\Cs\FileFinder\FileInfo;
6
  use Funivan\Cs\FileProcessor\CanProcessHelper;
7
  use Funivan\Cs\FileProcessor\FileTool;
8
9
  /**
10
   *
11
   */
12
  abstract class AbstractLineAfterOpenTag implements FileTool {
13
14
    /**
15
     * @return string* @inheritdoc
0 ignored issues
show
Documentation introduced by
The doc-type string* could not be parsed: Unknown type name "string*" at position 0. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
16
     */
17
    public function canProcess(FileInfo $file) {
18
      return (new CanProcessHelper())->notDeleted()->extension('php')->isValid($file);
19
    }
20
21
22
    /**
23
     * @param FileInfo $file
24
     * @return LineTokenData[]
25
     */
26
    protected function getInvalidStartTokens(FileInfo $file) {
27
      $collection = $file->getTokenizer()->getCollection();
28
29
      $data = [];
30
31
32
      foreach ($collection as $tag) {
33
        if (T_OPEN_TAG !== $tag->getType()) {
34
          continue;
35
        }
36
37
38
        $value = $tag->getValue();
39
        $next = $collection->getNext();
40
        $whitespaceToken = null;
41
        if ($next->getType() === T_WHITESPACE) {
42
          $value = $next->getValue();
43
          $whitespaceToken = $next;
44
        }
45
46
47
        $num = count(explode("\n", $value));
48
        if ($num !== 2) {
49
          $data[] = new LineTokenData($num, $tag, $whitespaceToken);
50
        }
51
      }
52
53
      return $data;
54
    }
55
56
  }