ClassLike   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 3
Bugs 0 Features 1
Metric Value
wmc 7
c 3
b 0
f 1
lcom 1
cbo 2
dl 0
loc 38
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getMethod() 0 9 4
A getMethods() 0 9 3
1
<?php
2
3
namespace PhpParser\Node\Stmt;
4
5
use PhpParser\Node;
6
7
abstract class ClassLike extends Node\Stmt {
8
    /** @var string Name */
9
    public $name;
10
    /** @var Node[] Statements */
11
    public $stmts;
12
13
    /**
14
     * Gets all methods defined directly in this class/interface/trait
15
     *
16
     * @return ClassMethod[]
17
     */
18
    public function getMethods() {
19
        $methods = array();
20
        foreach ($this->stmts as $stmt) {
21
            if ($stmt instanceof ClassMethod) {
22
                $methods[] = $stmt;
23
            }
24
        }
25
        return $methods;
26
    }
27
28
    /**
29
     * Gets method with the given name defined directly in this class/interface/trait.
30
     *
31
     * @param string $name Name of the method (compared case-insensitively)
32
     *
33
     * @return ClassMethod|null Method node or null if the method does not exist
34
     */
35
    public function getMethod($name) {
36
        $lowerName = strtolower($name);
37
        foreach ($this->stmts as $stmt) {
38
            if ($stmt instanceof ClassMethod && $lowerName === strtolower($stmt->name)) {
39
                return $stmt;
40
            }
41
        }
42
        return null;
43
    }
44
}
45