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

AbstractSpacesInEmptyLines   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 6

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 3
c 1
b 0
f 1
lcom 0
cbo 6
dl 0
loc 34
ccs 11
cts 11
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A canProcess() 0 3 1
A findTokens() 0 16 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