Skip to content

Commit c570bc9

Browse files
committed
add fluent call
1 parent 4b6abf2 commit c570bc9

File tree

5 files changed

+79
-38
lines changed

5 files changed

+79
-38
lines changed

README.md

+54-13
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ CONSTANT_NAME = 'default'
2929

3030
* `$name` - `/** @var Identifier Name */`
3131
* `$value` - `/** @var Expr Value */`
32+
* `$namespacedName` - `/** @var Name|null Namespaced name (if using NameResolver) */`
3233

3334
<br>
3435

@@ -168,7 +169,7 @@ fn() => 1
168169
* `$static` - `/** @var bool */`
169170
* `$byRef` - `/** @var bool */`
170171
* `$params` - `/** @var Node\Param[] */`
171-
* `$returnType` - `/** @var null|Node\Identifier|Node\Name|Node\NullableType|Node\UnionType */`
172+
* `$returnType` - `/** @var null|Node\Identifier|Node\Name|Node\ComplexType */`
172173
* `$expr` - `/** @var Expr */`
173174
* `$attrGroups` - `/** @var Node\AttributeGroup[] */`
174175

@@ -937,7 +938,7 @@ func_call($someVariable)
937938
### Public Properties
938939

939940
* `$name` - `/** @var Node\Name|Expr Function name */`
940-
* `$args` - `/** @var Node\Arg[] Arguments */`
941+
* `$args` - `/** @var array<Node\Arg|Node\VariadicPlaceholder> Arguments */`
941942

942943
<br>
943944

@@ -1165,6 +1166,36 @@ $someObject->methodName()
11651166

11661167
declare(strict_types=1);
11671168

1169+
use PhpParser\Node\Arg;
1170+
use PhpParser\Node\Expr\MethodCall;
1171+
use PhpParser\Node\Expr\Variable;
1172+
use PhpParser\Node\Scalar\String_;
1173+
1174+
$variable = new Variable('someObject');
1175+
1176+
$args = [];
1177+
$args[] = new Arg(new String_('yes'));
1178+
1179+
$methodCall = new MethodCall($variable, 'methodName', $args);
1180+
1181+
$nestedMethodCall = new MethodCall($methodCall, 'nextMethodName');
1182+
1183+
return $nestedMethodCall;
1184+
```
1185+
1186+
1187+
1188+
```php
1189+
$someObject->methodName('yes')->nextMethodName()
1190+
```
1191+
1192+
<br>
1193+
1194+
```php
1195+
<?php
1196+
1197+
declare(strict_types=1);
1198+
11681199
use PhpParser\Node\Expr\MethodCall;
11691200
use PhpParser\Node\Expr\PropertyFetch;
11701201
use PhpParser\Node\Expr\Variable;
@@ -1214,7 +1245,7 @@ $someObject->methodName('yes', 'maybe')
12141245

12151246
* `$var` - `/** @var Expr Variable holding object */`
12161247
* `$name` - `/** @var Identifier|Expr Method name */`
1217-
* `$args` - `/** @var Arg[] Arguments */`
1248+
* `$args` - `/** @var array<Arg|VariadicPlaceholder> Arguments */`
12181249

12191250
<br>
12201251

@@ -1271,7 +1302,7 @@ new SomeClass()
12711302
### Public Properties
12721303

12731304
* `$class` - `/** @var Node\Name|Expr|Node\Stmt\Class_ Class name */`
1274-
* `$args` - `/** @var Node\Arg[] Arguments */`
1305+
* `$args` - `/** @var array<Arg|VariadicPlaceholder> Arguments */`
12751306

12761307
<br>
12771308

@@ -1304,7 +1335,7 @@ $variableName?->methodName()
13041335

13051336
* `$var` - `/** @var Expr Variable holding object */`
13061337
* `$name` - `/** @var Identifier|Expr Method name */`
1307-
* `$args` - `/** @var Arg[] Arguments */`
1338+
* `$args` - `/** @var array<Arg|VariadicPlaceholder> Arguments */`
13081339

13091340
<br>
13101341

@@ -1401,7 +1432,7 @@ return new StaticCall($fullyQualified, 'methodName');
14011432

14021433
* `$class` - `/** @var Node\Name|Expr Class name */`
14031434
* `$name` - `/** @var Identifier|Expr Method name */`
1404-
* `$args` - `/** @var Node\Arg[] Arguments */`
1435+
* `$args` - `/** @var array<Arg|VariadicPlaceholder> Arguments */`
14051436

