Skip to content

Commit d5aea24

Browse files
committed
Fix code style and tests
1 parent ff8ad7c commit d5aea24

File tree

21 files changed

+179
-162
lines changed

21 files changed

+179
-162
lines changed

phpstan.neon

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ parameters:
66
ignoreErrors:
77

88
- '#Method phpDocumentor\\Reflection\\File\\LocalFile::md5\(\) should return string but returns string\|false\.#'
9-
- '#Else branch is unreachable because ternary operator condition is always true\.#'
109
#
1110
# all these $fqsen errors indicate the need for a decorator class around PhpParser\Node to hold the public $fqsen that Reflection is giving it)
1211
#

psalm-baseline.xml

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@
2929
</MixedArgumentTypeCoercion>
3030
</file>
3131
<file src="src/phpDocumentor/Reflection/NodeVisitor/ElementNameResolver.php">
32+
<DeprecatedClass>
33+
<code><![CDATA[PropertyProperty::class]]></code>
34+
<code><![CDATA[PropertyProperty::class]]></code>
35+
</DeprecatedClass>
3236
<ImplicitToStringCast>
3337
<code><![CDATA[$node->name]]></code>
3438
<code><![CDATA[$node->name]]></code>
@@ -53,9 +57,6 @@
5357
<PossiblyUndefinedMethod>
5458
<code><![CDATA[addConstant]]></code>
5559
</PossiblyUndefinedMethod>
56-
<RedundantCondition>
57-
<code><![CDATA[$const->getValue() !== null]]></code>
58-
</RedundantCondition>
5960
</file>
6061
<file src="src/phpDocumentor/Reflection/Php/Factory/ClassConstantIterator.php">
6162
<MixedReturnStatement>
@@ -115,11 +116,6 @@
115116
<code><![CDATA[$object->getAttribute('fqsen')]]></code>
116117
</MixedArgument>
117118
</file>
118-
<file src="src/phpDocumentor/Reflection/Php/Factory/GlobalConstant.php">
119-
<RedundantCondition>
120-
<code><![CDATA[$const->getValue() !== null]]></code>
121-
</RedundantCondition>
122-
</file>
123119
<file src="src/phpDocumentor/Reflection/Php/Factory/GlobalConstantIterator.php">
124120
<MixedReturnStatement>
125121
<code><![CDATA[$this->constant->consts[$this->index]->getAttribute('fqsen')]]></code>

src/phpDocumentor/Reflection/NodeVisitor/ElementNameResolver.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use phpDocumentor\Reflection\Fqsen;
1818
use PhpParser\Node;
1919
use PhpParser\Node\Const_;
20+
use PhpParser\Node\PropertyItem;
2021
use PhpParser\Node\Stmt\Class_;
2122
use PhpParser\Node\Stmt\ClassConst;
2223
use PhpParser\Node\Stmt\ClassMethod;
@@ -72,6 +73,7 @@ public function leaveNode(Node $node)
7273
case ClassMethod::class:
7374
case Trait_::class:
7475
case PropertyProperty::class:
76+
case PropertyItem::class:
7577
case Node\PropertyItem::class:
7678
case ClassConst::class:
7779
case Const_::class:

src/phpDocumentor/Reflection/Php/Argument.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public function __construct(
3838
/** @var string name of the Argument */
3939
private readonly string $name,
4040
Type|null $type = null,
41-
/** @var string|null the default value for an argument or null if none is provided */
41+
/** @var Expression|string|null the default value for an argument or null if none is provided */
4242
private Expression|string|null $default = null,
4343
/** @var bool whether the argument passes the parameter by reference instead of by value */
4444
private readonly bool $byReference = false,
@@ -53,7 +53,7 @@ public function __construct(
5353
trigger_error(
5454
'Default values for arguments should be of type Expression, support for strings will be '
5555
. 'removed in 7.x',
56-
E_USER_DEPRECATED
56+
E_USER_DEPRECATED,
5757
);
5858
$this->default = new Expression($this->default, []);
5959
}
@@ -74,8 +74,7 @@ public function getType(): Type|null
7474
return $this->type;
7575
}
7676

