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

AbstractSpacesInEmptyLines   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 6

Test Coverage

Coverage 100%

Importance

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

3 Methods

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