Skip to content

Commit cd72d39

Browse files
authored
Merge pull request #212 from orklah/static-fixes
change somes things for SA
2 parents 8bc250e + 9724d35 commit cd72d39

17 files changed

+44
-36
lines changed

.github/workflows/push.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ jobs:
180180
args: analyse src --configuration phpstan.neon
181181

182182
psalm:
183-
name: Psaml
183+
name: Psalm
184184
runs-on: ${{ matrix.operating-system }}
185185
strategy:
186186
matrix:

examples/04-adding-your-own-tag.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public function __construct(Description $description = null)
8484
* @see Tag for the interface declaration of the `create` method.
8585
* @see Tag::create() for more information on this method's workings.
8686
*/
87-
public static function create(string $body, DescriptionFactory $descriptionFactory = null, Context $context = null): MyTag
87+
public static function create(string $body, DescriptionFactory $descriptionFactory = null, Context $context = null): self
8888
{
8989
Assert::notNull($descriptionFactory);
9090

psalm.xml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,20 @@
2626
<file name="src/DocBlock/StandardTagFactory.php"/>
2727
</errorLevel>
2828
</PossiblyNullArrayOffset>
29+
30+
<DeprecatedInterface>
31+
<errorLevel type="info">
32+
<!-- Will be removed in 6.0.0 issues/211 -->
33+
<referencedClass name="phpDocumentor\Reflection\DocBlock\Tags\Factory\StaticMethod"/>
34+
</errorLevel>
35+
</DeprecatedInterface>
36+
37+
<RedundantConditionGivenDocblockType>
38+
<errorLevel type="info">
39+
<!-- Psalm manage to infer a more precise type than PHPStan. notNull assert is needed for PHPStan but
40+
Psalm sees it as redundant -->
41+
<directory name="src/DocBlock/Tags/"/>
42+
</errorLevel>
43+
</RedundantConditionGivenDocblockType>
2944
</issueHandlers>
3045
</psalm>

src/DocBlock/DescriptionFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ private function removeSuperfluousStartingWhitespace(string $contents) : string
160160
$startingSpaceCount = 9999999;
161161
for ($i = 1, $iMax = count($lines); $i < $iMax; ++$i) {
162162
// lines with a no length do not count as they are not indented at all
163-
if (strlen(trim($lines[$i])) === 0) {
163+
if (trim($lines[$i]) === '') {
164164
continue;
165165
}
166166

src/DocBlock/StandardTagFactory.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ final class StandardTagFactory implements TagFactory
7171
public const REGEX_TAGNAME = '[\w\-\_\\\\:]+';
7272

7373
/**
74-
* @var array<class-string<StaticMethod>> An array with a tag as a key, and an
75-
* FQCN to a class that handles it as an array value.
74+
* @var array<class-string<Tag>> An array with a tag as a key, and an
75+
* FQCN to a class that handles it as an array value.
7676
*/
7777
private $tagHandlerMappings = [
7878
'author' => Author::class,
@@ -97,7 +97,7 @@ final class StandardTagFactory implements TagFactory
9797
];
9898

9999
/**
100-
* @var array<class-string<StaticMethod>> An array with a anotation s a key, and an
100+
* @var array<class-string<Tag>> An array with a anotation s a key, and an
101101
* FQCN to a class that handles it as an array value.
102102
*/
103103
private $annotationMappings = [];
@@ -125,7 +125,7 @@ final class StandardTagFactory implements TagFactory
125125
*
126126
* @see self::registerTagHandler() to add a new tag handler to the existing default list.
127127
*
128-
* @param array<class-string<StaticMethod>> $tagHandlers
128+
* @param array<class-string<Tag>> $tagHandlers
129129
*/
130130
public function __construct(FqsenResolver $fqsenResolver, ?array $tagHandlers = null)
131131
{
@@ -224,7 +224,7 @@ private function createTag(string $body, string $name, TypeContext $context) : T
224224
/**
225225
* Determines the Fully Qualified Class Name of the Factory or Tag (containing a Factory Method `create`).
226226
*
227-
* @return class-string<StaticMethod>
227+
* @return class-string<Tag>
228228
*/
229229
private function findHandlerClassName(string $tagName, TypeContext $context) : string
230230
{

src/DocBlock/TagFactory.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
namespace phpDocumentor\Reflection\DocBlock;
1515

1616
use InvalidArgumentException;
17-
use phpDocumentor\Reflection\DocBlock\Tags\Factory\StaticMethod;
1817
use phpDocumentor\Reflection\Types\Context as TypeContext;
1918

2019
interface TagFactory
@@ -70,9 +69,9 @@ public function addService(object $service) : void;
7069
* to register the name of a tag with the FQCN of a 'Tag Handler'. The Tag handler should implement
7170
* the {@see Tag} interface (and thus the create method).
7271
*
73-
* @param string $tagName Name of tag to register a handler for. When registering a namespaced
72+
* @param string $tagName Name of tag to register a handler for. When registering a namespaced
7473
* tag, the full name, along with a prefixing slash MUST be provided.
75-
* @param class-string<StaticMethod> $handler FQCN of handler.
74+
* @param class-string<Tag> $handler FQCN of handler.
7675
*
7776
* @throws InvalidArgumentException If the tag name is not a string.
7877
* @throws InvalidArgumentException If the tag name is namespaced (contains backslashes) but

src/DocBlock/Tags/Author.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
use InvalidArgumentException;
1717
use function filter_var;
1818
use function preg_match;
19-
use function strlen;
2019
use function trim;
2120
use const FILTER_VALIDATE_EMAIL;
2221

@@ -72,7 +71,7 @@ public function getEmail() : string
7271
*/
7372
public function __toString() : string
7473
{
75-
return $this->authorName . (strlen($this->authorEmail) ? ' <' . $this->authorEmail . '>' : '');
74+
return $this->authorName . ($this->authorEmail !== '' ? ' <' . $this->authorEmail . '>' : '');
7675
}
7776

7877
/**

src/DocBlock/Tags/Factory/StaticMethod.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313

1414
namespace phpDocumentor\Reflection\DocBlock\Tags\Factory;
1515

16+
/**
17+
* @deprecated This contract is totally covered by Tag contract. Every class using StaticMethod also use Tag
18+
*/
1619
interface StaticMethod
1720
{
1821
/**

src/DocBlock/Tags/Method.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ public static function create(
154154
$argumentsExploded = explode(',', $argumentLines);
155155
foreach ($argumentsExploded as $argument) {
156156
$argument = explode(' ', self::stripRestArg(trim($argument)), 2);
157-
if ($argument[0][0] === '$') {
157+
if (strpos($argument[0], '$') === 0) {
158158
$argumentName = substr($argument[0], 1);
159159
$argumentType = new Mixed_();
160160
} else {

src/DocBlock/Tags/Param.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
use function array_unshift;
2424
use function implode;
2525
use function preg_split;
26-
use function strlen;
2726
use function strpos;
2827
use function substr;
2928
use const PREG_SPLIT_DELIM_CAPTURE;
@@ -71,18 +70,15 @@ public static function create(
7170
$isVariadic = false;
7271

7372
// if the first item that is encountered is not a variable; it is a type
74-
if ($firstPart && (strlen($firstPart) > 0) && ($firstPart[0] !== '$')) {
73+
if ($firstPart && $firstPart[0] !== '$') {
7574
$type = $typeResolver->resolve($firstPart, $context);
7675
} else {
7776
// first part is not a type; we should prepend it to the parts array for further processing
7877
array_unshift($parts, $firstPart);
7978
}
8079

8180
// if the next item starts with a $ or ...$ it must be the variable name
82-
if (isset($parts[0])
83-
&& (strlen($parts[0]) > 0)
84-
&& (strpos($parts[0], '$') === 0 || strpos($parts[0], '...$') === 0)
85-
) {
81+
if (isset($parts[0]) && (strpos($parts[0], '$') === 0 || strpos($parts[0], '...$') === 0)) {
8682
$variableName = array_shift($parts);
8783
array_shift($parts);
8884

src/DocBlock/Tags/Property.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
use function array_unshift;
2424
use function implode;
2525
use function preg_split;
26-
use function strlen;
2726
use function strpos;
2827
use function substr;
2928
use const PREG_SPLIT_DELIM_CAPTURE;
@@ -63,7 +62,7 @@ public static function create(
6362
$variableName = '';
6463

6564
// if the first item that is encountered is not a variable; it is a type
66-
if ($firstPart && (strlen($firstPart) > 0) && ($firstPart[0] !== '$')) {
65+
if ($firstPart && $firstPart[0] !== '$') {
6766
$type = $typeResolver->resolve($firstPart, $context);
6867
} else {
6968
// first part is not a type; we should prepend it to the parts array for further processing

src/DocBlock/Tags/PropertyRead.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
use function array_unshift;
2424
use function implode;
2525
use function preg_split;
26-
use function strlen;
2726
use function strpos;
2827
use function substr;
2928
use const PREG_SPLIT_DELIM_CAPTURE;
@@ -63,7 +62,7 @@ public static function create(
6362
$variableName = '';
6463

6564
// if the first item that is encountered is not a variable; it is a type
66-
if ($firstPart && (strlen($firstPart) > 0) && ($firstPart[0] !== '$')) {
65+
if ($firstPart && $firstPart[0] !== '$') {
6766
$type = $typeResolver->resolve($firstPart, $context);
6867
} else {
6968
// first part is not a type; we should prepend it to the parts array for further processing

src/DocBlock/Tags/PropertyWrite.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
use function array_unshift;
2424
use function implode;
2525
use function preg_split;
26-
use function strlen;
2726
use function strpos;
2827
use function substr;
2928
use const PREG_SPLIT_DELIM_CAPTURE;
@@ -63,7 +62,7 @@ public static function create(
6362
$variableName = '';
6463

6564
// if the first item that is encountered is not a variable; it is a type
66-
if ($firstPart && (strlen($firstPart) > 0) && ($firstPart[0] !== '$')) {
65+
if ($firstPart && $firstPart[0] !== '$') {
6766
$type = $typeResolver->resolve($firstPart, $context);
6867
} else {
6968
// first part is not a type; we should prepend it to the parts array for further processing

src/DocBlock/Tags/TagWithType.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ protected static function extractTypeFromBody(string $body) : array
4242
for ($i = 0, $iMax = strlen($body); $i < $iMax; $i++) {
4343
$character = $body[$i];
4444

45-
if (trim($character) === '' && $nestingLevel === 0) {
45+
if ($nestingLevel === 0 && trim($character) === '') {
4646
break;
4747
}
4848

src/DocBlock/Tags/Var_.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
use function array_unshift;
2424
use function implode;
2525
use function preg_split;
26-
use function strlen;
2726
use function strpos;
2827
use function substr;
2928
use const PREG_SPLIT_DELIM_CAPTURE;
@@ -64,7 +63,7 @@ public static function create(
6463
$variableName = '';
6564

6665
// if the first item that is encountered is not a variable; it is a type
67-
if ($firstPart && (strlen($firstPart) > 0) && ($firstPart[0] !== '$')) {
66+
if ($firstPart && $firstPart[0] !== '$') {
6867
$type = $typeResolver->resolve($firstPart, $context);
6968
} else {
7069
// first part is not a type; we should prepend it to the parts array for further processing

src/DocBlockFactory.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
use LogicException;
1818
use phpDocumentor\Reflection\DocBlock\DescriptionFactory;
1919
use phpDocumentor\Reflection\DocBlock\StandardTagFactory;
20+
use phpDocumentor\Reflection\DocBlock\Tag;
2021
use phpDocumentor\Reflection\DocBlock\TagFactory;
21-
use phpDocumentor\Reflection\DocBlock\Tags\Factory\StaticMethod;
2222
use Webmozart\Assert\Assert;
2323
use function array_shift;
2424
use function count;
@@ -52,7 +52,7 @@ public function __construct(DescriptionFactory $descriptionFactory, TagFactory $
5252
/**
5353
* Factory method for easy instantiation.
5454
*
55-
* @param array<string, class-string<StaticMethod>> $additionalTags
55+
* @param array<string, class-string<Tag>> $additionalTags
5656
*/
5757
public static function createInstance(array $additionalTags = []) : self
5858
{
@@ -110,7 +110,7 @@ public function create($docblock, ?Types\Context $context = null, ?Location $loc
110110
}
111111

112112
/**
113-
* @param class-string<StaticMethod> $handler
113+
* @param class-string<Tag> $handler
114114
*/
115115
public function registerTagHandler(string $tagName, string $handler) : void
116116
{
@@ -124,7 +124,7 @@ public function registerTagHandler(string $tagName, string $handler) : void
124124
*/
125125
private function stripDocComment(string $comment) : string
126126
{
127-
$comment = preg_replace('#[ \t]*(?:\/\*\*|\*\/|\*)?[ \t]{0,1}(.*)?#u', '$1', $comment);
127+
$comment = preg_replace('#[ \t]*(?:\/\*\*|\*\/|\*)?[ \t]?(.*)?#u', '$1', $comment);
128128
Assert::string($comment);
129129
$comment = trim($comment);
130130

@@ -254,7 +254,7 @@ private function splitTagBlockIntoTagLines(string $tags) : array
254254
{
255255
$result = [];
256256
foreach (explode("\n", $tags) as $tagLine) {
257-
if (isset($tagLine[0]) && ($tagLine[0] === '@')) {
257+
if ($tagLine !== '' && strpos($tagLine, '@') === 0) {
258258
$result[] = $tagLine;
259259
} else {
260260
$result[count($result) - 1] .= "\n" . $tagLine;

src/DocBlockFactoryInterface.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44

55
namespace phpDocumentor\Reflection;
66

7-
use phpDocumentor\Reflection\DocBlock\Tags\Factory\StaticMethod;
7+
use phpDocumentor\Reflection\DocBlock\Tag;
88

99
// phpcs:ignore SlevomatCodingStandard.Classes.SuperfluousInterfaceNaming.SuperfluousSuffix
1010
interface DocBlockFactoryInterface
1111
{
1212
/**
1313
* Factory method for easy instantiation.
1414
*
15-
* @param array<string, class-string<StaticMethod>> $additionalTags
15+
* @param array<string, class-string<Tag>> $additionalTags
1616
*/
1717
public static function createInstance(array $additionalTags = []) : DocBlockFactory;
1818

0 commit comments

Comments
 (0)