77-
/** */
78-
public function getDefault(bool $asString = true): string|null
77+
public function getDefault(bool $asString = true): Expression|string|null
7978
{
8079
if ($this->default === null) {
8180
return null;
@@ -84,7 +83,7 @@ public function getDefault(bool $asString = true): string|null
8483
if ($asString) {
8584
trigger_error(
8685
'The Default value will become of type Expression by default',
87-
E_USER_DEPRECATED
86+
E_USER_DEPRECATED,
8887
);
8988

9089
return (string) $this->default;

src/phpDocumentor/Reflection/Php/Constant.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,6 @@ final class Constant implements Element, MetaDataContainerInterface, AttributeCo
4343

4444
/**
4545
* Initializes the object.
46-
*
47-
* @param Expression|string|null $value
4846
*/
4947
public function __construct(
5048
private readonly Fqsen $fqsen,
@@ -59,14 +57,16 @@ public function __construct(
5957
$this->endLocation = $endLocation ?: new Location(-1);
6058
$this->visibility = $visibility ?: new Visibility(Visibility::PUBLIC_);
6159

62-
if (is_string($this->value)) {
63-
trigger_error(
64-
'Constant values should be of type Expression, support for strings will be '
65-
. 'removed in 6.x',
66-
E_USER_DEPRECATED
67-
);
68-
$this->value = new Expression($this->value, []);
60+
if (!is_string($this->value)) {
61+
return;
6962
}
63+
64+
trigger_error(
65+
'Constant values should be of type Expression, support for strings will be '
66+
. 'removed in 6.x',
67+
E_USER_DEPRECATED,
68+
);
69+
$this->value = new Expression($this->value, []);
7070
}
7171

7272
/**
@@ -81,7 +81,7 @@ public function getValue(bool $asString = true): Expression|string|null
8181
if ($asString) {
8282
trigger_error(
8383
'The expression value will become of type Expression by default',
84-
E_USER_DEPRECATED
84+
E_USER_DEPRECATED,
8585
);
8686

8787
return (string) $this->value;

src/phpDocumentor/Reflection/Php/EnumCase.php

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,16 @@ public function __construct(
4747

4848
$this->location = $location;
4949
$this->endLocation = $endLocation;
50-
if (is_string($this->value)) {
51-
trigger_error(
52-
'Expression values for enum cases should be of type Expression, support for strings will be '
53-
. 'removed in 7.x',
54-
E_USER_DEPRECATED
55-
);
56-
$this->value = new Expression($this->value, []);
50+
if (!is_string($this->value)) {
51+
return;
5752
}
53+
54+
trigger_error(
55+
'Expression values for enum cases should be of type Expression, support for strings will be '
56+
. 'removed in 7.x',
57+
E_USER_DEPRECATED,
58+
);
59+
$this->value = new Expression($this->value, []);
5860
}
5961

6062
#[Override]
@@ -96,7 +98,7 @@ public function getValue(bool $asString = true): Expression|string|null
9698
if ($asString) {
9799
trigger_error(
98100
'The enum case value will become of type Expression by default',
99-
E_USER_DEPRECATED
101+
E_USER_DEPRECATED,
100102
);
101103

102104
return (string) $this->value;

src/phpDocumentor/Reflection/Php/Expression.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@
4949
* for the definition of expressions in PHP.
5050
* @link https://www.rfc-editor.org/rfc/rfc6570 for more information on URI Templates.
5151
* @see ExpressionPrinter how an expression coming from PHP-Parser is transformed into an expression.
52+
*
53+
* @api
5254
*/
5355
final class Expression
5456
{
@@ -82,9 +84,7 @@ public static function generatePlaceholder(string $name): string
8284
return '{{ PHPDOC' . md5($name) . ' }}';
8385
}
8486

85-
/**
86-
* @param array<string, Fqsen|Type> $parts
87-
*/
87+
/** @param array<string, Fqsen|Type> $parts */
8888
public function __construct(string $expression, array $parts = [])
8989
{
9090
Assert::notEmpty($expression);

src/phpDocumentor/Reflection/Php/Expression/ExpressionPrinter.php

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use phpDocumentor\Reflection\Fqsen;
1717
use phpDocumentor\Reflection\Php\Expression;
1818
use phpDocumentor\Reflection\Type;
19+
use PhpParser\Node\Expr;
1920
use PhpParser\Node\Name;
2021
use PhpParser\PrettyPrinter\Standard;
2122

@@ -50,9 +51,20 @@ protected function pName_FullyQualified(Name\FullyQualified $node): string
5051
return $placeholder;
5152
}
5253

53-
/**
54-
* @return array<string, Fqsen|Type>
55-
*/
54+
// phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps
55+
protected function pExpr_ClassConstFetch(Expr\ClassConstFetch $node): string
56+
{
57+
$renderedName = parent::pObjectProperty($node->name);
58+
$className = $node->class instanceof Name ? parent::pName($node->class) : $this->p($node->class);
59+
$placeholder = Expression::generatePlaceholder($renderedName);
60+
$this->parts[$placeholder] = new Fqsen(
61+
'\\' . $className . '::' . $renderedName,
62+
);
63+
64+
return $placeholder;
65+
}
66+
67+
/** @return array<string, Fqsen|Type> */
5668
public function getParts(): array
5769
{
5870
return $this->parts;

src/phpDocumentor/Reflection/Php/Factory/Argument.php

Whitespace-only changes.

src/phpDocumentor/Reflection/Php/Factory/ClassConstant.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919
use phpDocumentor\Reflection\Php\Class_;
2020
use phpDocumentor\Reflection\Php\Constant as ConstantElement;
2121
use phpDocumentor\Reflection\Php\Enum_;
22-
use phpDocumentor\Reflection\Php\Factory\Reducer\Reducer;
2322
use phpDocumentor\Reflection\Php\Expression;
2423
use phpDocumentor\Reflection\Php\Expression\ExpressionPrinter;
24+
use phpDocumentor\Reflection\Php\Factory\Reducer\Reducer;
2525
use phpDocumentor\Reflection\Php\Interface_;
2626
use phpDocumentor\Reflection\Php\StrategyContainer;
2727
use phpDocumentor\Reflection\Php\Trait_;
@@ -109,7 +109,7 @@ protected function doCreate(
109109
return null;
110110
}
111111

112-
private function determineValue(ClassConstantIterator $value): Expression|null
112+
private function determineValue(ClassConstantIterator $value): Expression
113113
{
114114
$expression = $this->valueConverter->prettyPrintExpr($value->getValue());
115115
if ($this->valueConverter instanceof ExpressionPrinter) {

0 commit comments

Comments
 (0)