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

AbstractSpacesInEmptyLines::canProcess()   A

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 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 3
ccs 0
cts 0
cp 0
rs 10
cc 1
eloc 2
nc 1
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