AbstractSpacesInEmptyLines   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 38
c 0
b 0
f 0
wmc 5
lcom 0
cbo 4
ccs 10
cts 10
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A canProcess() 0 3 1
A findTokens() 0 7 1
A getLastInvalidToken() 0 7 3
1
<?php
2
3
  namespace Funivan\Cs\Tools\SpacesInEmptyLines;
4
5
  use Funivan\Cs\FileTool\FileTool;
6
  use Funivan\Cs\Fs\File;
7
  use Funivan\Cs\Fs\FileFilter;
8
  use Funivan\PhpTokenizer\Collection;
9
  use Funivan\PhpTokenizer\Query\Query;
10
  use Funivan\PhpTokenizer\Token;
11
12
  /**
13
   *
14
   */
15
  abstract class AbstractSpacesInEmptyLines implements FileTool {
16
17
    /**
18
     * @codeCoverageIgnore
19
     * @param File $file
20
     * @return boolean
21
     */
22
    public function canProcess(File $file) {
23
      return (new FileFilter())->notDeleted()->extension(['php', 'html'])->isValid($file);
24
    }
25
26
27
    /**
28
     * @param Collection $collection
29
     * @return Collection
30
     */
31 4
    protected function findTokens(Collection $collection) {
32 4
      $query = new Query();
33 4
      $query->valueLike('!\n[ ]+\n!');
34 4
      $query->typeIs(T_WHITESPACE);
35
36 4
      return $collection->find($query);
37
    }
38
39
40
    /**
41
     * @param Collection $collection
42
     * @return Token
43
     */
44 4
    protected function getLastInvalidToken(Collection $collection) {
45 4
      $lastToken = $collection->getLast();
46 4
      if ($lastToken and preg_match('![ ]+\n*$!', $lastToken->getValue())) {
47 2
        return $lastToken;
48
      }
49 2
      return null;
50
    }
51
52
  }
53