Skip to content

Commit d874c4d

Browse files
TomasVotrubajaapio
authored andcommitted
add strict_types and typehints
1 parent 94fd000 commit d874c4d

38 files changed

+230
-215
lines changed

src/DocBlock.php

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
<?php
1+
<?php declare(strict_types=1);
2+
23
/**
34
* This file is part of phpDocumentor.
45
*
@@ -40,21 +41,20 @@ final class DocBlock
4041

4142
/**
4243
* @param string $summary
43-
* @param DocBlock\Description $description
4444
* @param DocBlock\Tag[] $tags
4545
* @param Types\Context $context The context in which the DocBlock occurs.
4646
* @param Location $location The location within the file that this DocBlock occurs in.
4747
* @param bool $isTemplateStart
4848
* @param bool $isTemplateEnd
4949
*/
5050
public function __construct(
51-
$summary = '',
51+
string $summary = '',
5252
DocBlock\Description $description = null,
5353
array $tags = [],
5454
Types\Context $context = null,
5555
Location $location = null,
56-
$isTemplateStart = false,
57-
$isTemplateEnd = false
56+
bool $isTemplateStart = false,
57+
bool $isTemplateEnd = false
5858
) {
5959
Assert::string($summary);
6060
Assert::boolean($isTemplateStart);
@@ -77,15 +77,15 @@ public function __construct(
7777
/**
7878
* @return string
7979
*/
80-
public function getSummary()
80+
public function getSummary(): string
8181
{
8282
return $this->summary;
8383
}
8484

8585
/**
8686
* @return DocBlock\Description
8787
*/
88-
public function getDescription()
88+
public function getDescription(): DocBlock\Description
8989
{
9090
return $this->description;
9191
}
@@ -95,7 +95,7 @@ public function getDescription()
9595
*
9696
* @return Types\Context
9797
*/
98-
public function getContext()
98+
public function getContext(): Types\Context
9999
{
100100
return $this->context;
101101
}
@@ -105,7 +105,7 @@ public function getContext()
105105
*
106106
* @return Location
107107
*/
108-
public function getLocation()
108+
public function getLocation(): Location
109109
{
110110
return $this->location;
111111
}
@@ -131,7 +131,7 @@ public function getLocation()
131131
*
132132
* @return boolean
133133
*/
134-
public function isTemplateStart()
134+
public function isTemplateStart(): bool
135135
{
136136
return $this->isTemplateStart;
137137
}
@@ -143,7 +143,7 @@ public function isTemplateStart()
143143
*
144144
* @return boolean
145145
*/
146-
public function isTemplateEnd()
146+
public function isTemplateEnd(): bool
147147
{
148148
return $this->isTemplateEnd;
149149
}
@@ -166,7 +166,7 @@ public function getTags()
166166
*
167167
* @return Tag[]
168168
*/
169-
public function getTagsByName($name)
169+
public function getTagsByName(string $name)
170170
{
171171
Assert::string($name);
172172

@@ -191,7 +191,7 @@ public function getTagsByName($name)
191191
*
192192
* @return bool
193193
*/
194-
public function hasTag($name)
194+
public function hasTag(string $name): bool
195195
{
196196
Assert::string($name);
197197

@@ -210,7 +210,6 @@ public function hasTag($name)
210210
*
211211
* @param Tag $tag The tag to remove.
212212
*
213-
* @return void
214213
*/
215214
public function removeTag(Tag $tagToRemove)
216215
{
@@ -227,7 +226,6 @@ public function removeTag(Tag $tagToRemove)
227226
*
228227
* @param Tag $tag The tag to add.
229228
*
230-
* @return void
231229
*/
232230
private function addTag(Tag $tag)
233231
{

src/DocBlock/Description.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
<?php
1+
<?php declare(strict_types=1);
2+
23
/**
34
* This file is part of phpDocumentor.
45
*
@@ -62,10 +63,8 @@ class Description
6263
* @param string $bodyTemplate
6364
* @param Tag[] $tags
6465
*/
65-
public function __construct($bodyTemplate, array $tags = [])
66+
public function __construct(string $bodyTemplate, array $tags = [])
6667
{
67-
Assert::string($bodyTemplate);
68-
6968
$this->bodyTemplate = $bodyTemplate;
7069
$this->tags = $tags;
7170
}
@@ -84,11 +83,10 @@ public function getTags()
8483
* Renders this description as a string where the provided formatter will format the tags in the expected string
8584
* format.
8685
*
87-
* @param Formatter|null $formatter
8886
*
8987
* @return string
9088
*/
91-
public function render(Formatter $formatter = null)
89+
public function render(Formatter $formatter = null): string
9290
{
9391
if ($formatter === null) {
9492
$formatter = new PassthroughFormatter();
@@ -107,7 +105,7 @@ public function render(Formatter $formatter = null)
107105
*
108106
* @return string
109107
*/
110-
public function __toString()
108+
public function __toString(): string
111109
{
112110
return $this->render();
113111
}

src/DocBlock/DescriptionFactory.php

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
<?php
1+
<?php declare(strict_types=1);
2+
23
/**
34
* This file is part of phpDocumentor.
45
*
@@ -39,7 +40,6 @@ class DescriptionFactory
3940
/**
4041
* Initializes this factory with the means to construct (inline) tags.
4142
*
42-
* @param TagFactory $tagFactory
4343
*/
4444
public function __construct(TagFactory $tagFactory)
4545
{
@@ -50,11 +50,10 @@ public function __construct(TagFactory $tagFactory)
5050
* Returns the parsed text of this description.
5151
*
5252
* @param string $contents
53-
* @param TypeContext $context
5453
*
5554
* @return Description
5655
*/
57-
public function create($contents, TypeContext $context = null)
56+
public function create(string $contents, TypeContext $context = null): Description
5857
{
5958
list($text, $tags) = $this->parse($this->lex($contents), $context);
6059

@@ -68,7 +67,7 @@ public function create($contents, TypeContext $context = null)
6867
*
6968
* @return string[] A series of tokens of which the description text is composed.
7069
*/
71-
private function lex($contents)
70+
private function lex(string $contents)
7271
{
7372
$contents = $this->removeSuperfluousStartingWhitespace($contents);
7473

@@ -103,7 +102,7 @@ private function lex($contents)
103102
)
104103
\}/Sux',
105104
$contents,
106-
null,
105+
0,
107106
PREG_SPLIT_DELIM_CAPTURE
108107
);
109108
}
@@ -112,7 +111,6 @@ private function lex($contents)
112111
* Parses the stream of tokens in to a new set of tokens containing Tags.
113112
*
114113
* @param string[] $tokens
115-
* @param TypeContext $context
116114
*
117115
* @return string[]|Tag[]
118116
*/
@@ -156,7 +154,7 @@ private function parse($tokens, TypeContext $context)
156154
*
157155
* @return string
158156
*/
159-
private function removeSuperfluousStartingWhitespace($contents)
157+
private function removeSuperfluousStartingWhitespace(string $contents): string
160158
{
161159
$lines = explode("\n", $contents);
162160

src/DocBlock/ExampleFinder.php

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
<?php
1+
<?php declare(strict_types=1);
2+
23
/**
34
* This file is part of phpDocumentor.
45
*
@@ -28,11 +29,10 @@ class ExampleFinder
2829
/**
2930
* Attempts to find the example contents for the given descriptor.
3031
*
31-
* @param Example $example
3232
*
3333
* @return string
3434
*/
35-
public function find(Example $example)
35+
public function find(Example $example): string
3636
{
3737
$filename = $example->getFilePath();
3838

@@ -49,9 +49,8 @@ public function find(Example $example)
4949
*
5050
* @param string $directory
5151
*
52-
* @return void
5352
*/
54-
public function setSourceDirectory($directory = '')
53+
public function setSourceDirectory(string $directory = '')
5554
{
5655
$this->sourceDirectory = $directory;
5756
}
@@ -61,7 +60,7 @@ public function setSourceDirectory($directory = '')
6160
*
6261
* @return string
6362
*/
64-
public function getSourceDirectory()
63+
public function getSourceDirectory(): string
6564
{
6665
return $this->sourceDirectory;
6766
}
@@ -101,7 +100,7 @@ public function getExampleDirectories()
101100
*
102101
* @return string|null
103102
*/
104-
private function getExampleFileContents($filename)
103+
private function getExampleFileContents(string $filename)
105104
{
106105
$normalizedPath = null;
107106

@@ -133,7 +132,7 @@ private function getExampleFileContents($filename)
133132
*
134133
* @return string
135134
*/
136-
private function getExamplePathFromExampleDirectory($file)
135+
private function getExamplePathFromExampleDirectory(string $file): string
137136
{
138137
return getcwd() . DIRECTORY_SEPARATOR . 'examples' . DIRECTORY_SEPARATOR . $file;
139138
}
@@ -146,7 +145,7 @@ private function getExamplePathFromExampleDirectory($file)
146145
*
147146
* @return string
148147
*/
149-
private function constructExamplePath($directory, $file)
148+
private function constructExamplePath(string $directory, string $file): string
150149
{
151150
return rtrim($directory, '\\/') . DIRECTORY_SEPARATOR . $file;
152151
}
@@ -158,7 +157,7 @@ private function constructExamplePath($directory, $file)
158157
*
159158
* @return string
160159
*/
161-
private function getExamplePathFromSource($file)
160+
private function getExamplePathFromSource(string $file): string
162161
{
163162
return sprintf(
164163
'%s%s%s',

src/DocBlock/Serializer.php

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
<?php
1+
<?php declare(strict_types=1);
2+
23
/**
34
* This file is part of phpDocumentor.
45
*
@@ -44,7 +45,7 @@ class Serializer
4445
* @param int|null $lineLength The max length of a line or NULL to disable line wrapping.
4546
* @param DocBlock\Tags\Formatter $tagFormatter A custom tag formatter, defaults to PassthroughFormatter.
4647
*/
47-
public function __construct($indent = 0, $indentString = ' ', $indentFirstLine = true, $lineLength = null, $tagFormatter = null)
48+
public function __construct(int $indent = 0, string $indentString = ' ', bool $indentFirstLine = true, int $lineLength = null, DocBlock\Tags\Formatter $tagFormatter = null)
4849
{
4950
Assert::integer($indent);
5051
Assert::string($indentString);
@@ -66,7 +67,7 @@ public function __construct($indent = 0, $indentString = ' ', $indentFirstLine =
6667
*
6768
* @return string The serialized doc block.
6869
*/
69-
public function getDocComment(DocBlock $docblock)
70+
public function getDocComment(DocBlock $docblock): string
7071
{
7172
$indent = str_repeat($this->indentString, $this->indent);
7273
$firstIndent = $this->isFirstLineIndented ? $indent : '';
@@ -114,11 +115,10 @@ private function addAsterisksForEachLine($indent, $text)
114115
}
115116

116117
/**
117-
* @param DocBlock $docblock
118118
* @param $wrapLength
119119
* @return string
120120
*/
121-
private function getSummaryAndDescriptionTextBlock(DocBlock $docblock, $wrapLength)
121+
private function getSummaryAndDescriptionTextBlock(DocBlock $docblock, $wrapLength): string
122122
{
123123
$text = $docblock->getSummary() . ((string)$docblock->getDescription() ? "\n\n" . $docblock->getDescription()
124124
: '');
@@ -131,13 +131,12 @@ private function getSummaryAndDescriptionTextBlock(DocBlock $docblock, $wrapLeng
131131
}
132132

133133
/**
134-
* @param DocBlock $docblock
135134
* @param $wrapLength
136135
* @param $indent
137136
* @param $comment
138137
* @return string
139138
*/
140-
private function addTagBlock(DocBlock $docblock, $wrapLength, $indent, $comment)
139+
private function addTagBlock(DocBlock $docblock, $wrapLength, $indent, $comment): string
141140
{
142141
foreach ($docblock->getTags() as $tag) {
143142
$tagText = $this->tagFormatter->format($tag);

0 commit comments

Comments
 (0)