Completed
Push — master ( 7a83e2...2cf7e5 )
by Shcherbak
02:26
created

AbstractSpacesInEmptyLines::findTokens()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 16
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 16
ccs 11
cts 11
cp 1
rs 9.4285
cc 2
eloc 10
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
10
  /**
11
   *
12
   */
13
  abstract class AbstractSpacesInEmptyLines implements FileTool {
14
15
    /**
16
     * @codeCoverageIgnore
17
     * @param FileInfo $file
18
     * @return boolean
19
     */
20
    public function canProcess(FileInfo $file) {
21
      return (new CanProcessHelper())->notDeleted()->extension(['php', 'html'])->isValid($file);
22
    }
23
24
25
    /**
26
     * @param FileInfo $file
27
     * @return \Funivan\PhpTokenizer\Collection
28
     */
29 3
    protected function findTokens(FileInfo $file) {
30 3
      $tokens = $file->getTokenizer()->getCollection();
31
32 3
      $query = new Query();
33 3
      $query->valueLike('!\n[ ]+\n!');
34 3
      $query->typeIs(T_WHITESPACE);
35
36 3
      $stripTokens = $tokens->find($query);
37
38 3
      $lastToken = $tokens->getLast();
39 3
      if (preg_match('![ ]+\n*$!', $lastToken->getValue())) {
40 1
        $stripTokens->append($lastToken);
41 1
      }
42
43 3
      return $stripTokens;
44
    }
45
46
  }
47