diff --git a/Makefile b/Makefile index 9b28eb9..4d798eb 100644 --- a/Makefile +++ b/Makefile @@ -13,7 +13,7 @@ fix-code-style: .PHONY: static-code-analysis static-code-analysis: vendor ## Runs a static code analysis with phpstan/phpstan and vimeo/psalm docker run -it --rm -v${PWD}:/opt/project -w /opt/project php:7.4 vendor/bin/phpstan --configuration=phpstan.neon - docker run -it --rm -v${PWD}:/opt/project -w /opt/project php:7.4 vendor/bin/psalm + docker run -it --rm -v${PWD}:/opt/project -w /opt/project php:7.4 vendor/bin/psalm.phar .PHONY: test test: test-unit ## Runs all test suites with phpunit/phpunit diff --git a/src/DocBlock/ExampleFinder.php b/src/DocBlock/ExampleFinder.php index 7136e28..0fb24a6 100644 --- a/src/DocBlock/ExampleFinder.php +++ b/src/DocBlock/ExampleFinder.php @@ -44,7 +44,7 @@ class ExampleFinder $filename = $example->getFilePath(); $file = $this->getExampleFileContents($filename); - if (!$file) { + if ($file === null) { return sprintf('** File not found : %s **', $filename); } @@ -112,7 +112,7 @@ class ExampleFinder } } - if (!$normalizedPath) { + if ($normalizedPath === null) { if (is_readable($this->getExamplePathFromSource($filename))) { $normalizedPath = $this->getExamplePathFromSource($filename); } elseif (is_readable($this->getExamplePathFromExampleDirectory($filename))) { @@ -122,7 +122,7 @@ class ExampleFinder } } - $lines = $normalizedPath && is_readable($normalizedPath) ? file($normalizedPath) : false; + $lines = $normalizedPath !== null && is_readable($normalizedPath) ? file($normalizedPath) : false; return $lines !== false ? $lines : null; } diff --git a/src/DocBlock/Serializer.php b/src/DocBlock/Serializer.php index 31ca29c..2c257dd 100644 --- a/src/DocBlock/Serializer.php +++ b/src/DocBlock/Serializer.php @@ -82,7 +82,7 @@ class Serializer $indent = str_repeat($this->indentString, $this->indent); $firstIndent = $this->isFirstLineIndented ? $indent : ''; // 3 === strlen(' * ') - $wrapLength = $this->lineLength ? $this->lineLength - strlen($indent) - 3 : null; + $wrapLength = $this->lineLength !== null ? $this->lineLength - strlen($indent) - 3 : null; $text = $this->removeTrailingSpaces( $indent, diff --git a/src/DocBlock/StandardTagFactory.php b/src/DocBlock/StandardTagFactory.php index e9537a5..e08db7b 100644 --- a/src/DocBlock/StandardTagFactory.php +++ b/src/DocBlock/StandardTagFactory.php @@ -166,14 +166,14 @@ final class StandardTagFactory implements TagFactory public function addService(object $service, ?string $alias = null): void { - $this->serviceLocator[$alias ?: get_class($service)] = $service; + $this->serviceLocator[$alias ?? get_class($service)] = $service; } /** {@inheritDoc} */ public function registerTagHandler(string $tagName, $handler): void { Assert::stringNotEmpty($tagName); - if (strpos($tagName, '\\') && $tagName[0] !== '\\') { + if (strpos($tagName, '\\') !== false && $tagName[0] !== '\\') { throw new InvalidArgumentException( 'A namespaced tag must have a leading backslash as it must be fully qualified' ); diff --git a/src/DocBlock/Tags/Deprecated.php b/src/DocBlock/Tags/Deprecated.php index a55cd91..fff591f 100644 --- a/src/DocBlock/Tags/Deprecated.php +++ b/src/DocBlock/Tags/Deprecated.php @@ -62,7 +62,7 @@ final class Deprecated extends BaseTag implements Factory\StaticMethod ?DescriptionFactory $descriptionFactory = null, ?TypeContext $context = null ): self { - if (empty($body)) { + if ($body === null || $body === '') { return new static(); } diff --git a/src/DocBlock/Tags/Param.php b/src/DocBlock/Tags/Param.php index 19b1b5f..6d46686 100644 --- a/src/DocBlock/Tags/Param.php +++ b/src/DocBlock/Tags/Param.php @@ -160,7 +160,7 @@ final class Param extends TagWithType implements Factory\StaticMethod } $variableName = ''; - if ($this->variableName) { + if ($this->variableName !== null && $this->variableName !== '') { $variableName .= ($this->isReference ? '&' : '') . ($this->isVariadic ? '...' : ''); $variableName .= '$' . $this->variableName; } diff --git a/src/DocBlock/Tags/Property.php b/src/DocBlock/Tags/Property.php index 1287b6c..3328b08 100644 --- a/src/DocBlock/Tags/Property.php +++ b/src/DocBlock/Tags/Property.php @@ -111,13 +111,13 @@ final class Property extends TagWithType implements Factory\StaticMethod */ public function __toString(): string { - if ($this->description) { + if ($this->description !== null) { $description = $this->description->render(); } else { $description = ''; } - if ($this->variableName) { + if ($this->variableName !== null && $this->variableName !== '') { $variableName = '$' . $this->variableName; } else { $variableName = ''; diff --git a/src/DocBlock/Tags/PropertyRead.php b/src/DocBlock/Tags/PropertyRead.php index 2cf8e61..8ac1eb0 100644 --- a/src/DocBlock/Tags/PropertyRead.php +++ b/src/DocBlock/Tags/PropertyRead.php @@ -111,13 +111,13 @@ final class PropertyRead extends TagWithType implements Factory\StaticMethod */ public function __toString(): string { - if ($this->description) { + if ($this->description !== null) { $description = $this->description->render(); } else { $description = ''; } - if ($this->variableName) { + if ($this->variableName !== null && $this->variableName !== '') { $variableName = '$' . $this->variableName; } else { $variableName = ''; diff --git a/src/DocBlock/Tags/Since.php b/src/DocBlock/Tags/Since.php index 24400fa..8ec59e9 100644 --- a/src/DocBlock/Tags/Since.php +++ b/src/DocBlock/Tags/Since.php @@ -59,7 +59,7 @@ final class Since extends BaseTag implements Factory\StaticMethod ?DescriptionFactory $descriptionFactory = null, ?TypeContext $context = null ): ?self { - if (empty($body)) { + if ($body === null || $body === '') { return new static(); } @@ -89,7 +89,7 @@ final class Since extends BaseTag implements Factory\StaticMethod */ public function __toString(): string { - if ($this->description) { + if ($this->description !== null) { $description = $this->description->render(); } else { $description = ''; diff --git a/src/DocBlock/Tags/Var_.php b/src/DocBlock/Tags/Var_.php index 0a79ab9..b0bd8c2 100644 --- a/src/DocBlock/Tags/Var_.php +++ b/src/DocBlock/Tags/Var_.php @@ -111,13 +111,13 @@ final class Var_ extends TagWithType implements Factory\StaticMethod */ public function __toString(): string { - if ($this->description) { + if ($this->description !== null) { $description = $this->description->render(); } else { $description = ''; } - if ($this->variableName) { + if ($this->variableName !== null && $this->variableName !== '') { $variableName = '$' . $this->variableName; } else { $variableName = ''; diff --git a/src/DocBlock/Tags/Version.php b/src/DocBlock/Tags/Version.php index 1ed25d1..8ea96ed 100644 --- a/src/DocBlock/Tags/Version.php +++ b/src/DocBlock/Tags/Version.php @@ -59,7 +59,7 @@ final class Version extends BaseTag implements Factory\StaticMethod ?DescriptionFactory $descriptionFactory = null, ?TypeContext $context = null ): ?self { - if (empty($body)) { + if ($body === null || $body === '') { return new static(); }