Skip to content

Commit 5463f8d

Browse files
authored
Merge pull request #207 from orklah/static-analysis
More static analysis fixes
2 parents 45e5409 + 8641f53 commit 5463f8d

23 files changed

+62
-58
lines changed

phpcs.xml.dist

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
<arg value="p"/>
99

1010
<rule ref="phpDocumentor">
11+
<exclude name="SlevomatCodingStandard.Exceptions.ReferenceThrowableOnly.ReferencedGeneralException" />
1112
</rule>
1213

1314
<rule ref="SlevomatCodingStandard.Classes.SuperfluousAbstractClassNaming.SuperfluousPrefix">

psalm.xml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,18 @@
1313
</projectFiles>
1414

1515
<issueHandlers>
16-
<LessSpecificReturnType errorLevel="info" />
17-
1816
<RedundantConditionGivenDocblockType>
1917
<errorLevel type="info">
2018
<!-- Psalm is very strict and believe that because we documented a type, it is redundant to assert it -->
2119
<file name="src/DocBlock/StandardTagFactory.php"/>
2220
</errorLevel>
2321
</RedundantConditionGivenDocblockType>
22+
23+
<PossiblyNullArrayOffset>
24+
<errorLevel type="info">
25+
<!-- Psalm forbid accessing an array with a null offset but it's still working code without notice -->
26+
<file name="src/DocBlock/StandardTagFactory.php"/>
27+
</errorLevel>
28+
</PossiblyNullArrayOffset>
2429
</issueHandlers>
2530
</psalm>

src/DocBlock.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
final class DocBlock
2020
{
2121
/** @var string The opening line for this docblock. */
22-
private $summary = '';
22+
private $summary;
2323

2424
/** @var DocBlock\Description The actual description for this docblock. */
2525
private $description;
@@ -34,10 +34,10 @@ final class DocBlock
3434
private $location;
3535

3636
/** @var bool Is this DocBlock (the start of) a template? */
37-
private $isTemplateStart = false;
37+
private $isTemplateStart;
3838

3939
/** @var bool Does this DocBlock signify the end of a DocBlock template? */
40-
private $isTemplateEnd = false;
40+
private $isTemplateEnd;
4141

4242
/**
4343
* @param DocBlock\Tag[] $tags

src/DocBlock/DescriptionFactory.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ private function removeSuperfluousStartingWhitespace(string $contents) : string
158158

159159
// determine how many whitespace characters need to be stripped
160160
$startingSpaceCount = 9999999;
161-
for ($i = 1; $i < count($lines); ++$i) {
161+
for ($i = 1, $iMax = count($lines); $i < $iMax; ++$i) {
162162
// lines with a no length do not count as they are not indented at all
163163
if (strlen(trim($lines[$i])) === 0) {
164164
continue;
@@ -171,7 +171,7 @@ private function removeSuperfluousStartingWhitespace(string $contents) : string
171171

172172
// strip the number of spaces from each line
173173
if ($startingSpaceCount > 0) {
174-
for ($i = 1; $i < count($lines); ++$i) {
174+
for ($i = 1, $iMax = count($lines); $i < $iMax; ++$i) {
175175
$lines[$i] = substr($lines[$i], $startingSpaceCount);
176176
}
177177
}

src/DocBlock/Serializer.php

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,7 @@ public function getDocComment(DocBlock $docblock) : string
9898
return $comment . $indent . ' */';
9999
}
100100

101-
/**
102-
* @return mixed
103-
*/
104-
private function removeTrailingSpaces(string $indent, string $text)
101+
private function removeTrailingSpaces(string $indent, string $text) : string
105102
{
106103
return str_replace(
107104
sprintf("\n%s * \n", $indent),
@@ -110,10 +107,7 @@ private function removeTrailingSpaces(string $indent, string $text)
110107
);
111108
}
112109

113-
/**
114-
* @return mixed
115-
*/
116-
private function addAsterisksForEachLine(string $indent, string $text)
110+
private function addAsterisksForEachLine(string $indent, string $text) : string
117111
{
118112
return str_replace(
119113
"\n",

src/DocBlock/StandardTagFactory.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ private function createTag(string $body, string $name, TypeContext $context) : T
212212
try {
213213
$callable = [$handlerClassName, 'create'];
214214
Assert::isCallable($callable);
215+
/** @phpstan-var callable(string): ?Tag $callable */
215216
$tag = call_user_func_array($callable, $arguments);
216217

217218
return $tag ?? InvalidTag::create($body, $name);
@@ -222,6 +223,8 @@ private function createTag(string $body, string $name, TypeContext $context) : T
222223

223224
/**
224225
* Determines the Fully Qualified Class Name of the Factory or Tag (containing a Factory Method `create`).
226+
*
227+
* @return class-string<StaticMethod>
225228
*/
226229
private function findHandlerClassName(string $tagName, TypeContext $context) : string
227230
{

src/DocBlock/Tag.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ public function getName() : string;
2121

2222
/**
2323
* @return Tag|mixed Class that implements Tag
24+
*
25+
* @phpstan-return ?Tag
2426
*/
2527
public static function create(string $body);
2628

src/DocBlock/Tags/Author.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ final class Author extends BaseTag implements Factory\StaticMethod
2929
protected $name = 'author';
3030

3131
/** @var string The name of the author */
32-
private $authorName = '';
32+
private $authorName;
3333

3434
/** @var string The email of the author */
35-
private $authorEmail = '';
35+
private $authorEmail;
3636

3737
/**
3838
* Initializes this tag with the author name and e-mail.

src/DocBlock/Tags/Deprecated.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ final class Deprecated extends BaseTag implements Factory\StaticMethod
4444
)';
4545

4646
/** @var string|null The version vector. */
47-
private $version = '';
47+
private $version;
4848

4949
public function __construct(?string $version = null, ?Description $description = null)
5050
{

src/DocBlock/Tags/Example.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ final class Example implements Tag, Factory\StaticMethod
3434
* @var bool Whether the file path component represents an URI. This determines how the file portion
3535
* appears at {@link getContent()}.
3636
*/
37-
private $isURI = false;
37+
private $isURI;
3838

3939
/** @var int */
4040
private $startingLine;
@@ -55,7 +55,7 @@ public function __construct(string $filePath, bool $isURI, int $startingLine, in
5555
$this->startingLine = $startingLine;
5656
$this->lineCount = $lineCount;
5757
if ($content !== null) {
58-
$this->content = trim((string) $content);
58+
$this->content = trim($content);
5959
}
6060

6161
$this->isURI = $isURI;

0 commit comments

Comments
 (0)