InvalidPropertyFinder::find()   B
last analyzed

Complexity

Conditions 2
Paths 1

Size

Total Lines 29
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 21
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 29
ccs 21
cts 21
cp 1
rs 8.8571
c 0
b 0
f 0
cc 2
eloc 20
nc 1
nop 1
crap 2
1
<?php
2
3
  namespace Funivan\Cs\Tools\Php\RedundantNullPropertyValue;
4
5
  use Funivan\PhpTokenizer\Collection;
6
  use Funivan\PhpTokenizer\Pattern\PatternMatcher;
7
  use Funivan\PhpTokenizer\Pattern\Patterns\ClassPattern;
8
  use Funivan\PhpTokenizer\QuerySequence\QuerySequence;
9
  use Funivan\PhpTokenizer\Strategy\Strict;
10
11
  /**
12
   *
13
   */
14
  class InvalidPropertyFinder {
15
16
    /**
17
     * @param Collection $collection
18
     * @return PropertyDefinition[]
19
     */
20 15
    public static function find(Collection $collection) {
21 15
      $result = [];
22
23 15
      (new PatternMatcher($collection))
24 15
        ->apply(new ClassPattern())
25 15
        ->apply(function (QuerySequence $q) use (&$result) {
26
27
28 13
          $q->strict((new Strict())->valueIs(['public', 'protected', 'private']));
29 13
          $q->possible(T_WHITESPACE);
30 13
          $q->possible('static');
31 13
          $q->possible(T_WHITESPACE);
32 13
          $variable = $q->strict(T_VARIABLE);
33
34 13
          $tokensToRemove = [];
35 13
          $tokensToRemove[] = $q->possible(T_WHITESPACE);
36 13
          $tokensToRemove[] = $q->strict('=');
37 13
          $tokensToRemove[] = $q->possible(T_WHITESPACE);
38 13
          $tokensToRemove[] = $q->strict('null');
39 13
          $tokensToRemove[] = $q->possible(T_WHITESPACE);
40 13
          $q->strict(';');
41
42 13
          if ($q->isValid()) {
43 10
            $result[] = new PropertyDefinition($variable, $tokensToRemove);
44
          }
45 15
        });
46
47 15
      return $result;
48
    }
49
50
  }