FunctionCallVisitor   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 5
eloc 8
c 2
b 0
f 1
dl 0
loc 30
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 2 1
A enterNode() 0 11 4
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace Drupal\qa\Plugin\QaCheck\Dependencies;
6
7
use PhpParser\Node\Expr\FuncCall;
8
use PhpParser\NodeVisitorAbstract;
9
use PhpParser\Node;
10
11
/**
12
 * Class FunctionCallVisitor extract the names of called functions.
13
 *
14
 * @see \Drupal\qa\Plugin\QaCheck\Dependencies\Undeclared::functionCalls()
15
 */
16
class FunctionCallVisitor extends NodeVisitorAbstract {
17
18
  /**
19
   * The visitor write pad.
20
   *
21
   * @var array
22
   */
23
  public $pad;
24
25
  /**
26
   * FunctionCallVisitor constructor.
27
   */
28
  public function __construct() {
29
    $this->pad = [];
30
  }
31
32
  /**
33
   * {@inheritdoc}
34
   */
35
  public function enterNode(Node $node) {
36
    // Why this test ?
37
    // - Method calls need a different handling, using MethodCall.
38
    // - Closure calls are named by the variable holding them, and are
39
    //   necessarily defined, so don't need to be tracked.
40
    if ($node instanceof FuncCall && isset($node->name->parts)) {
41
      $func = implode('\\', $node->name->parts);
42
      if (!isset($this->pad[$func])) {
43
        $this->pad[$func] = [];
44
      }
45
      $this->pad[$func][] = $node->getAttribute('startLine') ?? '?';
46
    }
47
  }
48
49
}
50