14061437
<br>
14071438

@@ -1592,7 +1623,10 @@ shortName
15921623

15931624
### Public Properties
15941625

1595-
* `$parts` - `/** @var string[] Parts of the name */`
1626+
* `$parts` - `/**
1627+
* @var string[] Parts of the name
1628+
* @deprecated Use getParts() instead
1629+
*/`
15961630
* `$specialClassNames` - ``
15971631

15981632
<br>
@@ -1621,7 +1655,10 @@ return new FullyQualified('SomeNamespace\ShortName');
16211655

16221656
### Public Properties
16231657

1624-
* `$parts` - `/** @var string[] Parts of the name */`
1658+
* `$parts` - `/**
1659+
* @var string[] Parts of the name
1660+
* @deprecated Use getParts() instead
1661+
*/`
16251662

16261663
<br>
16271664

@@ -1680,7 +1717,7 @@ $variableName
16801717

16811718
### Public Properties
16821719

1683-
* `$type` - `/** @var null|Identifier|Name|NullableType|UnionType Type declaration */`
1720+
* `$type` - `/** @var null|Identifier|Name|ComplexType Type declaration */`
16841721
* `$byRef` - `/** @var bool Whether parameter is passed by reference */`
16851722
* `$variadic` - `/** @var bool Whether this is a variadic argument */`
16861723
* `$var` - `/** @var Expr\Variable|Expr\Error Parameter variable */`
@@ -1940,7 +1977,7 @@ public function methodName()
19401977
* `$byRef` - `/** @var bool Whether to return by reference */`
19411978
* `$name` - `/** @var Node\Identifier Name */`
19421979
* `$params` - `/** @var Node\Param[] Parameters */`
1943-
* `$returnType` - `/** @var null|Node\Identifier|Node\Name|Node\NullableType|Node\UnionType Return type */`
1980+
* `$returnType` - `/** @var null|Node\Identifier|Node\Name|Node\ComplexType Return type */`
19441981
* `$stmts` - `/** @var Node\Stmt[]|null Statements */`
19451982
* `$attrGroups` - `/** @var Node\AttributeGroup[] PHP attribute groups */`
19461983
* `$magicNames` - ``
@@ -2028,6 +2065,7 @@ final class ClassName extends \ParentClass
20282065
* `$name` - `/** @var Node\Identifier|null Name */`
20292066
* `$stmts` - `/** @var Node\Stmt[] Statements */`
20302067
* `$attrGroups` - `/** @var Node\AttributeGroup[] PHP attribute groups */`
2068+
* `$namespacedName` - `/** @var Node\Name|null Namespaced name (if using NameResolver) */`
20312069

20322070
<br>
20332071

@@ -2264,9 +2302,10 @@ function some_function()
22642302
* `$byRef` - `/** @var bool Whether function returns by reference */`
22652303
* `$name` - `/** @var Node\Identifier Name */`
22662304
* `$params` - `/** @var Node\Param[] Parameters */`
2267-
* `$returnType` - `/** @var null|Node\Identifier|Node\Name|Node\NullableType|Node\UnionType Return type */`
2305+
* `$returnType` - `/** @var null|Node\Identifier|Node\Name|Node\ComplexType Return type */`
22682306
* `$stmts` - `/** @var Node\Stmt[] Statements */`
22692307
* `$attrGroups` - `/** @var Node\AttributeGroup[] PHP attribute groups */`
2308+
* `$namespacedName` - `/** @var Node\Name|null Namespaced name (if using NameResolver) */`
22702309

22712310
<br>
22722311

@@ -2366,6 +2405,7 @@ interface InterfaceName
23662405
* `$name` - `/** @var Node\Identifier|null Name */`
23672406
* `$stmts` - `/** @var Node\Stmt[] Statements */`
23682407
* `$attrGroups` - `/** @var Node\AttributeGroup[] PHP attribute groups */`
2408+
* `$namespacedName` - `/** @var Node\Name|null Namespaced name (if using NameResolver) */`
23692409

23702410
<br>
23712411

@@ -2473,7 +2513,7 @@ public static $firstProperty, $secondProperty;
24732513

24742514
* `$flags` - `/** @var int Modifiers */`
24752515
* `$props` - `/** @var PropertyProperty[] Properties */`
2476-
* `$type` - `/** @var null|Identifier|Name|NullableType|UnionType Type declaration */`
2516+
* `$type` - `/** @var null|Identifier|Name|ComplexType Type declaration */`
24772517
* `$attrGroups` - `/** @var Node\AttributeGroup[] PHP attribute groups */`
24782518

