Skip to content

Commit 1fc3b8a

Browse files
committed
Initial commit
0 parents  commit 1fc3b8a

36 files changed

+2028
-0
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.idea
2+
composer.lock
3+
vendor

.scrutinizer.yml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
before_commands:
2+
- "composer install --no-dev --prefer-source"
3+
4+
tools:
5+
external_code_coverage:
6+
enabled: false
7+
timeout: 300
8+
filter:
9+
excluded_paths: ["tests", "vendor"]
10+
php_code_coverage:
11+
enabled: false
12+
test_command: phpunit -c phpunit.xml.dist
13+
php_code_sniffer:
14+
enabled: true
15+
config:
16+
standard: PSR2
17+
filter:
18+
paths: ["src/*", "tests/*"]
19+
php_cpd:
20+
enabled: true
21+
excluded_dirs: ["tests", "vendor"]
22+
php_cs_fixer:
23+
enabled: true
24+
config:
25+
level: all
26+
filter:
27+
paths: ["src/*", "tests/*"]
28+
php_loc:
29+
enabled: true
30+
excluded_dirs: ["tests", "vendor"]
31+
php_mess_detector:
32+
enabled: true
33+
config:
34+
ruleset: phpmd.xml.dist
35+
design_rules: { eval_expression: false }
36+
filter:
37+
paths: ["src/*"]
38+
php_pdepend:
39+
enabled: true
40+
excluded_dirs: ["tests", "vendor"]
41+
php_analyzer:
42+
enabled: true
43+
filter:
44+
paths: ["src/*", "tests/*"]
45+
sensiolabs_security_checker: true

.travis.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
language: php
2+
php:
3+
- 5.5
4+
- 5.6
5+
- 7.0
6+
- hhvm
7+
- hhvm-nightly
8+
9+
matrix:
10+
allow_failures:
11+
- php: hhvm
12+
- php: hhvm-nightly
13+
14+
script:
15+
- vendor/bin/phpunit
16+
17+
before_script:
18+
- sudo apt-get -qq update > /dev/null
19+
- phpenv rehash > /dev/null
20+
- composer selfupdate --quiet
21+
- composer install --no-interaction --prefer-source --dev
22+
23+
notifications:
24+
irc: "irc.freenode.org#phpdocumentor"
25+
email:
26+
27+

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2010 Mike van Riel
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in
13+
all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
THE SOFTWARE.

composer.json

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"name": "phpdocumentor/type-resolver",
3+
"type": "library",
4+
"license": "MIT",
5+
"authors": [
6+
{"name": "Mike van Riel", "email": "[email protected]"}
7+
],
8+
"require": {
9+
"php": ">=5.5",
10+
"phpdocumentor/reflection-common": "dev-master@dev"
11+
},
12+
"autoload": {
13+
"psr-4": {"phpDocumentor\\Reflection\\": ["src/"]}
14+
},
15+
"autoload-dev": {
16+
"psr-4": {"phpDocumentor\\Reflection\\": ["tests/unit"]}
17+
},
18+
"require-dev": {
19+
"phpunit/phpunit": "^4.6",
20+
"mockery/mockery": "^0.9.4"
21+
},
22+
"extra": {
23+
"branch-alias": {
24+
"dev-master": "1.0.x-dev"
25+
}
26+
}
27+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
use phpDocumentor\Reflection\Types\Resolver;
4+
5+
require '../vendor/autoload.php';
6+
7+
$typeResolver = new Resolver();
8+
9+
// Will yield an object of type phpDocumentor\Types\Compound
10+
var_export($typeResolver->resolveType('string|integer'));
11+
12+
// Will return the string "string|int"
13+
var_dump((string)$typeResolver->resolveType('string|integer'));

examples/02-resolving-classes.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
use phpDocumentor\Reflection\Types\Context;
4+
use phpDocumentor\Reflection\Types\Resolver;
5+
6+
require '../vendor/autoload.php';
7+
8+
$typeResolver = new Resolver();
9+
10+
// Will use the namespace and aliases to resolve to \phpDocumentor\Types\Resolver|Mockery\MockInterface
11+
$context = new Context('\phpDocumentor', [ 'm' => 'Mockery' ]);
12+
var_dump((string)$typeResolver->resolveType('Types\Resolver|m\MockInterface', $context));
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
use phpDocumentor\Reflection\Types\Context;
4+
use phpDocumentor\Reflection\Types\Resolver;
5+
6+
require '../vendor/autoload.php';
7+
8+
$typeResolver = new Resolver();
9+
10+
// Will use the namespace and aliases to resolve to a Fqsen object
11+
$context = new Context('\phpDocumentor\Types');
12+
13+
// Method named: \phpDocumentor\Types\Types\Resolver::resolveFqsen()
14+
var_dump((string)$typeResolver->resolveFqsen('Types\Resolver::resolveFqsen()', $context));
15+
16+
// Property named: \phpDocumentor\Types\Types\Resolver::$keyWords
17+
var_dump((string)$typeResolver->resolveFqsen('Types\Resolver::$keyWords', $context));
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
use phpDocumentor\Reflection\Types\ContextFactory;
4+
use phpDocumentor\Reflection\Types\Resolver;
5+
6+
require '../vendor/autoload.php';
7+
require 'Classy.php';
8+
9+
$typeResolver = new Resolver();
10+
$contextFactory = new ContextFactory();
11+
$context = $contextFactory->createFromClassReflector(new ReflectionClass('My\\Example\\Classy'));
12+
13+
// Class named: \phpDocumentor\Reflection\Types\Resolver
14+
var_dump((string)$typeResolver->resolveType('Types\Resolver', $context));
15+
16+
// String
17+
var_dump((string)$typeResolver->resolveType('string', $context));
18+
19+
// Property named: \phpDocumentor\Reflection\Types\Resolver::$keyWords
20+
var_dump((string)$typeResolver->resolveFqsen('Types\Resolver::$keyWords', $context));
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
use phpDocumentor\Reflection\Types\Context;
4+
use phpDocumentor\Reflection\Types\ContextFactory;
5+
use phpDocumentor\Reflection\Types\Resolver;
6+
7+
require '../vendor/autoload.php';
8+
9+
$typeResolver = new Resolver();
10+
$contextFactory = new ContextFactory();
11+
$context = $contextFactory->createForNamespace('My\Example', file_get_contents('Classy.php'));
12+
13+
// Class named: \phpDocumentor\Reflection\Types\Resolver
14+
var_dump((string)$typeResolver->resolveType('Types\Resolver', $context));
15+
16+
// String
17+
var_dump((string)$typeResolver->resolveType('string', $context));
18+
19+
// Property named: \phpDocumentor\Reflection\Types\Resolver::$keyWords
20+
var_dump((string)$typeResolver->resolveFqsen('Types\Resolver::$keyWords', $context));

