Completed
Pull Request — master (#12)
by Chuck
02:12
created

Fqsen   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 89.47%

Importance

Changes 0
Metric Value
dl 0
loc 64
c 0
b 0
f 0
wmc 5
lcom 0
cbo 0
ccs 17
cts 19
cp 0.8947
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
B __construct() 0 24 3
A __toString() 0 4 1
A getName() 0 4 1
1
<?php
2
/**
3
 * phpDocumentor
4
 *
5
 * PHP Version 5.5
6
 *
7
 * @copyright 2010-2015 Mike van Riel / Naenius (http://www.naenius.com)
8
 * @license   http://www.opensource.org/licenses/mit-license.php MIT
9
 * @link      http://phpdoc.org
10
 */
11
12
namespace phpDocumentor\Reflection;
13
14
/**
15
 * Value Object for Fqsen.
16
 *
17
 * @link https://github.com/phpDocumentor/fig-standards/blob/master/proposed/phpdoc-meta.md
18
 */
19
final class Fqsen
20
{
21
    /**
22
     * @var string full quallified class name
23
     */
24
    private $fqsen;
25
26
    /**
27
     * @var string name of the element without path.
28
     */
29
    private $name;
30
31
    /**
32
     * Initializes the object.
33
     *
34
     * @param string $fqsen
35
     *
36
     * @throws \InvalidArgumentException when $fqsen is not matching the format.
37
     */
38 17
    public function __construct($fqsen)
39
    {
40 17
        $matches = [];
41 17
        $result = preg_match(
42 17
            '/^\\\\([a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff\\\\]*)?(?:[:]{2}\\$?([a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff]*))?(?:\\(\\))?$/',
43 17
            $fqsen,
44 17
            $matches
45
        );
46
47 17
        if ($result === 0) {
48 4
            throw new \InvalidArgumentException(
49 4
                sprintf('"%s" is not a valid Fqsen.', $fqsen)
50
            );
51
        }
52
53 13
        $this->fqsen = $fqsen;
54
55 13
        if (isset($matches[2])) {
56 3
            $this->name = $matches[2];
57
        } else {
58 10
            $matches = explode('\\', $fqsen);
59 10
            $this->name = trim(end($matches), '()');
60
        }
61 13
    }
62
63
    /**
64
     * converts this class to string.
65
     *
66
     * @return string
67
     */
68 1
    public function __toString()
69
    {
70 1
        return $this->fqsen;
71
    }
72
73
    /**
74
     * Returns the name of the element without path.
75
     *
76
     * @return string
77
     */
78
    public function getName()
79
    {
80
        return $this->name;
81
    }
82
}
83