Skip to content

Commit 4a96758

Browse files
TomasVotrubajaapio
authored andcommitted
add PHP 7.1 typehints
1 parent f9d1a0c commit 4a96758

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+410
-430
lines changed

src/DocBlock.php

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,10 @@ final class DocBlock
4646
*/
4747
public function __construct(
4848
string $summary = '',
49-
DocBlock\Description $description = null,
49+
?DocBlock\Description $description = null,
5050
array $tags = [],
51-
Types\Context $context = null,
52-
Location $location = null,
51+
?Types\Context $context = null,
52+
?Location $location = null,
5353
bool $isTemplateStart = false,
5454
bool $isTemplateEnd = false
5555
) {
@@ -84,7 +84,6 @@ public function getDescription(): DocBlock\Description
8484
/**
8585
* Returns the current context.
8686
*
87-
* @return Types\Context
8887
*/
8988
public function getContext(): Types\Context
9089
{
@@ -118,7 +117,6 @@ public function getLocation(): ?Location
118117
*
119118
* @see self::isTemplateEnd() for the check whether a closing marker was provided.
120119
*
121-
* @return boolean
122120
*/
123121
public function isTemplateStart(): bool
124122
{
@@ -130,7 +128,6 @@ public function isTemplateStart(): bool
130128
*
131129
* @see self::isTemplateStart() for a more complete description of the Docblock Template functionality.
132130
*
133-
* @return boolean
134131
*/
135132
public function isTemplateEnd(): bool
136133
{
@@ -193,7 +190,7 @@ public function hasTag(string $name): bool
193190
*
194191
* @param Tag $tag The tag to remove.
195192
*/
196-
public function removeTag(Tag $tagToRemove)
193+
public function removeTag(Tag $tagToRemove): void
197194
{
198195
foreach ($this->tags as $key => $tag) {
199196
if ($tag === $tagToRemove) {
@@ -208,7 +205,7 @@ public function removeTag(Tag $tagToRemove)
208205
*
209206
* @param Tag $tag The tag to add.
210207
*/
211-
private function addTag(Tag $tag)
208+
private function addTag(Tag $tag): void
212209
{
213210
$this->tags[] = $tag;
214211
}

src/DocBlock/Description.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public function getTags()
8181
* Renders this description as a string where the provided formatter will format the tags in the expected string
8282
* format.
8383
*/
84-
public function render(Formatter $formatter = null): string
84+
public function render(?Formatter $formatter = null): string
8585
{
8686
if ($formatter === null) {
8787
$formatter = new PassthroughFormatter();

src/DocBlock/DescriptionFactory.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,10 @@ public function __construct(TagFactory $tagFactory)
4949
* Returns the parsed text of this description.
5050
*
5151
*
52-
* @return Description
5352
*/
54-
public function create(string $contents, TypeContext $context = null): Description
53+
public function create(string $contents, ?TypeContext $context = null): Description
5554
{
56-
list($text, $tags) = $this->parse($this->lex($contents), $context);
55+
[$text, $tags] = $this->parse($this->lex($contents), $context);
5756

5857
return new Description($text, $tags);
5958
}

src/DocBlock/ExampleFinder.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public function find(Example $example): string
4444
/**
4545
* Registers the project's root directory where an 'examples' folder can be expected.
4646
*/
47-
public function setSourceDirectory(string $directory = '')
47+
public function setSourceDirectory(string $directory = ''): void
4848
{
4949
$this->sourceDirectory = $directory;
5050
}
@@ -62,7 +62,7 @@ public function getSourceDirectory(): string
6262
*
6363
* @param string[] $directories
6464
*/
65-
public function setExampleDirectories(array $directories)
65+
public function setExampleDirectories(array $directories): void
6666
{
6767
$this->exampleDirectories = $directories;
6868
}
@@ -89,9 +89,8 @@ public function getExampleDirectories()
8989
* 4. Checks the path relative to the current working directory for the given filename
9090
*
9191
*
92-
* @return string|null
9392
*/
94-
private function getExampleFileContents(string $filename)
93+
private function getExampleFileContents(string $filename): ?string
9594
{
9695
$normalizedPath = null;
9796

src/DocBlock/StandardTagFactory.php

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
final class StandardTagFactory implements TagFactory
4040
{
4141
/** PCRE regular expression matching a tag name. */
42-
const REGEX_TAGNAME = '[\w\-\_\\\\]+';
42+
public const REGEX_TAGNAME = '[\w\-\_\\\\]+';
4343

4444
/**
4545
* @var string[] An array with a tag as a key, and an FQCN to a class that handles it as an array value.
@@ -92,7 +92,7 @@ final class StandardTagFactory implements TagFactory
9292
*
9393
* @see self::registerTagHandler() to add a new tag handler to the existing default list.
9494
*/
95-
public function __construct(FqsenResolver $fqsenResolver, array $tagHandlers = null)
95+
public function __construct(FqsenResolver $fqsenResolver, ?array $tagHandlers = null)
9696
{
9797
$this->fqsenResolver = $fqsenResolver;
9898
if ($tagHandlers !== null) {
@@ -105,13 +105,13 @@ public function __construct(FqsenResolver $fqsenResolver, array $tagHandlers = n
105105
/**
106106
* {@inheritDoc}
107107
*/
108-
public function create(string $tagLine, TypeContext $context = null): Tag
108+
public function create(string $tagLine, ?TypeContext $context = null): Tag
109109
{
110110
if (! $context) {
111111
$context = new TypeContext('');
112112
}
113113

114-
list($tagName, $tagBody) = $this->extractTagParts($tagLine);
114+
[$tagName, $tagBody] = $this->extractTagParts($tagLine);
115115

116116
if ($tagBody !== '' && $tagBody[0] === '[') {
117117
throw new \InvalidArgumentException(
@@ -125,23 +125,23 @@ public function create(string $tagLine, TypeContext $context = null): Tag
125125
/**
126126
* {@inheritDoc}
127127
*/
128-
public function addParameter(string $name, $value)
128+
public function addParameter(string $name, $value): void
129129
{
130130
$this->serviceLocator[$name] = $value;
131131
}
132132

133133
/**
134134
* {@inheritDoc}
135135
*/
136-
public function addService($service, $alias = null)
136+
public function addService($service, $alias = null): void
137137
{
138138
$this->serviceLocator[$alias ?: get_class($service)] = $service;
139139
}
140140

141141
/**
142142
* {@inheritDoc}
143143
*/
144-
public function registerTagHandler(string $tagName, string $handler)
144+
public function registerTagHandler(string $tagName, string $handler): void
145145
{
146146
Assert::stringNotEmpty($tagName);
147147
Assert::stringNotEmpty($handler);
@@ -184,9 +184,8 @@ private function extractTagParts(string $tagLine)
184184
* body was invalid.
185185
*
186186
*
187-
* @return Tag|null
188187
*/
189-
private function createTag(string $body, string $name, TypeContext $context)
188+
private function createTag(string $body, string $name, TypeContext $context): ?Tag
190189
{
191190
$handlerClassName = $this->findHandlerClassName($name, $context);
192191
$arguments = $this->getArgumentsForParametersFromWiring(

src/DocBlock/Tag.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,14 @@
1717

1818
interface Tag
1919
{
20-
public function getName();
20+
public function getName(): string;
2121

22+
/**
23+
* @return Tag Class that implements Tag
24+
*/
2225
public static function create(string $body);
2326

24-
public function render(Formatter $formatter = null);
27+
public function render(?Formatter $formatter = null): string;
2528

26-
public function __toString();
29+
public function __toString(): string;
2730
}

src/DocBlock/TagFactory.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,9 @@ interface TagFactory
3535
*
3636
* These parameters are injected at the last moment and will override any existing parameter with those names.
3737
*
38-
* @param string $name
3938
* @param mixed $value
4039
*/
41-
public function addParameter(string $name, $value);
40+
public function addParameter(string $name, $value): void;
4241

4342
/**
4443
* Registers a service with the Service Locator using the FQCN of the class or the alias, if provided.
@@ -51,7 +50,7 @@ public function addParameter(string $name, $value);
5150
*
5251
* @param object $service
5352
*/
54-
public function addService($service);
53+
public function addService($service): void;
5554

5655
/**
5756
* Factory method responsible for instantiating the correct sub type.
@@ -62,7 +61,7 @@ public function addService($service);
6261
*
6362
* @return Tag A new tag object.
6463
*/
65-
public function create(string $tagLine, TypeContext $context = null): ?Tag;
64+
public function create(string $tagLine, ?TypeContext $context = null): ?Tag;
6665

6766
/**
6867
* Registers a handler for tags.
@@ -82,5 +81,5 @@ public function create(string $tagLine, TypeContext $context = null): ?Tag;
8281
* @throws \InvalidArgumentException if the handler is not an existing class
8382
* @throws \InvalidArgumentException if the handler does not implement the {@see Tag} interface
8483
*/
85-
public function registerTagHandler(string $tagName, string $handler);
84+
public function registerTagHandler(string $tagName, string $handler): void;
8685
}

src/DocBlock/Tags/BaseTag.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public function getDescription()
4242
return $this->description;
4343
}
4444

45-
public function render(Formatter $formatter = null)
45+
public function render(?Formatter $formatter = null): string
4646
{
4747
if ($formatter === null) {
4848
$formatter = new Formatter\PassthroughFormatter();

src/DocBlock/Tags/Covers.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ final class Covers extends BaseTag implements Factory\StaticMethod
3333
/**
3434
* Initializes this tag.
3535
*/
36-
public function __construct(Fqsen $refers, Description $description = null)
36+
public function __construct(Fqsen $refers, ?Description $description = null)
3737
{
3838
$this->refers = $refers;
3939
$this->description = $description;
@@ -44,9 +44,9 @@ public function __construct(Fqsen $refers, Description $description = null)
4444
*/
4545
public static function create(
4646
string $body,
47-
DescriptionFactory $descriptionFactory = null,
48-
FqsenResolver $resolver = null,
49-
TypeContext $context = null
47+
?DescriptionFactory $descriptionFactory = null,
48+
?FqsenResolver $resolver = null,
49+
?TypeContext $context = null
5050
) {
5151
Assert::notEmpty($body);
5252

@@ -61,7 +61,6 @@ public static function create(
6161
/**
6262
* Returns the structural element this tag refers to.
6363
*
64-
* @return Fqsen
6564
*/
6665
public function getReference(): Fqsen
6766
{

src/DocBlock/Tags/Deprecated.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ final class Deprecated extends BaseTag implements Factory\StaticMethod
2929
* PCRE regular expression matching a version vector.
3030
* Assumes the "x" modifier.
3131
*/
32-
const REGEX_VECTOR = '(?:
32+
public const REGEX_VECTOR = '(?:
3333
# Normal release vectors.
3434
\d\S*
3535
|
@@ -44,7 +44,7 @@ final class Deprecated extends BaseTag implements Factory\StaticMethod
4444
/** @var string The version vector. */
4545
private $version = '';
4646

47-
public function __construct($version = null, Description $description = null)
47+
public function __construct($version = null, ?Description $description = null)
4848
{
4949
Assert::nullOrStringNotEmpty($version);
5050

@@ -57,8 +57,8 @@ public function __construct($version = null, Description $description = null)
5757
*/
5858
public static function create(
5959
?string $body,
60-
DescriptionFactory $descriptionFactory = null,
61-
TypeContext $context = null
60+
?DescriptionFactory $descriptionFactory = null,
61+
?TypeContext $context = null
6262
) {
6363
if (empty($body)) {
6464
return new static();
@@ -81,9 +81,8 @@ public static function create(
8181
/**
8282
* Gets the version section of the tag.
8383
*
84-
* @return string|null
8584
*/
86-
public function getVersion()
85+
public function getVersion(): ?string
8786
{
8887
return $this->version;
8988
}

0 commit comments

Comments
 (0)