24792519
<br>
@@ -2742,6 +2782,7 @@ trait TraitName
27422782
* `$name` - `/** @var Node\Identifier|null Name */`
27432783
* `$stmts` - `/** @var Node\Stmt[] Statements */`
27442784
* `$attrGroups` - `/** @var Node\AttributeGroup[] PHP attribute groups */`
2785+
* `$namespacedName` - `/** @var Node\Name|null Namespaced name (if using NameResolver) */`
27452786

27462787
<br>
27472788

@@ -2915,6 +2956,6 @@ string|int
29152956

29162957
### Public Properties
29172958

2918-
* `$types` - `/** @var (Identifier|Name)[] Types */`
2959+
* `$types` - `/** @var (Identifier|Name|IntersectionType)[] Types */`
29192960

29202961
<br>

phpstan.neon

-5
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,3 @@ parameters:
44
paths:
55
- src
66
- tests
7-
8-
ignoreErrors:
9-
-
10-
message: '#Cannot cast (.*?) to string#'
11-
path: src/Command/DumpNodesCommand.php

snippet/method_call_fluent.php

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use PhpParser\Node\Arg;
6+
use PhpParser\Node\Expr\MethodCall;
7+
use PhpParser\Node\Expr\Variable;
8+
use PhpParser\Node\Scalar\String_;
9+
10+
$variable = new Variable('someObject');
11+
12+
$args = [];
13+
$args[] = new Arg(new String_('yes'));
14+
15+
$methodCall = new MethodCall($variable, 'methodName', $args);
16+
17+
$nestedMethodCall = new MethodCall($methodCall, 'nextMethodName');
18+
19+
return $nestedMethodCall;

src/Command/DumpNodesCommand.php

+4-19
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,10 @@
88
use Rector\PhpParserNodesDocs\Printer\MarkdownNodeInfosPrinter;
99
use Symfony\Component\Console\Command\Command;
1010
use Symfony\Component\Console\Input\InputInterface;
11-
use Symfony\Component\Console\Input\InputOption;
1211
use Symfony\Component\Console\Output\OutputInterface;
1312

1413
final class DumpNodesCommand extends Command
1514
{
16-
/**
17-
* @var string
18-
*/
19-
private const OUTPUT_FILE = 'output-file';
20-
2115
public function __construct(
2216
private readonly MarkdownNodeInfosPrinter $markdownNodeInfosPrinter,
2317
private readonly NodeInfosFactory $nodeInfosFactory,
@@ -29,29 +23,20 @@ protected function configure(): void
2923
{
3024
$this->setName('dump-nodes');
3125
$this->setDescription('Dump nodes overview');
32-
33-
$this->addOption(
34-
self::OUTPUT_FILE,
35-
null,
36-
InputOption::VALUE_REQUIRED,
37-
'Where to output the file',
38-
getcwd() . '/docs/nodes_overview.md'
39-
);
4026
}
4127

4228
protected function execute(InputInterface $input, OutputInterface $output): int
4329
{
44-
$outputFile = (string) $input->getOption(self::OUTPUT_FILE);
45-
4630
$nodeInfos = $this->nodeInfosFactory->create();
4731
$printedContent = $this->markdownNodeInfosPrinter->print($nodeInfos);
4832

49-
file_put_contents($outputFile, $printedContent);
33+
file_put_contents(getcwd() . '/README.md', $printedContent);
34+
35+
$output->write(PHP_EOL);
5036

5137
$output->writeln(sprintf(
52-
'Documentation for "%d" PhpParser Nodes was generated to "%s"',
38+
'<info>Documentation for %d nodes was generated to README.md</info>' . PHP_EOL,
5339
count($nodeInfos),
54-
$outputFile
5540
));
5641

5742
return self::SUCCESS;

src/NodeCodeSampleProvider.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ public function provide(): array
3434
/** @var string $fileContents */
3535
$fileContents = file_get_contents($phpFilePath);
3636

37-
Assert::isInstanceOf($node, Node::class, $phpFilePath);
37+
$errorMessage = sprintf('The "%s" file must return "%s" instance ', $phpFilePath, Node::class);
38+
Assert::isInstanceOf($node, Node::class, $errorMessage);
3839

3940
$nodeClass = $node::class;
4041

0 commit comments

Comments
 (0)