MethodIdentifier   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 47
rs 10
c 0
b 0
f 0
wmc 7
lcom 1
cbo 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A wrap() 0 4 2
A isValidMethodIdReference() 0 4 1
A fromMethodIdReference() 0 10 2
A __toString() 0 4 1
1
<?php
2
3
namespace Psalm\Internal;
4
5
class MethodIdentifier
6
{
7
    public $fq_class_name;
8
    public $method_name;
9
10
    /**
11
     * @param  string $fq_class_name
12
     * @param  lowercase-string $method_name
0 ignored issues
show
Documentation introduced by
The doc-type lowercase-string could not be parsed: Unknown type name "lowercase-string" at position 0. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
13
     */
14
    public function __construct(string $fq_class_name, string $method_name)
15
    {
16
        $this->fq_class_name = $fq_class_name;
17
        $this->method_name = $method_name;
18
    }
19
20
    /**
21
     * Takes any valid reference to a method id and converts
22
     * it into a MethodIdentifier
23
     * @param string|MethodIdentifier $method_id
24
     */
25
    public static function wrap($method_id): self
26
    {
27
        return \is_string($method_id) ? static::fromMethodIdReference($method_id) : $method_id;
28
    }
29
30
    public static function isValidMethodIdReference(string $method_id): bool
31
    {
32
        return \strpos($method_id, '::') !== false;
33
    }
34
35
    public static function fromMethodIdReference(string $method_id): self
36
    {
37
        if (!static::isValidMethodIdReference($method_id)) {
38
            throw new \InvalidArgumentException('Invalid method id reference provided: ' . $method_id);
39
        }
40
        // remove trailing backslash if it exists
41
        $method_id = \preg_replace('/^\\\\/', '', $method_id);
42
        $method_id_parts = \explode('::', $method_id);
43
        return new static($method_id_parts[0], \strtolower($method_id_parts[1]));
44
    }
45
46
    /** @return non-empty-string */
0 ignored issues
show
Documentation introduced by
The doc-type non-empty-string could not be parsed: Unknown type name "non-empty-string" at position 0. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
47
    public function __toString()
48
    {
49
        return $this->fq_class_name . '::' . $this->method_name;
50
    }
51
}
52