Skip to content

Commit 83e5abe

Browse files
committed
Use code fences for code samples in PHPDocs
phpdoc-parser trims the first line of a paragraph, so indented code samples lost the indentation that made them code blocks. Amp-Thread-ID: https://ampcode.com/threads/T-01a176c6-528a-7430-b296-e66930d153b4
1 parent 766bb6b commit 83e5abe

7 files changed

Lines changed: 39 additions & 24 deletions

File tree

‎src/DependencyInjection/ContainerExtensionsExtension.php‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@
1818
*
1919
* Extending ExtensionsExtension is required, not cosmetic. Compiler::processExtensions() starts with
2020
*
21-
* $first = $this->getExtensions(ParametersExtension::class) + $this->getExtensions(ExtensionsExtension::class);
21+
* ```php
22+
* $first = $this->getExtensions(ParametersExtension::class) + $this->getExtensions(ExtensionsExtension::class);
23+
* ```
2224
*
2325
* and only extensions matching those types by instanceof have their loadConfiguration() called before
2426
* the compiler snapshots its extension list. Everything registered after that snapshot is rejected with

‎src/TrinaryLogic.php‎

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,17 @@
2020
* depend on runtime values that can't be known statically. Extension developers
2121
* encounter TrinaryLogic extensively when querying type properties:
2222
*
23-
* if ($type->isString()->yes()) {
24-
* // Definitely a string
25-
* }
26-
* if ($type->isString()->maybe()) {
27-
* // Could be a string (e.g. mixed)
28-
* }
29-
* if ($type->isString()->no()) {
30-
* // Definitely not a string
31-
* }
23+
* ```php
24+
* if ($type->isString()->yes()) {
25+
* // Definitely a string
26+
* }
27+
* if ($type->isString()->maybe()) {
28+
* // Could be a string (e.g. mixed)
29+
* }
30+
* if ($type->isString()->no()) {
31+
* // Definitely not a string
32+
* }
33+
* ```
3234
*
3335
* TrinaryLogic supports logical operations (and, or, negate) that propagate
3436
* uncertainty correctly. It is used as a flyweight — instances are cached and

‎src/Type/Accessory/AccessoryType.php‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,15 @@
1515
*
1616
* For example, `non-empty-string` is represented as:
1717
*
18-
* IntersectionType([StringType, AccessoryNonEmptyStringType])
18+
* ```
19+
* IntersectionType([StringType, AccessoryNonEmptyStringType])
20+
* ```
1921
*
2022
* And `non-empty-list<int>` is represented as:
2123
*
22-
* IntersectionType([ArrayType(int, int), NonEmptyArrayType, AccessoryArrayListType])
24+
* ```
25+
* IntersectionType([ArrayType(int, int), NonEmptyArrayType, AccessoryArrayListType])
26+
* ```
2327
*
2428
* Each AccessoryType implementation has a corresponding query method on the `Type` interface
2529
* that returns `TrinaryLogic`. This lets any code query the refinement without knowing

‎src/Type/GeneralizePrecision.php‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@
2222
*
2323
* Used as a parameter to Type::generalize():
2424
*
25-
* $type->generalize(GeneralizePrecision::lessSpecific())
25+
* ```php
26+
* $type->generalize(GeneralizePrecision::lessSpecific())
27+
* ```
2628
*/
2729
#[ReferencedByTurboExtension(key: 'generalizePrecision')]
2830
final class GeneralizePrecision

‎src/Type/Type.php‎

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,13 @@
3636
* will miss union types, intersection types with accessory types, and other composite forms.
3737
* Always use the `is*()` methods or `isSuperTypeOf()` instead:
3838
*
39-
* // Wrong:
40-
* if ($type instanceof StringType) { ... }
39+
* ```php
40+
* // Wrong:
41+
* if ($type instanceof StringType) { ... }
4142
*
42-
* // Correct:
43-
* if ($type->isString()->yes()) { ... }
43+
* // Correct:
44+
* if ($type->isString()->yes()) { ... }
45+
* ```
4446
*
4547
* @api
4648
* @api-do-not-implement
@@ -563,14 +565,13 @@ public function getGreaterOrEqualType(PhpVersion $phpVersion): Type;
563565
/**
564566
* Returns actual template type for a given object.
565567
*
566-
* Example:
567-
*
568-
* @-template T
569-
* class Foo {}
568+
* For example, with a class `Foo` that declares `@template T`:
570569
*
570+
* ```php
571571
* // $fooType is Foo<int>
572572
* $t = $fooType->getTemplateType(Foo::class, 'T');
573573
* $t->isInteger(); // yes
574+
* ```
574575
*
575576
* Returns ErrorType in case of a missing type.
576577
*

‎src/Type/TypeTraverser.php‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ final class TypeTraverser
3030
* The following example converts constant strings to objects, while
3131
* preserving unions and intersections:
3232
*
33+
* ```php
3334
* TypeTraverser::map($type, function (Type $type, callable $traverse): Type {
3435
* if ($type instanceof UnionType || $type instanceof IntersectionType) {
3536
* // Traverse inner types
@@ -42,6 +43,7 @@ final class TypeTraverser
4243
* // Replaces the current type, and don't traverse
4344
* return new MixedType();
4445
* });
46+
* ```
4547
*
4648
* @api
4749
* @param TypeTraverserCallable|callable(Type $type, callable(Type): Type $traverse): Type $cb

‎src/Type/VerbosityLevel.php‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,11 @@
3232
*
3333
* Used as a parameter to Type::describe() to control output detail:
3434
*
35-
* $type->describe(VerbosityLevel::typeOnly()) // "string"
36-
* $type->describe(VerbosityLevel::value()) // "'hello'"
37-
* $type->describe(VerbosityLevel::precise()) // "non-empty-lowercase-string"
35+
* ```php
36+
* $type->describe(VerbosityLevel::typeOnly()) // "string"
37+
* $type->describe(VerbosityLevel::value()) // "'hello'"
38+
* $type->describe(VerbosityLevel::precise()) // "non-empty-lowercase-string"
39+
* ```
3840
*
3941
* The getRecommendedLevelByType() factory method automatically chooses the right level
4042
* for error messages based on what types are involved — it picks the minimum verbosity

0 commit comments

Comments
 (0)