diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml
index 41f337a..0100cf9 100644
--- a/.github/workflows/push.yml
+++ b/.github/workflows/push.yml
@@ -180,7 +180,7 @@ jobs:
args: analyse src --configuration phpstan.neon
psalm:
- name: Psaml
+ name: Psalm
runs-on: ${{ matrix.operating-system }}
strategy:
matrix:
diff --git a/examples/04-adding-your-own-tag.php b/examples/04-adding-your-own-tag.php
index e3c5ee6..63ba5bf 100644
--- a/examples/04-adding-your-own-tag.php
+++ b/examples/04-adding-your-own-tag.php
@@ -84,7 +84,7 @@ final class MyTag extends BaseTag implements StaticMethod
* @see Tag for the interface declaration of the `create` method.
* @see Tag::create() for more information on this method's workings.
*/
- public static function create(string $body, DescriptionFactory $descriptionFactory = null, Context $context = null): MyTag
+ public static function create(string $body, DescriptionFactory $descriptionFactory = null, Context $context = null): self
{
Assert::notNull($descriptionFactory);
diff --git a/psalm.xml b/psalm.xml
index 4b0caa7..7324a2c 100644
--- a/psalm.xml
+++ b/psalm.xml
@@ -26,5 +26,20 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/DocBlock/DescriptionFactory.php b/src/DocBlock/DescriptionFactory.php
index 8f94e15..0501c3c 100644
--- a/src/DocBlock/DescriptionFactory.php
+++ b/src/DocBlock/DescriptionFactory.php
@@ -160,7 +160,7 @@ class DescriptionFactory
$startingSpaceCount = 9999999;
for ($i = 1, $iMax = count($lines); $i < $iMax; ++$i) {
// lines with a no length do not count as they are not indented at all
- if (strlen(trim($lines[$i])) === 0) {
+ if (trim($lines[$i]) === '') {
continue;
}
diff --git a/src/DocBlock/StandardTagFactory.php b/src/DocBlock/StandardTagFactory.php
index 0a5568e..9a58c29 100644
--- a/src/DocBlock/StandardTagFactory.php
+++ b/src/DocBlock/StandardTagFactory.php
@@ -71,8 +71,8 @@ final class StandardTagFactory implements TagFactory
public const REGEX_TAGNAME = '[\w\-\_\\\\:]+';
/**
- * @var array> An array with a tag as a key, and an
- * FQCN to a class that handles it as an array value.
+ * @var array> An array with a tag as a key, and an
+ * FQCN to a class that handles it as an array value.
*/
private $tagHandlerMappings = [
'author' => Author::class,
@@ -97,7 +97,7 @@ final class StandardTagFactory implements TagFactory
];
/**
- * @var array> An array with a anotation s a key, and an
+ * @var array> An array with a anotation s a key, and an
* FQCN to a class that handles it as an array value.
*/
private $annotationMappings = [];
@@ -125,7 +125,7 @@ final class StandardTagFactory implements TagFactory
*
* @see self::registerTagHandler() to add a new tag handler to the existing default list.
*
- * @param array> $tagHandlers
+ * @param array> $tagHandlers
*/
public function __construct(FqsenResolver $fqsenResolver, ?array $tagHandlers = null)
{
@@ -224,7 +224,7 @@ final class StandardTagFactory implements TagFactory
/**
* Determines the Fully Qualified Class Name of the Factory or Tag (containing a Factory Method `create`).
*
- * @return class-string
+ * @return class-string
*/
private function findHandlerClassName(string $tagName, TypeContext $context) : string
{
diff --git a/src/DocBlock/TagFactory.php b/src/DocBlock/TagFactory.php
index 1602d67..0d318d1 100644
--- a/src/DocBlock/TagFactory.php
+++ b/src/DocBlock/TagFactory.php
@@ -14,7 +14,6 @@ declare(strict_types=1);
namespace phpDocumentor\Reflection\DocBlock;
use InvalidArgumentException;
-use phpDocumentor\Reflection\DocBlock\Tags\Factory\StaticMethod;
use phpDocumentor\Reflection\Types\Context as TypeContext;
interface TagFactory
@@ -70,9 +69,9 @@ interface TagFactory
* to register the name of a tag with the FQCN of a 'Tag Handler'. The Tag handler should implement
* the {@see Tag} interface (and thus the create method).
*
- * @param string $tagName Name of tag to register a handler for. When registering a namespaced
+ * @param string $tagName Name of tag to register a handler for. When registering a namespaced
* tag, the full name, along with a prefixing slash MUST be provided.
- * @param class-string $handler FQCN of handler.
+ * @param class-string $handler FQCN of handler.
*
* @throws InvalidArgumentException If the tag name is not a string.
* @throws InvalidArgumentException If the tag name is namespaced (contains backslashes) but
diff --git a/src/DocBlock/Tags/Author.php b/src/DocBlock/Tags/Author.php
index 048dd48..f3c49ad 100644
--- a/src/DocBlock/Tags/Author.php
+++ b/src/DocBlock/Tags/Author.php
@@ -16,7 +16,6 @@ namespace phpDocumentor\Reflection\DocBlock\Tags;
use InvalidArgumentException;
use function filter_var;
use function preg_match;
-use function strlen;
use function trim;
use const FILTER_VALIDATE_EMAIL;
@@ -72,7 +71,7 @@ final class Author extends BaseTag implements Factory\StaticMethod
*/
public function __toString() : string
{
- return $this->authorName . (strlen($this->authorEmail) ? ' <' . $this->authorEmail . '>' : '');
+ return $this->authorName . ($this->authorEmail !== '' ? ' <' . $this->authorEmail . '>' : '');
}
/**
diff --git a/src/DocBlock/Tags/Factory/StaticMethod.php b/src/DocBlock/Tags/Factory/StaticMethod.php
index b21a3f0..f6f0bb5 100644
--- a/src/DocBlock/Tags/Factory/StaticMethod.php
+++ b/src/DocBlock/Tags/Factory/StaticMethod.php
@@ -13,6 +13,9 @@ declare(strict_types=1);
namespace phpDocumentor\Reflection\DocBlock\Tags\Factory;
+/**
+ * @deprecated This contract is totally covered by Tag contract. Every class using StaticMethod also use Tag
+ */
interface StaticMethod
{
/**
diff --git a/src/DocBlock/Tags/Method.php b/src/DocBlock/Tags/Method.php
index e9b7a85..834f1bd 100644
--- a/src/DocBlock/Tags/Method.php
+++ b/src/DocBlock/Tags/Method.php
@@ -154,7 +154,7 @@ final class Method extends BaseTag implements Factory\StaticMethod
$argumentsExploded = explode(',', $argumentLines);
foreach ($argumentsExploded as $argument) {
$argument = explode(' ', self::stripRestArg(trim($argument)), 2);
- if ($argument[0][0] === '$') {
+ if (strpos($argument[0], '$') === 0) {
$argumentName = substr($argument[0], 1);
$argumentType = new Mixed_();
} else {
diff --git a/src/DocBlock/Tags/Param.php b/src/DocBlock/Tags/Param.php
index 48d158b..7f94361 100644
--- a/src/DocBlock/Tags/Param.php
+++ b/src/DocBlock/Tags/Param.php
@@ -23,7 +23,6 @@ use function array_shift;
use function array_unshift;
use function implode;
use function preg_split;
-use function strlen;
use function strpos;
use function substr;
use const PREG_SPLIT_DELIM_CAPTURE;
@@ -71,7 +70,7 @@ final class Param extends TagWithType implements Factory\StaticMethod
$isVariadic = false;
// if the first item that is encountered is not a variable; it is a type
- if ($firstPart && (strlen($firstPart) > 0) && ($firstPart[0] !== '$')) {
+ if ($firstPart && $firstPart[0] !== '$') {
$type = $typeResolver->resolve($firstPart, $context);
} else {
// first part is not a type; we should prepend it to the parts array for further processing
@@ -79,10 +78,7 @@ final class Param extends TagWithType implements Factory\StaticMethod
}
// if the next item starts with a $ or ...$ it must be the variable name
- if (isset($parts[0])
- && (strlen($parts[0]) > 0)
- && (strpos($parts[0], '$') === 0 || strpos($parts[0], '...$') === 0)
- ) {
+ if (isset($parts[0]) && (strpos($parts[0], '$') === 0 || strpos($parts[0], '...$') === 0)) {
$variableName = array_shift($parts);
array_shift($parts);
diff --git a/src/DocBlock/Tags/Property.php b/src/DocBlock/Tags/Property.php
index 1fd1c00..0da0233 100644
--- a/src/DocBlock/Tags/Property.php
+++ b/src/DocBlock/Tags/Property.php
@@ -23,7 +23,6 @@ use function array_shift;
use function array_unshift;
use function implode;
use function preg_split;
-use function strlen;
use function strpos;
use function substr;
use const PREG_SPLIT_DELIM_CAPTURE;
@@ -63,7 +62,7 @@ final class Property extends TagWithType implements Factory\StaticMethod
$variableName = '';
// if the first item that is encountered is not a variable; it is a type
- if ($firstPart && (strlen($firstPart) > 0) && ($firstPart[0] !== '$')) {
+ if ($firstPart && $firstPart[0] !== '$') {
$type = $typeResolver->resolve($firstPart, $context);
} else {
// first part is not a type; we should prepend it to the parts array for further processing
diff --git a/src/DocBlock/Tags/PropertyRead.php b/src/DocBlock/Tags/PropertyRead.php
index 2144631..af768fb 100644
--- a/src/DocBlock/Tags/PropertyRead.php
+++ b/src/DocBlock/Tags/PropertyRead.php
@@ -23,7 +23,6 @@ use function array_shift;
use function array_unshift;
use function implode;
use function preg_split;
-use function strlen;
use function strpos;
use function substr;
use const PREG_SPLIT_DELIM_CAPTURE;
@@ -63,7 +62,7 @@ final class PropertyRead extends TagWithType implements Factory\StaticMethod
$variableName = '';
// if the first item that is encountered is not a variable; it is a type
- if ($firstPart && (strlen($firstPart) > 0) && ($firstPart[0] !== '$')) {
+ if ($firstPart && $firstPart[0] !== '$') {
$type = $typeResolver->resolve($firstPart, $context);
} else {
// first part is not a type; we should prepend it to the parts array for further processing
diff --git a/src/DocBlock/Tags/PropertyWrite.php b/src/DocBlock/Tags/PropertyWrite.php
index 3353671..34cd75f 100644
--- a/src/DocBlock/Tags/PropertyWrite.php
+++ b/src/DocBlock/Tags/PropertyWrite.php
@@ -23,7 +23,6 @@ use function array_shift;
use function array_unshift;
use function implode;
use function preg_split;
-use function strlen;
use function strpos;
use function substr;
use const PREG_SPLIT_DELIM_CAPTURE;
@@ -63,7 +62,7 @@ final class PropertyWrite extends TagWithType implements Factory\StaticMethod
$variableName = '';
// if the first item that is encountered is not a variable; it is a type
- if ($firstPart && (strlen($firstPart) > 0) && ($firstPart[0] !== '$')) {
+ if ($firstPart && $firstPart[0] !== '$') {
$type = $typeResolver->resolve($firstPart, $context);
} else {
// first part is not a type; we should prepend it to the parts array for further processing
diff --git a/src/DocBlock/Tags/TagWithType.php b/src/DocBlock/Tags/TagWithType.php
index 58d9416..0083d34 100644
--- a/src/DocBlock/Tags/TagWithType.php
+++ b/src/DocBlock/Tags/TagWithType.php
@@ -42,7 +42,7 @@ abstract class TagWithType extends BaseTag
for ($i = 0, $iMax = strlen($body); $i < $iMax; $i++) {
$character = $body[$i];
- if (trim($character) === '' && $nestingLevel === 0) {
+ if ($nestingLevel === 0 && trim($character) === '') {
break;
}
diff --git a/src/DocBlock/Tags/Var_.php b/src/DocBlock/Tags/Var_.php
index 2d867c5..e03f994 100644
--- a/src/DocBlock/Tags/Var_.php
+++ b/src/DocBlock/Tags/Var_.php
@@ -23,7 +23,6 @@ use function array_shift;
use function array_unshift;
use function implode;
use function preg_split;
-use function strlen;
use function strpos;
use function substr;
use const PREG_SPLIT_DELIM_CAPTURE;
@@ -64,7 +63,7 @@ final class Var_ extends TagWithType implements Factory\StaticMethod
$variableName = '';
// if the first item that is encountered is not a variable; it is a type
- if ($firstPart && (strlen($firstPart) > 0) && ($firstPart[0] !== '$')) {
+ if ($firstPart && $firstPart[0] !== '$') {
$type = $typeResolver->resolve($firstPart, $context);
} else {
// first part is not a type; we should prepend it to the parts array for further processing
diff --git a/src/DocBlockFactory.php b/src/DocBlockFactory.php
index 56e2002..cf04e5a 100644
--- a/src/DocBlockFactory.php
+++ b/src/DocBlockFactory.php
@@ -17,8 +17,8 @@ use InvalidArgumentException;
use LogicException;
use phpDocumentor\Reflection\DocBlock\DescriptionFactory;
use phpDocumentor\Reflection\DocBlock\StandardTagFactory;
+use phpDocumentor\Reflection\DocBlock\Tag;
use phpDocumentor\Reflection\DocBlock\TagFactory;
-use phpDocumentor\Reflection\DocBlock\Tags\Factory\StaticMethod;
use Webmozart\Assert\Assert;
use function array_shift;
use function count;
@@ -52,7 +52,7 @@ final class DocBlockFactory implements DocBlockFactoryInterface
/**
* Factory method for easy instantiation.
*
- * @param array> $additionalTags
+ * @param array> $additionalTags
*/
public static function createInstance(array $additionalTags = []) : self
{
@@ -110,7 +110,7 @@ final class DocBlockFactory implements DocBlockFactoryInterface
}
/**
- * @param class-string $handler
+ * @param class-string $handler
*/
public function registerTagHandler(string $tagName, string $handler) : void
{
@@ -124,7 +124,7 @@ final class DocBlockFactory implements DocBlockFactoryInterface
*/
private function stripDocComment(string $comment) : string
{
- $comment = preg_replace('#[ \t]*(?:\/\*\*|\*\/|\*)?[ \t]{0,1}(.*)?#u', '$1', $comment);
+ $comment = preg_replace('#[ \t]*(?:\/\*\*|\*\/|\*)?[ \t]?(.*)?#u', '$1', $comment);
Assert::string($comment);
$comment = trim($comment);
@@ -254,7 +254,7 @@ final class DocBlockFactory implements DocBlockFactoryInterface
{
$result = [];
foreach (explode("\n", $tags) as $tagLine) {
- if (isset($tagLine[0]) && ($tagLine[0] === '@')) {
+ if ($tagLine !== '' && strpos($tagLine, '@') === 0) {
$result[] = $tagLine;
} else {
$result[count($result) - 1] .= "\n" . $tagLine;
diff --git a/src/DocBlockFactoryInterface.php b/src/DocBlockFactoryInterface.php
index 22dc859..ef039a4 100644
--- a/src/DocBlockFactoryInterface.php
+++ b/src/DocBlockFactoryInterface.php
@@ -4,7 +4,7 @@ declare(strict_types=1);
namespace phpDocumentor\Reflection;
-use phpDocumentor\Reflection\DocBlock\Tags\Factory\StaticMethod;
+use phpDocumentor\Reflection\DocBlock\Tag;
// phpcs:ignore SlevomatCodingStandard.Classes.SuperfluousInterfaceNaming.SuperfluousSuffix
interface DocBlockFactoryInterface
@@ -12,7 +12,7 @@ interface DocBlockFactoryInterface
/**
* Factory method for easy instantiation.
*
- * @param array> $additionalTags
+ * @param array> $additionalTags
*/
public static function createInstance(array $additionalTags = []) : DocBlockFactory;