Merge pull request #212 from orklah/static-fixes

change somes things for SA
This commit is contained in:
Jaap van Otterdijk
2020-02-22 13:28:44 +01:00
committed by GitHub
17 changed files with 44 additions and 36 deletions
+1 -1
View File
@@ -180,7 +180,7 @@ jobs:
args: analyse src --configuration phpstan.neon args: analyse src --configuration phpstan.neon
psalm: psalm:
name: Psaml name: Psalm
runs-on: ${{ matrix.operating-system }} runs-on: ${{ matrix.operating-system }}
strategy: strategy:
matrix: matrix:
+1 -1
View File
@@ -84,7 +84,7 @@ final class MyTag extends BaseTag implements StaticMethod
* @see Tag for the interface declaration of the `create` method. * @see Tag for the interface declaration of the `create` method.
* @see Tag::create() for more information on this method's workings. * @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); Assert::notNull($descriptionFactory);
+15
View File
@@ -26,5 +26,20 @@
<file name="src/DocBlock/StandardTagFactory.php"/> <file name="src/DocBlock/StandardTagFactory.php"/>
</errorLevel> </errorLevel>
</PossiblyNullArrayOffset> </PossiblyNullArrayOffset>
<DeprecatedInterface>
<errorLevel type="info">
<!-- Will be removed in 6.0.0 issues/211 -->
<referencedClass name="phpDocumentor\Reflection\DocBlock\Tags\Factory\StaticMethod"/>
</errorLevel>
</DeprecatedInterface>
<RedundantConditionGivenDocblockType>
<errorLevel type="info">
<!-- Psalm manage to infer a more precise type than PHPStan. notNull assert is needed for PHPStan but
Psalm sees it as redundant -->
<directory name="src/DocBlock/Tags/"/>
</errorLevel>
</RedundantConditionGivenDocblockType>
</issueHandlers> </issueHandlers>
</psalm> </psalm>
+1 -1
View File
@@ -160,7 +160,7 @@ class DescriptionFactory
$startingSpaceCount = 9999999; $startingSpaceCount = 9999999;
for ($i = 1, $iMax = count($lines); $i < $iMax; ++$i) { for ($i = 1, $iMax = count($lines); $i < $iMax; ++$i) {
// lines with a no length do not count as they are not indented at all // 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; continue;
} }
+4 -4
View File
@@ -71,7 +71,7 @@ final class StandardTagFactory implements TagFactory
public const REGEX_TAGNAME = '[\w\-\_\\\\:]+'; public const REGEX_TAGNAME = '[\w\-\_\\\\:]+';
/** /**
* @var array<class-string<StaticMethod>> An array with a tag as a key, and an * @var array<class-string<Tag>> An array with a tag as a key, and an
* FQCN to a class that handles it as an array value. * FQCN to a class that handles it as an array value.
*/ */
private $tagHandlerMappings = [ private $tagHandlerMappings = [
@@ -97,7 +97,7 @@ final class StandardTagFactory implements TagFactory
]; ];
/** /**
* @var array<class-string<StaticMethod>> An array with a anotation s a key, and an * @var array<class-string<Tag>> An array with a anotation s a key, and an
* FQCN to a class that handles it as an array value. * FQCN to a class that handles it as an array value.
*/ */
private $annotationMappings = []; 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. * @see self::registerTagHandler() to add a new tag handler to the existing default list.
* *
* @param array<class-string<StaticMethod>> $tagHandlers * @param array<class-string<Tag>> $tagHandlers
*/ */
public function __construct(FqsenResolver $fqsenResolver, ?array $tagHandlers = null) 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`). * Determines the Fully Qualified Class Name of the Factory or Tag (containing a Factory Method `create`).
* *
* @return class-string<StaticMethod> * @return class-string<Tag>
*/ */
private function findHandlerClassName(string $tagName, TypeContext $context) : string private function findHandlerClassName(string $tagName, TypeContext $context) : string
{ {
+1 -2
View File
@@ -14,7 +14,6 @@ declare(strict_types=1);
namespace phpDocumentor\Reflection\DocBlock; namespace phpDocumentor\Reflection\DocBlock;
use InvalidArgumentException; use InvalidArgumentException;
use phpDocumentor\Reflection\DocBlock\Tags\Factory\StaticMethod;
use phpDocumentor\Reflection\Types\Context as TypeContext; use phpDocumentor\Reflection\Types\Context as TypeContext;
interface TagFactory interface TagFactory
@@ -72,7 +71,7 @@ interface TagFactory
* *
* @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. * tag, the full name, along with a prefixing slash MUST be provided.
* @param class-string<StaticMethod> $handler FQCN of handler. * @param class-string<Tag> $handler FQCN of handler.
* *
* @throws InvalidArgumentException If the tag name is not a string. * @throws InvalidArgumentException If the tag name is not a string.
* @throws InvalidArgumentException If the tag name is namespaced (contains backslashes) but * @throws InvalidArgumentException If the tag name is namespaced (contains backslashes) but
+1 -2
View File
@@ -16,7 +16,6 @@ namespace phpDocumentor\Reflection\DocBlock\Tags;
use InvalidArgumentException; use InvalidArgumentException;
use function filter_var; use function filter_var;
use function preg_match; use function preg_match;
use function strlen;
use function trim; use function trim;
use const FILTER_VALIDATE_EMAIL; use const FILTER_VALIDATE_EMAIL;
@@ -72,7 +71,7 @@ final class Author extends BaseTag implements Factory\StaticMethod
*/ */
public function __toString() : string public function __toString() : string
{ {
return $this->authorName . (strlen($this->authorEmail) ? ' <' . $this->authorEmail . '>' : ''); return $this->authorName . ($this->authorEmail !== '' ? ' <' . $this->authorEmail . '>' : '');
} }
/** /**
@@ -13,6 +13,9 @@ declare(strict_types=1);
namespace phpDocumentor\Reflection\DocBlock\Tags\Factory; namespace phpDocumentor\Reflection\DocBlock\Tags\Factory;
/**
* @deprecated This contract is totally covered by Tag contract. Every class using StaticMethod also use Tag
*/
interface StaticMethod interface StaticMethod
{ {
/** /**
+1 -1
View File
@@ -154,7 +154,7 @@ final class Method extends BaseTag implements Factory\StaticMethod
$argumentsExploded = explode(',', $argumentLines); $argumentsExploded = explode(',', $argumentLines);
foreach ($argumentsExploded as $argument) { foreach ($argumentsExploded as $argument) {
$argument = explode(' ', self::stripRestArg(trim($argument)), 2); $argument = explode(' ', self::stripRestArg(trim($argument)), 2);
if ($argument[0][0] === '$') { if (strpos($argument[0], '$') === 0) {
$argumentName = substr($argument[0], 1); $argumentName = substr($argument[0], 1);
$argumentType = new Mixed_(); $argumentType = new Mixed_();
} else { } else {
+2 -6
View File
@@ -23,7 +23,6 @@ use function array_shift;
use function array_unshift; use function array_unshift;
use function implode; use function implode;
use function preg_split; use function preg_split;
use function strlen;
use function strpos; use function strpos;
use function substr; use function substr;
use const PREG_SPLIT_DELIM_CAPTURE; use const PREG_SPLIT_DELIM_CAPTURE;
@@ -71,7 +70,7 @@ final class Param extends TagWithType implements Factory\StaticMethod
$isVariadic = false; $isVariadic = false;
// if the first item that is encountered is not a variable; it is a type // 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); $type = $typeResolver->resolve($firstPart, $context);
} else { } else {
// first part is not a type; we should prepend it to the parts array for further processing // 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 the next item starts with a $ or ...$ it must be the variable name
if (isset($parts[0]) if (isset($parts[0]) && (strpos($parts[0], '$') === 0 || strpos($parts[0], '...$') === 0)) {
&& (strlen($parts[0]) > 0)
&& (strpos($parts[0], '$') === 0 || strpos($parts[0], '...$') === 0)
) {
$variableName = array_shift($parts); $variableName = array_shift($parts);
array_shift($parts); array_shift($parts);
+1 -2
View File
@@ -23,7 +23,6 @@ use function array_shift;
use function array_unshift; use function array_unshift;
use function implode; use function implode;
use function preg_split; use function preg_split;
use function strlen;
use function strpos; use function strpos;
use function substr; use function substr;
use const PREG_SPLIT_DELIM_CAPTURE; use const PREG_SPLIT_DELIM_CAPTURE;
@@ -63,7 +62,7 @@ final class Property extends TagWithType implements Factory\StaticMethod
$variableName = ''; $variableName = '';
// if the first item that is encountered is not a variable; it is a type // 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); $type = $typeResolver->resolve($firstPart, $context);
} else { } else {
// first part is not a type; we should prepend it to the parts array for further processing // first part is not a type; we should prepend it to the parts array for further processing
+1 -2
View File
@@ -23,7 +23,6 @@ use function array_shift;
use function array_unshift; use function array_unshift;
use function implode; use function implode;
use function preg_split; use function preg_split;
use function strlen;
use function strpos; use function strpos;
use function substr; use function substr;
use const PREG_SPLIT_DELIM_CAPTURE; use const PREG_SPLIT_DELIM_CAPTURE;
@@ -63,7 +62,7 @@ final class PropertyRead extends TagWithType implements Factory\StaticMethod
$variableName = ''; $variableName = '';
// if the first item that is encountered is not a variable; it is a type // 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); $type = $typeResolver->resolve($firstPart, $context);
} else { } else {
// first part is not a type; we should prepend it to the parts array for further processing // first part is not a type; we should prepend it to the parts array for further processing
+1 -2
View File
@@ -23,7 +23,6 @@ use function array_shift;
use function array_unshift; use function array_unshift;
use function implode; use function implode;
use function preg_split; use function preg_split;
use function strlen;
use function strpos; use function strpos;
use function substr; use function substr;
use const PREG_SPLIT_DELIM_CAPTURE; use const PREG_SPLIT_DELIM_CAPTURE;
@@ -63,7 +62,7 @@ final class PropertyWrite extends TagWithType implements Factory\StaticMethod
$variableName = ''; $variableName = '';
// if the first item that is encountered is not a variable; it is a type // 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); $type = $typeResolver->resolve($firstPart, $context);
} else { } else {
// first part is not a type; we should prepend it to the parts array for further processing // first part is not a type; we should prepend it to the parts array for further processing
+1 -1
View File
@@ -42,7 +42,7 @@ abstract class TagWithType extends BaseTag
for ($i = 0, $iMax = strlen($body); $i < $iMax; $i++) { for ($i = 0, $iMax = strlen($body); $i < $iMax; $i++) {
$character = $body[$i]; $character = $body[$i];
if (trim($character) === '' && $nestingLevel === 0) { if ($nestingLevel === 0 && trim($character) === '') {
break; break;
} }
+1 -2
View File
@@ -23,7 +23,6 @@ use function array_shift;
use function array_unshift; use function array_unshift;
use function implode; use function implode;
use function preg_split; use function preg_split;
use function strlen;
use function strpos; use function strpos;
use function substr; use function substr;
use const PREG_SPLIT_DELIM_CAPTURE; use const PREG_SPLIT_DELIM_CAPTURE;
@@ -64,7 +63,7 @@ final class Var_ extends TagWithType implements Factory\StaticMethod
$variableName = ''; $variableName = '';
// if the first item that is encountered is not a variable; it is a type // 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); $type = $typeResolver->resolve($firstPart, $context);
} else { } else {
// first part is not a type; we should prepend it to the parts array for further processing // first part is not a type; we should prepend it to the parts array for further processing
+5 -5
View File
@@ -17,8 +17,8 @@ use InvalidArgumentException;
use LogicException; use LogicException;
use phpDocumentor\Reflection\DocBlock\DescriptionFactory; use phpDocumentor\Reflection\DocBlock\DescriptionFactory;
use phpDocumentor\Reflection\DocBlock\StandardTagFactory; use phpDocumentor\Reflection\DocBlock\StandardTagFactory;
use phpDocumentor\Reflection\DocBlock\Tag;
use phpDocumentor\Reflection\DocBlock\TagFactory; use phpDocumentor\Reflection\DocBlock\TagFactory;
use phpDocumentor\Reflection\DocBlock\Tags\Factory\StaticMethod;
use Webmozart\Assert\Assert; use Webmozart\Assert\Assert;
use function array_shift; use function array_shift;
use function count; use function count;
@@ -52,7 +52,7 @@ final class DocBlockFactory implements DocBlockFactoryInterface
/** /**
* Factory method for easy instantiation. * Factory method for easy instantiation.
* *
* @param array<string, class-string<StaticMethod>> $additionalTags * @param array<string, class-string<Tag>> $additionalTags
*/ */
public static function createInstance(array $additionalTags = []) : self public static function createInstance(array $additionalTags = []) : self
{ {
@@ -110,7 +110,7 @@ final class DocBlockFactory implements DocBlockFactoryInterface
} }
/** /**
* @param class-string<StaticMethod> $handler * @param class-string<Tag> $handler
*/ */
public function registerTagHandler(string $tagName, string $handler) : void public function registerTagHandler(string $tagName, string $handler) : void
{ {
@@ -124,7 +124,7 @@ final class DocBlockFactory implements DocBlockFactoryInterface
*/ */
private function stripDocComment(string $comment) : string 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); Assert::string($comment);
$comment = trim($comment); $comment = trim($comment);
@@ -254,7 +254,7 @@ final class DocBlockFactory implements DocBlockFactoryInterface
{ {
$result = []; $result = [];
foreach (explode("\n", $tags) as $tagLine) { foreach (explode("\n", $tags) as $tagLine) {
if (isset($tagLine[0]) && ($tagLine[0] === '@')) { if ($tagLine !== '' && strpos($tagLine, '@') === 0) {
$result[] = $tagLine; $result[] = $tagLine;
} else { } else {
$result[count($result) - 1] .= "\n" . $tagLine; $result[count($result) - 1] .= "\n" . $tagLine;
+2 -2
View File
@@ -4,7 +4,7 @@ declare(strict_types=1);
namespace phpDocumentor\Reflection; namespace phpDocumentor\Reflection;
use phpDocumentor\Reflection\DocBlock\Tags\Factory\StaticMethod; use phpDocumentor\Reflection\DocBlock\Tag;
// phpcs:ignore SlevomatCodingStandard.Classes.SuperfluousInterfaceNaming.SuperfluousSuffix // phpcs:ignore SlevomatCodingStandard.Classes.SuperfluousInterfaceNaming.SuperfluousSuffix
interface DocBlockFactoryInterface interface DocBlockFactoryInterface
@@ -12,7 +12,7 @@ interface DocBlockFactoryInterface
/** /**
* Factory method for easy instantiation. * Factory method for easy instantiation.
* *
* @param array<string, class-string<StaticMethod>> $additionalTags * @param array<string, class-string<Tag>> $additionalTags
*/ */
public static function createInstance(array $additionalTags = []) : DocBlockFactory; public static function createInstance(array $additionalTags = []) : DocBlockFactory;