Completed
Push — master ( 2cf7e5...0496dc )
by Shcherbak
02:23
created

AbstractSpacesInEmptyLines::getLastInvalidToken()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 7
ccs 5
cts 5
cp 1
rs 9.4285
cc 2
eloc 5
nc 2
nop 1
crap 2
1
<?php
2
3
  namespace Funivan\Cs\Tools\SpacesInEmptyLines;
4
5
  use Funivan\Cs\FileFinder\FileInfo;
6
  use Funivan\Cs\FileProcessor\CanProcessHelper;
7
  use Funivan\Cs\FileProcessor\FileTool;
8
  use Funivan\PhpTokenizer\Query\Query;
9
  use Funivan\PhpTokenizer\Token;
10
11
  /**
12
   *
13
   */
14
  abstract class AbstractSpacesInEmptyLines implements FileTool {
15
16
    /**
17
     * @codeCoverageIgnore
18
     * @param FileInfo $file
19
     * @return boolean
20
     */
21
    public function canProcess(FileInfo $file) {
22
      return (new CanProcessHelper())->notDeleted()->extension(['php', 'html'])->isValid($file);
23
    }
24
25
26
    /**
27
     * @param FileInfo $file
28
     * @return \Funivan\PhpTokenizer\Collection
29
     */
30 4
    protected function findTokens(FileInfo $file) {
31 4
      $tokens = $file->getTokenizer()->getCollection();
32
33 4
      $query = new Query();
34 4
      $query->valueLike('!\n[ ]+\n!');
35 4
      $query->typeIs(T_WHITESPACE);
36
37 4
      return $tokens->find($query);
38
    }
39
40
41
    /**
42
     * @param FileInfo $file
43
     * @return Token
44
     */
45 4
    protected function getLastInvalidToken(FileInfo $file) {
46 4
      $lastToken = $file->getTokenizer()->getCollection()->getLast();
47 4
      if (preg_match('![ ]+\n*$!', $lastToken->getValue())) {
48 2
        return $lastToken;
49
      }
50 2
      return null;
51
    }
52
53
  }
54