Skip to content

Commit 22b3efc

Browse files
TomasVotrubajaapio
authored andcommitted
README: clear spaces, add tests and coverage badges
1 parent b87b1cc commit 22b3efc

File tree

1 file changed

+20
-37
lines changed

1 file changed

+20
-37
lines changed

README.md

Lines changed: 20 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
TypeResolver and FqsenResolver
2-
==============================
1+
# TypeResolver and FqsenResolver
2+
3+
[![Build Status](https://img.shields.io/travis/phpDocumentor/TypeResolver/master.svg?style=flat-square)](https://travis-ci.org/phpDocumentor/TypeResolver)
4+
5+
[![Code Coverage](https://img.shields.io/coveralls/phpDocumentor/TypeResolver/master.svg?style=flat-square)](https://coveralls.io/github/phpDocumentor/TypeResolver)
36

47
The specification on types in DocBlocks (PSR-5) describes various keywords and special constructs
58
but also how to statically resolve the partial name of a Class into a Fully Qualified Class Name (FQCN).
@@ -22,8 +25,7 @@ The easiest way to install this library is with [Composer](https://getcomposer.o
2225

2326
## Examples
2427

25-
Ready to dive in and don't want to read through all that text below? Just consult the [examples](examples) folder and
26-
check which type of action that your want to accomplish.
28+
Ready to dive in and don't want to read through all that text below? Just consult the [examples](examples) folder and check which type of action that your want to accomplish.
2729

2830
## On Types and Element Names
2931

@@ -59,8 +61,7 @@ Where the FqsenResolver can resolve:
5961

6062
## Resolving a type
6163

62-
In order to resolve a type you will have to instantiate the class `\phpDocumentor\Reflection\TypeResolver`
63-
and call its `resolve` method like this:
64+
In order to resolve a type you will have to instantiate the class `\phpDocumentor\Reflection\TypeResolver` and call its `resolve` method like this:
6465

6566
```php
6667
$typeResolver = new \phpDocumentor\Reflection\TypeResolver();
@@ -71,31 +72,24 @@ In this example you will receive a Value Object of class `\phpDocumentor\Reflect
7172
elements, one of type `\phpDocumentor\Reflection\Types\String_` and one of type
7273
`\phpDocumentor\Reflection\Types\Integer`.
7374

74-
The real power of this resolver is in its capability to expand partial class names into fully qualified class names; but
75-
in order to do that we need an additional `\phpDocumentor\Reflection\Types\Context` class that will inform the resolver
76-
in which namespace the given expression occurs and which namespace aliases (or imports) apply.
75+
The real power of this resolver is in its capability to expand partial class names into fully qualified class names; but in order to do that we need an additional `\phpDocumentor\Reflection\Types\Context` class that will inform the resolver in which namespace the given expression occurs and which namespace aliases (or imports) apply.
7776

7877
## Resolving an FQSEN
7978

80-
A Fully Qualified Structural Element Name is a reference to another element in your code bases and can be resolved using
81-
the `\phpDocumentor\Reflection\FqsenResolver` class' `resolve` method, like this:
79+
A Fully Qualified Structural Element Name is a reference to another element in your code bases and can be resolved using the `\phpDocumentor\Reflection\FqsenResolver` class' `resolve` method, like this:
8280

8381
```php
8482
$fqsenResolver = new \phpDocumentor\Reflection\FqsenResolver();
8583
$fqsen = $fqsenResolver->resolve('\phpDocumentor\Reflection\FqsenResolver::resolve()');
8684
```
8785

88-
In this example we resolve a Fully Qualified Structural Element Name (meaning that it includes the full namespace, class
89-
name and element name) and receive a Value Object of type `\phpDocumentor\Reflection\Fqsen`.
86+
In this example we resolve a Fully Qualified Structural Element Name (meaning that it includes the full namespace, class name and element name) and receive a Value Object of type `\phpDocumentor\Reflection\Fqsen`.
9087

91-
The real power of this resolver is in its capability to expand partial element names into Fully Qualified Structural
92-
Element Names; but in order to do that we need an additional `\phpDocumentor\Reflection\Types\Context` class that will
93-
inform the resolver in which namespace the given expression occurs and which namespace aliases (or imports) apply.
88+
The real power of this resolver is in its capability to expand partial element names into Fully Qualified Structural Element Names; but in order to do that we need an additional `\phpDocumentor\Reflection\Types\Context` class that will inform the resolver in which namespace the given expression occurs and which namespace aliases (or imports) apply.
9489

9590
## Resolving partial Classes and Structural Element Names
9691

97-
Perhaps the best feature of this library is that it knows how to resolve partial class names into fully qualified class
98-
names.
92+
Perhaps the best feature of this library is that it knows how to resolve partial class names into fully qualified class names.
9993

10094
For example, you have this file:
10195

@@ -117,9 +111,8 @@ class Classy
117111
```
118112

119113
Suppose that you would want to resolve (and expand) the type in the `@var` tag and the element name in the `@see` tag.
120-
For the resolvers to know how to expand partial names you have to provide a bit of _Context_ for them by instantiating
121-
a new class named `\phpDocumentor\Reflection\Types\Context` with the name of the namespace and the aliases that are in
122-
play.
114+
115+
For the resolvers to know how to expand partial names you have to provide a bit of _Context_ for them by instantiating a new class named `\phpDocumentor\Reflection\Types\Context` with the name of the namespace and the aliases that are in play.
123116

124117
### Creating a Context
125118

@@ -132,9 +125,7 @@ $context = new \phpDocumentor\Reflection\Types\Context(
132125
);
133126
```
134127

135-
Or by using the `\phpDocumentor\Reflection\Types\ContextFactory` to instantiate a new context based on a Reflector
136-
object or by providing the namespace that you'd like to extract and the source code of the file in which the given
137-
type expression occurs.
128+
Or by using the `\phpDocumentor\Reflection\Types\ContextFactory` to instantiate a new context based on a Reflector object or by providing the namespace that you'd like to extract and the source code of the file in which the given type expression occurs.
138129

139130
```php
140131
$contextFactory = new \phpDocumentor\Reflection\Types\ContextFactory();
@@ -150,8 +141,7 @@ $context = $contextFactory->createForNamespace('\My\Example', file_get_contents(
150141

151142
### Using the Context
152143

153-
After you have obtained a Context it is just a matter of passing it along with the `resolve` method of either Resolver
154-
class as second argument and the Resolvers will take this into account when resolving partial names.
144+
After you have obtained a Context it is just a matter of passing it along with the `resolve` method of either Resolver class as second argument and the Resolvers will take this into account when resolving partial names.
155145

156146
To obtain the resolved class name for the `@var` tag in the example above you can do:
157147

@@ -160,24 +150,17 @@ $typeResolver = new \phpDocumentor\Reflection\TypeResolver();
160150
$type = $typeResolver->resolve('Types\Context', $context);
161151
```
162152

163-
When you do this you will receive an object of class `\phpDocumentor\Reflection\Types\Object_` for which you can call
164-
the `getFqsen` method to receive a Value Object that represents the complete FQSEN. So that would be
165-
`phpDocumentor\Reflection\Types\Context`.
153+
When you do this you will receive an object of class `\phpDocumentor\Reflection\Types\Object_` for which you can call the `getFqsen` method to receive a Value Object that represents the complete FQSEN. So that would be `phpDocumentor\Reflection\Types\Context`.
166154

167155
> Why is the FQSEN wrapped in another object `Object_`?
168156
>
169-
> The resolve method of the TypeResolver only returns object with the interface `Type` and the FQSEN is a common
170-
> type that does not represent a Type. Also: in some cases a type can represent an "Untyped Object", meaning that it
171-
> is an object (signified by the `object` keyword) but does not refer to a specific element using an FQSEN.
157+
> The resolve method of the TypeResolver only returns object with the interface `Type` and the FQSEN is a common type that does not represent a Type. Also: in some cases a type can represent an "Untyped Object", meaning that it is an object (signified by the `object` keyword) but does not refer to a specific element using an FQSEN.
172158
173-
Another example is on how to resolve the FQSEN of a method as can be seen with the `@see` tag in the example above. To
174-
resolve that you can do the following:
159+
Another example is on how to resolve the FQSEN of a method as can be seen with the `@see` tag in the example above. To resolve that you can do the following:
175160

176161
```php
177162
$fqsenResolver = new \phpDocumentor\Reflection\FqsenResolver();
178163
$type = $fqsenResolver->resolve('Classy::otherFunction()', $context);
179164
```
180165

181-
Because Classy is a Class in the current namespace its FQSEN will have the `My\Example` namespace and by calling the
182-
`resolve` method of the FQSEN Resolver you will receive an `Fqsen` object that refers to
183-
`\My\Example\Classy::otherFunction()`.
166+
Because Classy is a Class in the current namespace its FQSEN will have the `My\Example` namespace and by calling the `resolve` method of the FQSEN Resolver you will receive an `Fqsen` object that refers to `\My\Example\Classy::otherFunction()`.

0 commit comments

Comments
 (0)