examples/Classy.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
namespace My\Example;
4+
5+
use Mockery as m;
6+
use phpDocumentor\Reflection\Types;
7+
8+
class Classy
9+
{
10+
public function __construct()
11+
{
12+
13+
}
14+
}

phpunit.xml.dist

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
3+
<phpunit colors="true" strict="true" bootstrap="vendor/autoload.php">
4+
<testsuites>
5+
<testsuite name="phpDocumentor\Reflection\DocBlock">
6+
<directory>./tests/</directory>
7+
</testsuite>
8+
</testsuites>
9+
<filter>
10+
<whitelist>
11+
<directory suffix=".php">./src/</directory>
12+
</whitelist>
13+
<blacklist>
14+
<directory>./vendor/</directory>
15+
</blacklist>
16+
</filter>
17+
</phpunit>

src/FqsenFactory.php

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
<?php
2+
/**
3+
* This file is part of phpDocumentor.
4+
*
5+
* For the full copyright and license information, please view the LICENSE
6+
* file that was distributed with this source code.
7+
*
8+
* @copyright 2010-2015 Mike van Riel<[email protected]>
9+
* @license http://www.opensource.org/licenses/mit-license.php MIT
10+
* @link http://phpdoc.org
11+
*/
12+
13+
namespace phpDocumentor\Reflection;
14+
15+
use phpDocumentor\Reflection\Types\Context;
16+
17+
class FqsenFactory
18+
{
19+
/** @var string Definition of the NAMESPACE operator in PHP */
20+
const OPERATOR_NAMESPACE = '\\';
21+
22+
public function create($fqsen, Context $context = null)
23+
{
24+
if ($context === null) {
25+
$context = new Context('');
26+
}
27+
28+
if ($this->isFqsen($fqsen)) {
29+
return new Fqsen($fqsen);
30+
}
31+
32+
return $this->resolvePartialStructuralElementName($fqsen, $context);
33+
}
34+
35+
/**
36+
* Tests whether the given type is a Fully Qualified Structural Element Name.
37+
*
38+
* @param string $type
39+
*
40+
* @return bool
41+
*/
42+
private function isFqsen($type)
43+
{
44+
return strpos($type, self::OPERATOR_NAMESPACE) === 0;
45+
}
46+
47+
/**
48+
* Resolves a partial Structural Element Name (i.e. `Reflection\DocBlock`) to its FQSEN representation
49+
* (i.e. `\phpDocumentor\Reflection\DocBlock`) based on the Namespace and aliases mentioned in the Context.
50+
*
51+
* @param string $type
52+
* @param Context $context
53+
*
54+
* @return Fqsen
55+
*/
56+
private function resolvePartialStructuralElementName($type, Context $context)
57+
{
58+
$typeParts = explode(self::OPERATOR_NAMESPACE, $type, 2);
59+
60+
$namespaceAliases = $context->getNamespaceAliases();
61+
62+
// if the first segment is not an alias; prepend namespace name and return
63+
if (!isset($namespaceAliases[$typeParts[0]])) {
64+
$namespace = $context->getNamespace();
65+
if ('' !== $namespace) {
66+
$namespace .= self::OPERATOR_NAMESPACE;
67+
}
68+
69+
return new Fqsen(self::OPERATOR_NAMESPACE . $namespace . $type);
70+
}
71+
72+
$typeParts[0] = $namespaceAliases[$typeParts[0]];
73+
74+
return new Fqsen(self::OPERATOR_NAMESPACE . implode(self::OPERATOR_NAMESPACE, $typeParts));
75+
}
76+
}

src/Type.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
/**
3+
* This file is part of phpDocumentor.
4+
*
5+
* For the full copyright and license information, please view the LICENSE
6+
* file that was distributed with this source code.
7+
*
8+
* @copyright 2010-2015 Mike van Riel<[email protected]>
9+
* @license http://www.opensource.org/licenses/mit-license.php MIT
10+
* @link http://phpdoc.org
11+
*/
12+
13+
namespace phpDocumentor\Reflection;
14+
15+
interface Type
16+
{
17+
public function __toString();
18+
}

0 commit comments

Comments
 (0)