mirror of
https://github.com/barryvdh/ReflectionDocBlock.git
synced 2026-08-18 01:57:13 +00:00
Apply more strict type checking
This commit is contained in:
@@ -13,7 +13,7 @@ fix-code-style:
|
|||||||
.PHONY: static-code-analysis
|
.PHONY: static-code-analysis
|
||||||
static-code-analysis: vendor ## Runs a static code analysis with phpstan/phpstan and vimeo/psalm
|
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/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
|
.PHONY: test
|
||||||
test: test-unit ## Runs all test suites with phpunit/phpunit
|
test: test-unit ## Runs all test suites with phpunit/phpunit
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ class ExampleFinder
|
|||||||
$filename = $example->getFilePath();
|
$filename = $example->getFilePath();
|
||||||
|
|
||||||
$file = $this->getExampleFileContents($filename);
|
$file = $this->getExampleFileContents($filename);
|
||||||
if (!$file) {
|
if ($file === null) {
|
||||||
return sprintf('** File not found : %s **', $filename);
|
return sprintf('** File not found : %s **', $filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -112,7 +112,7 @@ class ExampleFinder
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$normalizedPath) {
|
if ($normalizedPath === null) {
|
||||||
if (is_readable($this->getExamplePathFromSource($filename))) {
|
if (is_readable($this->getExamplePathFromSource($filename))) {
|
||||||
$normalizedPath = $this->getExamplePathFromSource($filename);
|
$normalizedPath = $this->getExamplePathFromSource($filename);
|
||||||
} elseif (is_readable($this->getExamplePathFromExampleDirectory($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;
|
return $lines !== false ? $lines : null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -82,7 +82,7 @@ class Serializer
|
|||||||
$indent = str_repeat($this->indentString, $this->indent);
|
$indent = str_repeat($this->indentString, $this->indent);
|
||||||
$firstIndent = $this->isFirstLineIndented ? $indent : '';
|
$firstIndent = $this->isFirstLineIndented ? $indent : '';
|
||||||
// 3 === strlen(' * ')
|
// 3 === strlen(' * ')
|
||||||
$wrapLength = $this->lineLength ? $this->lineLength - strlen($indent) - 3 : null;
|
$wrapLength = $this->lineLength !== null ? $this->lineLength - strlen($indent) - 3 : null;
|
||||||
|
|
||||||
$text = $this->removeTrailingSpaces(
|
$text = $this->removeTrailingSpaces(
|
||||||
$indent,
|
$indent,
|
||||||
|
|||||||
@@ -166,14 +166,14 @@ final class StandardTagFactory implements TagFactory
|
|||||||
|
|
||||||
public function addService(object $service, ?string $alias = null): 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} */
|
/** {@inheritDoc} */
|
||||||
public function registerTagHandler(string $tagName, $handler): void
|
public function registerTagHandler(string $tagName, $handler): void
|
||||||
{
|
{
|
||||||
Assert::stringNotEmpty($tagName);
|
Assert::stringNotEmpty($tagName);
|
||||||
if (strpos($tagName, '\\') && $tagName[0] !== '\\') {
|
if (strpos($tagName, '\\') !== false && $tagName[0] !== '\\') {
|
||||||
throw new InvalidArgumentException(
|
throw new InvalidArgumentException(
|
||||||
'A namespaced tag must have a leading backslash as it must be fully qualified'
|
'A namespaced tag must have a leading backslash as it must be fully qualified'
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ final class Deprecated extends BaseTag implements Factory\StaticMethod
|
|||||||
?DescriptionFactory $descriptionFactory = null,
|
?DescriptionFactory $descriptionFactory = null,
|
||||||
?TypeContext $context = null
|
?TypeContext $context = null
|
||||||
): self {
|
): self {
|
||||||
if (empty($body)) {
|
if ($body === null || $body === '') {
|
||||||
return new static();
|
return new static();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -160,7 +160,7 @@ final class Param extends TagWithType implements Factory\StaticMethod
|
|||||||
}
|
}
|
||||||
|
|
||||||
$variableName = '';
|
$variableName = '';
|
||||||
if ($this->variableName) {
|
if ($this->variableName !== null && $this->variableName !== '') {
|
||||||
$variableName .= ($this->isReference ? '&' : '') . ($this->isVariadic ? '...' : '');
|
$variableName .= ($this->isReference ? '&' : '') . ($this->isVariadic ? '...' : '');
|
||||||
$variableName .= '$' . $this->variableName;
|
$variableName .= '$' . $this->variableName;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -111,13 +111,13 @@ final class Property extends TagWithType implements Factory\StaticMethod
|
|||||||
*/
|
*/
|
||||||
public function __toString(): string
|
public function __toString(): string
|
||||||
{
|
{
|
||||||
if ($this->description) {
|
if ($this->description !== null) {
|
||||||
$description = $this->description->render();
|
$description = $this->description->render();
|
||||||
} else {
|
} else {
|
||||||
$description = '';
|
$description = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->variableName) {
|
if ($this->variableName !== null && $this->variableName !== '') {
|
||||||
$variableName = '$' . $this->variableName;
|
$variableName = '$' . $this->variableName;
|
||||||
} else {
|
} else {
|
||||||
$variableName = '';
|
$variableName = '';
|
||||||
|
|||||||
@@ -111,13 +111,13 @@ final class PropertyRead extends TagWithType implements Factory\StaticMethod
|
|||||||
*/
|
*/
|
||||||
public function __toString(): string
|
public function __toString(): string
|
||||||
{
|
{
|
||||||
if ($this->description) {
|
if ($this->description !== null) {
|
||||||
$description = $this->description->render();
|
$description = $this->description->render();
|
||||||
} else {
|
} else {
|
||||||
$description = '';
|
$description = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->variableName) {
|
if ($this->variableName !== null && $this->variableName !== '') {
|
||||||
$variableName = '$' . $this->variableName;
|
$variableName = '$' . $this->variableName;
|
||||||
} else {
|
} else {
|
||||||
$variableName = '';
|
$variableName = '';
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ final class Since extends BaseTag implements Factory\StaticMethod
|
|||||||
?DescriptionFactory $descriptionFactory = null,
|
?DescriptionFactory $descriptionFactory = null,
|
||||||
?TypeContext $context = null
|
?TypeContext $context = null
|
||||||
): ?self {
|
): ?self {
|
||||||
if (empty($body)) {
|
if ($body === null || $body === '') {
|
||||||
return new static();
|
return new static();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -89,7 +89,7 @@ final class Since extends BaseTag implements Factory\StaticMethod
|
|||||||
*/
|
*/
|
||||||
public function __toString(): string
|
public function __toString(): string
|
||||||
{
|
{
|
||||||
if ($this->description) {
|
if ($this->description !== null) {
|
||||||
$description = $this->description->render();
|
$description = $this->description->render();
|
||||||
} else {
|
} else {
|
||||||
$description = '';
|
$description = '';
|
||||||
|
|||||||
@@ -111,13 +111,13 @@ final class Var_ extends TagWithType implements Factory\StaticMethod
|
|||||||
*/
|
*/
|
||||||
public function __toString(): string
|
public function __toString(): string
|
||||||
{
|
{
|
||||||
if ($this->description) {
|
if ($this->description !== null) {
|
||||||
$description = $this->description->render();
|
$description = $this->description->render();
|
||||||
} else {
|
} else {
|
||||||
$description = '';
|
$description = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->variableName) {
|
if ($this->variableName !== null && $this->variableName !== '') {
|
||||||
$variableName = '$' . $this->variableName;
|
$variableName = '$' . $this->variableName;
|
||||||
} else {
|
} else {
|
||||||
$variableName = '';
|
$variableName = '';
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ final class Version extends BaseTag implements Factory\StaticMethod
|
|||||||
?DescriptionFactory $descriptionFactory = null,
|
?DescriptionFactory $descriptionFactory = null,
|
||||||
?TypeContext $context = null
|
?TypeContext $context = null
|
||||||
): ?self {
|
): ?self {
|
||||||
if (empty($body)) {
|
if ($body === null || $body === '') {
|
||||||
return new static();
|
return new static();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user