Skip to content

Commit f10c8a4

Browse files
committed
Merge branch 'master' of github.com:phpDocumentor/ReflectionCommon
2 parents 8dac756 + 4b22a99 commit f10c8a4

File tree

4 files changed

+90
-12
lines changed

4 files changed

+90
-12
lines changed

src/Fqsen.php

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ final class Fqsen
2323
*/
2424
private $fqsen;
2525

26+
/**
27+
* @var string name of the element without path.
28+
*/
29+
private $name;
30+
2631
/**
2732
* Initializes the object.
2833
*
@@ -32,14 +37,23 @@ final class Fqsen
3237
*/
3338
public function __construct($fqsen)
3439
{
35-
$result = preg_match('/^\\\\([A-Za-z_\\\\]+)(::\\$?[a-zA-Z_]+)?(\\(\\))?$/', $fqsen);
40+
$matches = array();
41+
$result = preg_match('/^\\\\([\\w_\\\\]*)(?:[:]{2}\\$?([\\w_]+))?(?:\\(\\))?$/', $fqsen, $matches);
42+
3643
if ($result === 0) {
3744
throw new \InvalidArgumentException(
3845
sprintf('"%s" is not a valid Fqsen.', $fqsen)
3946
);
4047
}
4148

4249
$this->fqsen = $fqsen;
50+
51+
if (isset($matches[2])) {
52+
$this->name = $matches[2];
53+
} else {
54+
$matches = explode('\\', $fqsen);
55+
$this->name = trim(end($matches), '()');
56+
}
4357
}
4458

4559
/**
@@ -51,4 +65,14 @@ public function __toString()
5165
{
5266
return $this->fqsen;
5367
}
68+
69+
/**
70+
* Returns the name of the element without path.
71+
*
72+
* @return string
73+
*/
74+
public function getName()
75+
{
76+
return $this->name;
77+
}
5478
}

src/Project.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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+
* Interface for project. Since the definition of a project can be different per factory this interface will be small.
16+
*/
17+
interface Project
18+
{
19+
/**
20+
* Returns the name of the project.
21+
*
22+
* @return string
23+
*/
24+
public function getName();
25+
}

src/ProjectFactory.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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+
namespace phpDocumentor\Reflection;
12+
13+
/**
14+
* Interface for project factories. A project factory shall convert a set of files
15+
* into an object implementing the Project interface.
16+
*/
17+
interface ProjectFactory
18+
{
19+
/**
20+
* Creates a project from the set of files.
21+
*
22+
* @param string[] $files
23+
* @return Project
24+
*/
25+
public function create(array $files);
26+
}

tests/unit/FqsenTest.php

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,10 @@ class FqsenTest extends \PHPUnit_Framework_TestCase
2222
* @covers ::__construct
2323
* @dataProvider validFqsenProvider
2424
*/
25-
public function testValidFormats($fqsen)
25+
public function testValidFormats($fqsen, $name)
2626
{
27-
new Fqsen($fqsen);
27+
$instance = new Fqsen($fqsen);
28+
$this->assertEquals($name, $instance->getName());
2829
}
2930

3031
/**
@@ -35,15 +36,17 @@ public function testValidFormats($fqsen)
3536
public function validFqsenProvider()
3637
{
3738
return [
38-
['\My\Space'],
39-
['\My\Space\myFunction()'],
40-
['\My\Space\MY_CONSTANT'],
41-
['\My\Space\MyClass'],
42-
['\My\Space\MyInterface'],
43-
['\My\Space\MyTrait'],
44-
['\My\Space\MyClass::myMethod()'],
45-
['\My\Space\MyClass::$my_property'],
46-
['\My\Space\MyClass::MY_CONSTANT'],
39+
['\\', ''],
40+
['\My\Space', 'Space'],
41+
['\My\Space\myFunction()', 'myFunction'],
42+
['\My\Space\MY_CONSTANT', 'MY_CONSTANT'],
43+
['\My\Space\MY_CONSTANT2', 'MY_CONSTANT2'],
44+
['\My\Space\MyClass', 'MyClass'],
45+
['\My\Space\MyInterface', 'MyInterface'],
46+
['\My\Space\MyTrait', 'MyTrait'],
47+
['\My\Space\MyClass::myMethod()', 'myMethod'],
48+
['\My\Space\MyClass::$my_property', 'my_property'],
49+
['\My\Space\MyClass::MY_CONSTANT', 'MY_CONSTANT'],
4750
];
4851
}
4952

0 commit comments

Comments
 (0)