Skip to content

Commit f985773

Browse files
committed
Apply more strict type checking
1 parent db271d6 commit f985773

File tree

11 files changed

+18
-18
lines changed

11 files changed

+18
-18
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ fix-code-style:
1313
.PHONY: static-code-analysis
1414
static-code-analysis: vendor ## Runs a static code analysis with phpstan/phpstan and vimeo/psalm
1515
docker run -it --rm -v${PWD}:/opt/project -w /opt/project php:7.4 vendor/bin/phpstan --configuration=phpstan.neon
16-
docker run -it --rm -v${PWD}:/opt/project -w /opt/project php:7.4 vendor/bin/psalm
16+
docker run -it --rm -v${PWD}:/opt/project -w /opt/project php:7.4 vendor/bin/psalm.phar
1717

1818
.PHONY: test
1919
test: test-unit ## Runs all test suites with phpunit/phpunit

src/DocBlock/ExampleFinder.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public function find(Example $example): string
4444
$filename = $example->getFilePath();
4545

4646
$file = $this->getExampleFileContents($filename);
47-
if (!$file) {
47+
if ($file === null) {
4848
return sprintf('** File not found : %s **', $filename);
4949
}
5050

@@ -112,7 +112,7 @@ private function getExampleFileContents(string $filename): ?array
112112
}
113113
}
114114

115-
if (!$normalizedPath) {
115+
if ($normalizedPath === null) {
116116
if (is_readable($this->getExamplePathFromSource($filename))) {
117117
$normalizedPath = $this->getExamplePathFromSource($filename);
118118
} elseif (is_readable($this->getExamplePathFromExampleDirectory($filename))) {
@@ -122,7 +122,7 @@ private function getExampleFileContents(string $filename): ?array
122122
}
123123
}
124124

125-
$lines = $normalizedPath && is_readable($normalizedPath) ? file($normalizedPath) : false;
125+
$lines = $normalizedPath !== null && is_readable($normalizedPath) ? file($normalizedPath) : false;
126126

127127
return $lines !== false ? $lines : null;
128128
}

src/DocBlock/Serializer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public function getDocComment(DocBlock $docblock): string
8282
$indent = str_repeat($this->indentString, $this->indent);
8383
$firstIndent = $this->isFirstLineIndented ? $indent : '';
8484
// 3 === strlen(' * ')
85-
$wrapLength = $this->lineLength ? $this->lineLength - strlen($indent) - 3 : null;
85+
$wrapLength = $this->lineLength !== null ? $this->lineLength - strlen($indent) - 3 : null;
8686

8787
$text = $this->removeTrailingSpaces(
8888
$indent,

src/DocBlock/StandardTagFactory.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,14 +166,14 @@ public function addParameter(string $name, $value): void
166166

167167
public function addService(object $service, ?string $alias = null): void
168168
{
169-
$this->serviceLocator[$alias ?: get_class($service)] = $service;
169+
$this->serviceLocator[$alias ?? get_class($service)] = $service;
170170
}
171171

172172
/** {@inheritDoc} */
173173
public function registerTagHandler(string $tagName, $handler): void
174174
{
175175
Assert::stringNotEmpty($tagName);
176-
if (strpos($tagName, '\\') && $tagName[0] !== '\\') {
176+
if (strpos($tagName, '\\') !== false && $tagName[0] !== '\\') {
177177
throw new InvalidArgumentException(
178178
'A namespaced tag must have a leading backslash as it must be fully qualified'
179179
);

src/DocBlock/Tags/Deprecated.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public static function create(
6262
?DescriptionFactory $descriptionFactory = null,
6363
?TypeContext $context = null
6464
): self {
65-
if (empty($body)) {
65+
if ($body === null || $body === '') {
6666
return new static();
6767
}
6868

src/DocBlock/Tags/Param.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ public function __toString(): string
160160
}
161161

162162
$variableName = '';
163-
if ($this->variableName) {
163+
if ($this->variableName !== null && $this->variableName !== '') {
164164
$variableName .= ($this->isReference ? '&' : '') . ($this->isVariadic ? '...' : '');
165165
$variableName .= '$' . $this->variableName;
166166
}

src/DocBlock/Tags/Property.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,13 +111,13 @@ public function getVariableName(): ?string
111111
*/
112112
public function __toString(): string
113113
{
114-
if ($this->description) {
114+
if ($this->description !== null) {
115115
$description = $this->description->render();
116116
} else {
117117
$description = '';
118118
}
119119

120-
if ($this->variableName) {
120+
if ($this->variableName !== null && $this->variableName !== '') {
121121
$variableName = '$' . $this->variableName;
122122
} else {
123123
$variableName = '';

src/DocBlock/Tags/PropertyRead.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,13 +111,13 @@ public function getVariableName(): ?string
111111
*/
112112
public function __toString(): string
113113
{
114-
if ($this->description) {
114+
if ($this->description !== null) {
115115
$description = $this->description->render();
116116
} else {
117117
$description = '';
118118
}
119119

120-
if ($this->variableName) {
120+
if ($this->variableName !== null && $this->variableName !== '') {
121121
$variableName = '$' . $this->variableName;
122122
} else {
123123
$variableName = '';

src/DocBlock/Tags/Since.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public static function create(
5959
?DescriptionFactory $descriptionFactory = null,
6060
?TypeContext $context = null
6161
): ?self {
62-
if (empty($body)) {
62+
if ($body === null || $body === '') {
6363
return new static();
6464
}
6565

@@ -89,7 +89,7 @@ public function getVersion(): ?string
8989
*/
9090
public function __toString(): string
9191
{
92-
if ($this->description) {
92+
if ($this->description !== null) {
9393
$description = $this->description->render();
9494
} else {
9595
$description = '';

src/DocBlock/Tags/Var_.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,13 +111,13 @@ public function getVariableName(): ?string
111111
*/
112112
public function __toString(): string
113113
{
114-
if ($this->description) {
114+
if ($this->description !== null) {
115115
$description = $this->description->render();
116116
} else {
117117
$description = '';
118118
}
119119

120-
if ($this->variableName) {
120+
if ($this->variableName !== null && $this->variableName !== '') {
121121
$variableName = '$' . $this->variableName;
122122
} else {
123123
$variableName = '';

0 commit comments

Comments
 (0)