PhpClass   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 66
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 90%

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 4
dl 0
loc 66
ccs 18
cts 20
cp 0.9
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A addMethods() 0 6 2
A addMethod() 0 4 1
A hasMethod() 0 4 1
A getMethods() 0 4 1
A getMethod() 0 8 2
1
<?php declare(strict_types=1);
2
3
namespace Bigwhoop\Trumpet\CodeParsing\Php;
4
5
use Bigwhoop\Trumpet\Exceptions\OutOfBoundsException;
6
7
final class PhpClass
8
{
9
    use FullyQualifiedNameTrait;
10
    use SourceTrait;
11
12
    /** @var PhpMethod[] */
13
    private $methods = [];
14
15
    /**
16
     * @param string      $name
17
     * @param PhpMethod[] $methods
18
     * @param string      $source
19
     */
20 10
    public function __construct(string $name, array $methods = [], string $source = '')
21
    {
22 10
        $this->name = $name;
23 10
        $this->addMethods($methods);
24 10
        $this->source = $source;
25 10
    }
26
    
27 10
    public function addMethods(array $methods)
28
    {
29 10
        foreach ($methods as $method) {
30
            $this->addMethod($method);
31
        }
32 10
    }
33
    
34 8
    public function addMethod(PhpMethod $method)
35
    {
36 8
        $this->methods[$method->getName()] = $method;
37 8
    }
38
39
    /**
40
     * @param string $name
41
     *
42
     * @return bool
43
     */
44 4
    public function hasMethod($name)
45
    {
46 4
        return array_key_exists($name, $this->methods);
47
    }
48
49
    /**
50
     * @return PhpMethod[]
51
     */
52 1
    public function getMethods()
53
    {
54 1
        return $this->methods;
55
    }
56
57
    /**
58
     * @param string $name
59
     *
60
     * @return PhpMethod
61
     *
62
     * @throws OutOfBoundsException
63
     */
64 3
    public function getMethod($name)
65
    {
66 3
        if (!array_key_exists($name, $this->methods)) {
67
            throw new OutOfBoundsException("Method '$name' is not available.");
68
        }
69
70 3
        return $this->methods[$name];
71
    }
72
}
73