Skip to content

Commit 435f6a3

Browse files
mvrieljaapio
authored andcommitted
Update docs and removed useless files too
1 parent fc9863f commit 435f6a3

File tree

13 files changed

+65
-5
lines changed

13 files changed

+65
-5
lines changed

docs/expressions.rst

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
Expressions
2+
===========
3+
4+
Starting with version 5.4, we now support parsing expressions and extracting types and references to elements from them.
5+
6+
.. info::
7+
8+
An expression is, for example, the default value for a property or argument, the definition of an enum case or a
9+
constant value. These are called expressions and can contain more complex combinations of operators and values.
10+
11+
As this library revolves around reflecting Static information, most parts of an expression are considered irrelevant;
12+
except for type information -such as type hints- and references to other elements, such as constants. As such, whenever
13+
an expression is interpreted, it will result in a string containing placeholders and an array containing the reflected
14+
parts -such as FQSENs-.
15+
16+
This means that the getters like ``getDefault()`` will return a string or when you provide the optional argument
17+
$isString as being false, it will return an Expression object; which, when cast to string, will provide the same result.
18+
19+
.. warning::
20+
21+
Deprecation: In version 6, we will remove the optional argument and always return an Expression object. When the
22+
result was used as a string nothing will change, but code that checks if the output is a string will no longer
23+
function starting from that version.
24+
25+
This will allow consumers to be able to extract types and links to elements from expressions. This allows consumers to,
26+
for example, interpret the default value for a constructor promoted properties when it directly instantiates an object.

docs/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,5 @@ are however several advantages to using this library:
2525

2626
getting-started
2727
reflection-structure
28+
expressions
2829
extending/index

src/phpDocumentor/Reflection/Php/Argument.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@
1616
use phpDocumentor\Reflection\Type;
1717
use phpDocumentor\Reflection\Types\Mixed_;
1818

19+
use function is_string;
20+
use function trigger_error;
21+
22+
use const E_USER_DEPRECATED;
23+
1924
/**
2025
* Descriptor representing a single Argument of a method or function.
2126
*

src/phpDocumentor/Reflection/Php/Constant.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@
2020
use phpDocumentor\Reflection\Location;
2121
use phpDocumentor\Reflection\Metadata\MetaDataContainer as MetaDataContainerInterface;
2222

23+
use function is_string;
24+
use function trigger_error;
25+
26+
use const E_USER_DEPRECATED;
27+
2328
/**
2429
* Descriptor representing a constant
2530
*

src/phpDocumentor/Reflection/Php/EnumCase.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@
1111
use phpDocumentor\Reflection\Location;
1212
use phpDocumentor\Reflection\Metadata\MetaDataContainer as MetaDataContainerInterface;
1313

14+
use function is_string;
15+
use function trigger_error;
16+
17+
use const E_USER_DEPRECATED;
18+
1419
/**
1520
* Represents a case in an Enum.
1621
*

src/phpDocumentor/Reflection/Php/Expression.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
use phpDocumentor\Reflection\Fqsen;
88
use phpDocumentor\Reflection\Type;
99

10+
use function array_keys;
11+
use function array_map;
12+
use function str_replace;
13+
1014
final class Expression
1115
{
1216
private string $expression;
@@ -33,7 +37,7 @@ public function getParts(): array
3337
public function __toString(): string
3438
{
3539
$valuesAsStrings = array_map(
36-
static fn(object $part): string => (string)$part,
40+
static fn (object $part): string => (string) $part,
3741
$this->parts
3842
);
3943

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
use PhpParser\Node\Name;
99
use PhpParser\PrettyPrinter\Standard;
1010

11+
use function md5;
12+
1113
final class ExpressionPrinter extends Standard
1214
{
13-
/**
14-
* @var array<Fqsen>
15-
*/
15+
/** @var array<Fqsen> */
1616
private array $parts = [];
1717

1818
protected function resetState(): void

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
use PhpParser\PrettyPrinter\Standard as PrettyPrinter;
3131
use Webmozart\Assert\Assert;
3232

33+
use function is_string;
34+
3335
/**
3436
* Strategy to convert ClassConstantIterator to ConstantElement
3537
*
@@ -113,6 +115,7 @@ private function determineValue(ClassConstantIterator $value): null|Expression
113115
if ($this->valueConverter instanceof ExpressionPrinter) {
114116
$expression = new Expression($expression, $this->valueConverter->getParts());
115117
}
118+
116119
if (is_string($expression)) {
117120
$expression = new Expression($expression, []);
118121
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
use PhpParser\PrettyPrinter\Standard as PrettyPrinter;
3434

3535
use function assert;
36+
use function is_string;
3637
use function sprintf;
3738
use function str_starts_with;
3839

@@ -130,6 +131,7 @@ private function determineValue(Arg|null $value): ValueExpression|null
130131
if ($this->valueConverter instanceof ExpressionPrinter) {
131132
$expression = new ValueExpression($expression, $this->valueConverter->getParts());
132133
}
134+
133135
if (is_string($expression)) {
134136
$expression = new ValueExpression($expression, []);
135137
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
use PhpParser\PrettyPrinter\Standard as PrettyPrinter;
2626
use Webmozart\Assert\Assert;
2727

28+
use function is_string;
29+
2830
/**
2931
* Strategy to convert GlobalConstantIterator to ConstantElement
3032
*
@@ -88,6 +90,7 @@ private function determineValue(GlobalConstantIterator $value): ?Expression
8890
if ($this->valueConverter instanceof ExpressionPrinter) {
8991
$expression = new Expression($expression, $this->valueConverter->getParts());
9092
}
93+
9194
if (is_string($expression)) {
9295
$expression = new Expression($expression, []);
9396
}

0 commit comments

Comments
 (0)