Skip to content

Commit

Permalink
Apply more strict type checking
Browse files Browse the repository at this point in the history
  • Loading branch information
jaapio committed Nov 3, 2024
1 parent db271d6 commit f985773
Show file tree
Hide file tree
Showing 11 changed files with 18 additions and 18 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/DocBlock/ExampleFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function find(Example $example): string
$filename = $example->getFilePath();

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

Expand Down Expand Up @@ -112,7 +112,7 @@ private function getExampleFileContents(string $filename): ?array
}
}

if (!$normalizedPath) {
if ($normalizedPath === null) {
if (is_readable($this->getExamplePathFromSource($filename))) {
$normalizedPath = $this->getExamplePathFromSource($filename);
} elseif (is_readable($this->getExamplePathFromExampleDirectory($filename))) {
Expand All @@ -122,7 +122,7 @@ private function getExampleFileContents(string $filename): ?array
}
}

$lines = $normalizedPath && is_readable($normalizedPath) ? file($normalizedPath) : false;
$lines = $normalizedPath !== null && is_readable($normalizedPath) ? file($normalizedPath) : false;

return $lines !== false ? $lines : null;
}
Expand Down
2 changes: 1 addition & 1 deletion src/DocBlock/Serializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public function getDocComment(DocBlock $docblock): string
$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,
Expand Down
4 changes: 2 additions & 2 deletions src/DocBlock/StandardTagFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,14 +166,14 @@ public function addParameter(string $name, $value): void

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'
);
Expand Down
2 changes: 1 addition & 1 deletion src/DocBlock/Tags/Deprecated.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public static function create(
?DescriptionFactory $descriptionFactory = null,
?TypeContext $context = null
): self {
if (empty($body)) {
if ($body === null || $body === '') {
return new static();
}

Expand Down
2 changes: 1 addition & 1 deletion src/DocBlock/Tags/Param.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ public function __toString(): string
}

$variableName = '';
if ($this->variableName) {
if ($this->variableName !== null && $this->variableName !== '') {
$variableName .= ($this->isReference ? '&' : '') . ($this->isVariadic ? '...' : '');
$variableName .= '$' . $this->variableName;
}
Expand Down
4 changes: 2 additions & 2 deletions src/DocBlock/Tags/Property.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,13 @@ public function getVariableName(): ?string
*/
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 = '';
Expand Down
4 changes: 2 additions & 2 deletions src/DocBlock/Tags/PropertyRead.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,13 @@ public function getVariableName(): ?string
*/
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 = '';
Expand Down
4 changes: 2 additions & 2 deletions src/DocBlock/Tags/Since.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public static function create(
?DescriptionFactory $descriptionFactory = null,
?TypeContext $context = null
): ?self {
if (empty($body)) {
if ($body === null || $body === '') {
return new static();
}

Expand Down Expand Up @@ -89,7 +89,7 @@ public function getVersion(): ?string
*/
public function __toString(): string
{
if ($this->description) {
if ($this->description !== null) {
$description = $this->description->render();
} else {
$description = '';
Expand Down
4 changes: 2 additions & 2 deletions src/DocBlock/Tags/Var_.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,13 @@ public function getVariableName(): ?string
*/
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 = '';
Expand Down
2 changes: 1 addition & 1 deletion src/DocBlock/Tags/Version.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public static function create(
?DescriptionFactory $descriptionFactory = null,
?TypeContext $context = null
): ?self {
if (empty($body)) {
if ($body === null || $body === '') {
return new static();
}

Expand Down

0 comments on commit f985773

Please sign in to comment.