Completed
Push — master ( 699ba6...05ec17 )
by Shcherbak
03:15
created

InvalidPropertyFinder   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Test Coverage

Coverage 100%

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
B find() 0 29 2
1
<?
0 ignored issues
show
Security Best Practice introduced by
It is not recommend to use PHP's short opening tag <?, better use <?php, or <?= in case of outputting.

Short opening tags are disabled in PHP’s default configuration. In such a case, all content of this file is output verbatim to the browser without being parsed, or executed.

As a precaution to avoid these problems better use the long opening tag <?php.

Loading history...
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
    public static function find(Collection $collection) {
21
      $result = [];
22
23
      (new PatternMatcher($collection))
24
        ->apply(new ClassPattern())
25
        ->apply(function (QuerySequence $q) use (&$result) {
26
27
28
          $q->strict((new Strict())->valueIs(['public', 'protected', 'private']));
29
          $q->possible(T_WHITESPACE);
30
          $q->possible('static');
31
          $q->possible(T_WHITESPACE);
32
          $variable = $q->strict(T_VARIABLE);
33
34
          $tokensToRemove = [];
35
          $tokensToRemove[] = $q->possible(T_WHITESPACE);
36
          $tokensToRemove[] = $q->strict('=');
37
          $tokensToRemove[] = $q->possible(T_WHITESPACE);
38
          $tokensToRemove[] = $q->strict('null');
39
          $tokensToRemove[] = $q->possible(T_WHITESPACE);
40
          $q->strict(';');
41
42
          if ($q->isValid()) {
43
            $result[] = new PropertyDefinition($variable, $tokensToRemove);
44
          }
45
        });
46
47
      return $result;
48
    }
49
50
  }