ClassMethodReference::getMethodName()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
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