ClassMethodReference   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 19
dl 0
loc 53
ccs 21
cts 21
cp 1
rs 10
c 0
b 0
f 0
wmc 7

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getMethodName() 0 3 1
A __construct() 0 25 4
A getName() 0 3 1
A getClassName() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace UsageFinder;
6
7
use InvalidArgumentException;
8
use function count;
9
use function explode;
10
use function sprintf;
11
use function trim;
12
13
final class ClassMethodReference
14
{
15
    /** @var string */
16
    private $name;
17
18
    /** @var string */
19
    private $className;
20
21
    /** @var string */
22
    private $methodName;
23
24 13
    public function __construct(string $name)
25
    {
26 13
        if ($name === '') {
27 1
            throw new InvalidArgumentException(
28 1
                'Invalid ClassMethodReference, empty string given. Format must be ClassName::methodName.'
29
            );
30
        }
31
32 12
        $this->name = $name;
33
34 12
        $e = explode('::', $this->name);
35
36 12
        if (count($e) < 2) {
37 1
            throw new InvalidArgumentException(
38 1
                sprintf('Invalid ClassMethodReference, "%s" given. Format must be ClassName::methodName.', $name)
39
            );
40
        }
41
42 11
        [$this->className, $this->methodName] = $e;
43
44 11
        $this->methodName = trim($this->methodName);
45
46 11
        if ($this->methodName === '') {
47 2
            throw new InvalidArgumentException(
48 2
                sprintf('You must specify a method name to find. "%s" given.', $name)
49
            );
50
        }
51 9
    }
52
53 7
    public function getName() : string
54
    {
55 7
        return $this->name;
56
    }
57
58 7
    public function getClassName() : string
59
    {
60 7
        return $this->className;
61
    }
62
63 7
    public function getMethodName() : string
64
    {
65 7
        return $this->methodName;
66
    }
67
}
68