Decopule nodes docs generator (#5453)

Co-authored-by: kaizen-ci <info@kaizen-ci.org>
This commit is contained in:
Tomas Votruba 2021-02-08 02:04:48 +01:00 committed by GitHub
parent f7c1103571
commit e9cdf37d16
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
124 changed files with 90 additions and 1858 deletions

View File

@ -65,7 +65,7 @@ It supports all versions of PHP from 5.2 and major open-source projects:
- [Explore 660+ Rector Rules](/docs/rector_rules_overview.md)
- [How Does Rector Work?](/docs/how_it_works.md)
- [PHP Parser Nodes](/docs/nodes_overview.md)
- [PHP Parser Nodes](https://github.com/rectorphp/php-parser-nodes-docs/blob/master/docs/nodes_overview.md)
### Advanced

View File

@ -19,7 +19,7 @@ require __DIR__ . '/../vendor/autoload.php';
$fileRenamer = new FileRenamer();
$fileRenamer->rename(
// paths
[__DIR__ . '/../utils/node-documentation-generator/snippet'],
[__DIR__ . '/../utils'],
'*.php.inc',
'#(\.php\.inc)$#',
'.php'

View File

@ -48,16 +48,16 @@
"symfony/finder": "^4.4.8|^5.1",
"symfony/http-kernel": "^4.4.8|^5.1",
"symfony/process": "^4.4.8|^5.1",
"symplify/astral": "^9.0.47",
"symplify/autowire-array-parameter": "^9.0.47",
"symplify/console-color-diff": "^9.0.47",
"symplify/package-builder": "^9.0.47",
"symplify/rule-doc-generator": "^9.0.47",
"symplify/set-config-resolver": "^9.0.47",
"symplify/simple-php-doc-parser": "^9.0.47",
"symplify/skipper": "^9.0.47",
"symplify/smart-file-system": "^9.0.47",
"symplify/symfony-php-config": "^9.0.47",
"symplify/astral": "^9.1.1",
"symplify/autowire-array-parameter": "^9.1.1",
"symplify/console-color-diff": "^9.1.1",
"symplify/package-builder": "^9.1.1",
"symplify/rule-doc-generator": "^9.1.1",
"symplify/set-config-resolver": "^9.1.1",
"symplify/simple-php-doc-parser": "^9.1.1",
"symplify/skipper": "^9.1.1",
"symplify/smart-file-system": "^9.1.1",
"symplify/symfony-php-config": "^9.1.1",
"webmozart/assert": "^1.9"
},
"require-dev": {
@ -71,13 +71,13 @@
"phpunit/phpunit": "^9.5",
"symfony/security-core": "^5.2",
"symfony/security-http": "^5.2",
"symplify/changelog-linker": "^9.0.47",
"symplify/coding-standard": "^9.0.47",
"symplify/easy-coding-standard": "^9.0.47",
"symplify/changelog-linker": "^9.1.1",
"symplify/coding-standard": "^9.1.1",
"symplify/easy-coding-standard": "^9.1.1",
"symplify/easy-ci": "^9.1.0",
"symplify/easy-testing": "^9.0.47",
"symplify/phpstan-extensions": "^9.0.47",
"symplify/phpstan-rules": "^9.0.47",
"symplify/easy-testing": "^9.1.1",
"symplify/phpstan-extensions": "^9.1.1",
"symplify/phpstan-rules": "^9.1.1",
"tracy/tracy": "^2.8"
},
"replace": {
@ -291,8 +291,6 @@
"Rector\\Transform\\Tests\\": "rules/transform/tests",
"Rector\\TypeDeclaration\\Tests\\": "rules/type-declaration/tests",
"Rector\\Utils\\DoctrineAnnotationParserSyncer\\": "utils/doctrine-annotation-parser-syncer/src",
"Rector\\Utils\\NodeDocumentationGenerator\\": "utils/node-documentation-generator/src",
"Rector\\Utils\\NodeDocumentationGenerator\\Tests\\": "utils/node-documentation-generator/tests",
"Rector\\Utils\\PHPStanTypeMapperChecker\\": "utils/phpstan-type-mapper-checker/src",
"Rector\\Utils\\ProjectValidator\\": "utils/project-validator/src",
"Rector\\Carbon\\Tests\\": "rules/carbon/tests",
@ -323,7 +321,6 @@
],
"docs": [
"vendor/bin/rule-doc-generator generate packages rules --output-file docs/rector_rules_overview.md --ansi --categorize",
"bin/rector dump-nodes --output-file docs/nodes_overview.md --ansi",
"vendor/bin/ecs check-markdown docs/rector_rules_overview.md docs/nodes_overview.md --ansi --fix"
],
"rector-ci": "bin/rector process --dry-run --ansi",

View File

@ -58,14 +58,7 @@ return static function (ContainerConfigurator $containerConfigurator): void {
__DIR__ . '/config/set',
]);
$parameters->set(Option::SETS, [
SetList::PSR_12,
SetList::PHP_70,
SetList::PHP_71,
SetList::SYMPLIFY,
SetList::COMMON,
SetList::CLEAN_CODE,
]);
$parameters->set(Option::SETS, [SetList::PSR_12, SetList::SYMPLIFY, SetList::COMMON, SetList::CLEAN_CODE]);
$parameters->set(Option::SKIP, [
'*/Source/*',

View File

@ -33,17 +33,10 @@ final class PHPStanServicesFactory
$containerFactory = new ContainerFactory(getcwd());
$additionalConfigFiles = [];
$additionalConfigFiles[] = $parameterProvider->provideStringParameter(Option::PHPSTAN_FOR_RECTOR_PATH);
$additionalConfigFiles[] = getcwd() . '/vendor/phpstan/phpstan-phpunit/extension.neon';
// enable type inferring from constructor
$additionalConfigFiles[] = __DIR__ . '/../../config/phpstan/better-infer.neon';
// symplify phpstan extensions
$additionalConfigFiles[] = getcwd() . '/vendor/symplify/phpstan-extensions/config/config.neon';
$existingAdditionalConfigFiles = array_filter($additionalConfigFiles, 'file_exists');
$this->container = $containerFactory->create(sys_get_temp_dir(), $existingAdditionalConfigFiles, []);
}

View File

@ -1,4 +1,9 @@
# this config has extensions, that helps PHPStan inside Rector to resolve more precise types
parameters:
inferPrivatePropertyTypeFromConstructor: true
includes:
- utils/phpstan-extensions/config/phpstan-extensions.neon
- vendor/phpstan/phpstan-nette/extension.neon
- vendor/symplify/astral/config/services.neon
- vendor/symplify/phpstan-extensions/config/config.neon

View File

@ -88,17 +88,9 @@ parameters:
# known types
- '#Access to an undefined property PhpParser\\Node\\Expr\:\:\$args#'
- '#Parameter \#2 \$name of method Rector\\Core\\Rector\\AbstractRector\:\:isName\(\) expects string, string\|null given#'
# sense-less errors
# PHP 7.4 1_000 support
- '#Property PhpParser\\Node\\Scalar\\DNumber\:\:\$value \(float\) does not accept string#'
-
message: '#Class Rector\\Generic\\Tests\\Rector\\StaticCall\\SwapClassMethodArgumentsRector\\Fixture\\SomeClass not found#'
path: rules/generic/tests/Rector/StaticCall/SwapClassMethodArgumentsRector/SwapClassMethodArgumentsRectorTest.php
# mixed
- '#Offset int\|string\|null does not exist on array<PhpParser\\Node\\Stmt>\|null#'
- '#class-string<T of object>\|T of object#'
@ -145,7 +137,6 @@ parameters:
# known value
- '#Property PhpParser\\Node\\Stmt\\Foreach_\:\:\$valueVar \(PhpParser\\Node\\Expr\) does not accept PhpParser\\Node\\Expr\|null#'
- '#Access to an undefined property PHPStan\\PhpDocParser\\Ast\\PhpDoc\\PhpDocTagValueNode\:\:\$type#'
- '#Content of method "configure\(\)" is duplicated with method "configure\(\)" in "Rector\\Composer\\Rector\\AddPackageToRequireComposerRector" class\. Use unique content or abstract service instead#'
# only local use
-
@ -322,7 +313,6 @@ parameters:
-
message: '#Cannot cast array<string\>\|bool\|string\|null to string#'
paths:
- utils/node-documentation-generator/src/Command/DumpNodesCommand.php
- src/Configuration/Configuration.php
- src/Console/Command/ProcessCommand.php
@ -482,10 +472,6 @@ parameters:
- '#Content of method "configure\(\)" is duplicated with method "configure\(\)" in "Rector\\Composer\\Rector\\AddPackageToRequireComposerRector" class\. Use unique content or abstract service instead#'
- '#Content of method "getFunctionLikePhpDocInfo\(\)" is duplicated with method "getFunctionLikePhpDocInfo\(\)" in "Rector\\TypeDeclaration\\TypeInferer\\ParamTypeInferer\\PHPUnitDataProviderParamTypeInferer" class\. Use unique content or abstract service instead#'
- '#Parameter \#1 \$type of method Rector\\BetterPhpDocParser\\PhpDocInfo\\PhpDocInfo\:\:hasByType\(\) expects class\-string<PHPStan\\PhpDocParser\\Ast\\PhpDoc\\PhpDocTagValueNode\>, string given#'
- '#Method Rector\\BetterPhpDocParser\\PhpDocInfo\\PhpDocInfo\:\:findAllByType\(\) should return array<T of PHPStan\\PhpDocParser\\Ast\\Node\> but returns array<int, PHPStan\\PhpDocParser\\Ast\\PhpDoc\\PhpDocTagNode\|\(PHPStan\\PhpDocParser\\Ast\\PhpDoc\\PhpDocTagValueNode&T of PHPStan\\PhpDocParser\\Ast\\Node\)\>#'
# buggy phpstan clas-string
- '#Method (.*?) should return class\-string but returns string#'
@ -518,14 +504,6 @@ parameters:
message: '#Use value object over return of values#'
path: packages/better-php-doc-parser/src/PhpDocNodeFactory/MultiPhpDocNodeFactory.php
-
message: '#Do not use setter on a service#'
path: packages/better-php-doc-parser/src/PhpDocNodeFactory/NetteInjectDocNodeFactory.php
- '#Content of method "getFunctionLikePhpDocInfo\(\)" is duplicated with method "getFunctionLikePhpDocInfo\(\)" in "Rector\\NodeTypeResolver\\NodeTypeResolver\\ParamTypeResolver" class\. Use unique content or abstract service instead#'
# constants
- '#Parameter \#1 \$types of method Rector\\BetterPhpDocParser\\PhpDocInfo\\PhpDocInfo\:\:hasByTypes\(\) expects array<class\-string<PHPStan\\PhpDocParser\\Ast\\PhpDoc\\PhpDocTagValueNode\>\>, array<int, (.*?)\> given#'
-
message: '#Use defined constant Symplify\\ComposerJsonManipulator\\ValueObject\\ComposerJsonSection\:\:REQUIRE over string require#'
paths:
@ -534,3 +512,10 @@ parameters:
- '#Class Acme\\Bar\\DoNotUpdateExistingTargetNamespace not found#'
- '#Class Acme\\Foo\\DoNotUpdateExistingTargetNamespace not found#'
- '#Content of method "getFunctionLikePhpDocInfo\(\)" is duplicated with method "getFunctionLikePhpDocInfo\(\)" in "Rector\\TypeDeclaration\\TypeInferer\\ParamTypeInferer\\PHPUnitDataProviderParamTypeInferer" class\. Use unique content or abstract service instead#'
- '#Method Rector\\Core\\PhpParser\\Node\\BetterNodeFinder\:\:findParentType\(\) should return T of PhpParser\\Node\|null but returns class\-string<T of PhpParser\\Node\>\|T of PhpParser\\Node#'
-
message: '#Namespace "Rector\\Composer\\Tests\\Rector" is only reserved for "Rector"\. Move the class somewhere else#'
path: rules/composer/tests/Rector/AbstractComposerRectorTestCase.php

View File

@ -196,6 +196,7 @@ CODE_SAMPLE
return false;
}
/** @var ArrayDimFetch[] $arrayDimFetches */
$arrayDimFetches = $this->betterNodeFinder->findInstanceOf($node, ArrayDimFetch::class);
foreach ($arrayDimFetches as $arrayDimFetch) {

View File

@ -51,6 +51,7 @@ final class AnonymousFunctionFactory
*/
public function create(ClassMethod $classMethod, Node $node): Closure
{
/** @var Return_[] $classMethodReturns */
$classMethodReturns = $this->betterNodeFinder->findInstanceOf((array) $classMethod->stmts, Return_::class);
$anonymousFunction = new Closure();

View File

@ -8,7 +8,6 @@ use PhpParser\Node;
use PhpParser\Node\Expr\Assign;
use PhpParser\Node\Expr\Variable;
use PhpParser\Node\FunctionLike;
use PhpParser\Node\Stmt\ClassMethod;
use PhpParser\Node\Stmt\Expression;
use Rector\Core\Rector\AbstractRector;
use Rector\NodeTypeResolver\Node\AttributeKey;
@ -86,9 +85,9 @@ CODE_SAMPLE
/**
* @return Variable[]
*/
private function findVariableUsages(ClassMethod $classMethod, Assign $assign): array
private function findVariableUsages(FunctionLike $functionLike, Assign $assign): array
{
return $this->betterNodeFinder->find((array) $classMethod->getStmts(), function (Node $node) use (
return $this->betterNodeFinder->find((array) $functionLike->getStmts(), function (Node $node) use (
$assign
): bool {
if (! $node instanceof Variable) {

View File

@ -1,51 +0,0 @@
<?php
namespace Rector\Naming\Tests\Rector\Assign\RenameVariableToMatchMethodCallReturnTypeRector\Fixture;
use PhpParser\Node\Stmt\ClassLike;
use PhpParser\Node\Stmt\ClassMethod;
use PhpParser\Node\Stmt\Interface_;
use Rector\NodeTypeResolver\Node\AttributeKey;
class RenameVariableExpression
{
private function shouldSkip(ClassMethod $classMethod): bool
{
/** @var ClassLike|null $class */
$class = $classMethod->getAttribute(AttributeKey::CLASS_NODE);
if ($class === null) {
return true;
}
/** @var Interface_ $class */
return ! (bool) $class->extends;
}
}
?>
-----
<?php
namespace Rector\Naming\Tests\Rector\Assign\RenameVariableToMatchMethodCallReturnTypeRector\Fixture;
use PhpParser\Node\Stmt\ClassLike;
use PhpParser\Node\Stmt\ClassMethod;
use PhpParser\Node\Stmt\Interface_;
use Rector\NodeTypeResolver\Node\AttributeKey;
class RenameVariableExpression
{
private function shouldSkip(ClassMethod $classMethod): bool
{
/** @var ClassLike|null $classLike */
$classLike = $classMethod->getAttribute(AttributeKey::CLASS_NODE);
if ($classLike === null) {
return true;
}
/** @var Interface_ $classLike */
return ! (bool) $classLike->extends;
}
}
?>

View File

@ -2,7 +2,7 @@
namespace Rector\Transform\Tests\Rector\MethodCall\MethodCallToStaticCallRector\Fixture;
use Rector\Transform\Tests\Rector\MethodCall\MethodCallToStaticCallRector\AnotherDependency;
use Rector\Transform\Tests\Rector\MethodCall\MethodCallToStaticCallRector\Source\AnotherDependency;
final class SomeClass
{
@ -25,7 +25,7 @@ final class SomeClass
namespace Rector\Transform\Tests\Rector\MethodCall\MethodCallToStaticCallRector\Fixture;
use Rector\Transform\Tests\Rector\MethodCall\MethodCallToStaticCallRector\AnotherDependency;
use Rector\Transform\Tests\Rector\MethodCall\MethodCallToStaticCallRector\Source\AnotherDependency;
final class SomeClass
{

View File

@ -7,6 +7,7 @@ namespace Rector\Transform\Tests\Rector\MethodCall\MethodCallToStaticCallRector;
use Iterator;
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
use Rector\Transform\Rector\MethodCall\MethodCallToStaticCallRector;
use Rector\Transform\Tests\Rector\MethodCall\MethodCallToStaticCallRector\Source\AnotherDependency;
use Rector\Transform\ValueObject\MethodCallToStaticCall;
use Symplify\SmartFileSystem\SmartFileInfo;

View File

@ -2,7 +2,7 @@
declare(strict_types=1);
namespace Rector\Transform\Tests\Rector\MethodCall\MethodCallToStaticCallRector;
namespace Rector\Transform\Tests\Rector\MethodCall\MethodCallToStaticCallRector\Source;
final class AnotherDependency
{

View File

@ -13,7 +13,6 @@ use Rector\Core\Configuration\Configuration;
use Rector\Core\Configuration\Option;
use Rector\Core\Exception\Configuration\InvalidConfigurationException;
use Rector\Core\Exception\NoRectorsLoadedException;
use Rector\Utils\NodeDocumentationGenerator\Command\DumpNodesCommand;
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputDefinition;
@ -89,11 +88,6 @@ final class ConsoleApplication extends Application
}
// skip in this case, since generate content must be clear from meta-info
$dumpCommands = [CommandNaming::classToName(DumpNodesCommand::class)];
if (in_array($input->getFirstArgument(), $dumpCommands, true)) {
return parent::doRun($input, $output);
}
if ($this->shouldPrintMetaInformation($input)) {
$output->writeln($this->getLongVersion());
$shouldFollowByNewline = true;

View File

@ -76,7 +76,7 @@ final class BetterNodeFinder
return $parent;
}
if ($parent === null) {
if (! $parent instanceof Node) {
return null;
}
} while ($parent = $parent->getAttribute(AttributeKey::PARENT_NODE));
@ -135,7 +135,8 @@ final class BetterNodeFinder
public function findFirstAncestorInstancesOf(Node $node, array $types): ?Node
{
$currentNode = $node->getAttribute(AttributeKey::PARENT_NODE);
while ($currentNode !== null) {
while ($currentNode instanceof Node) {
foreach ($types as $type) {
if (is_a($currentNode, $type, true)) {
return $currentNode;

View File

@ -48,7 +48,7 @@ final class ClassReflectionToAstResolver
return $this->getClass($classReflection, $className);
}
public function getClass(ClassReflection $classReflection, string $className): ?Class_
private function getClass(ClassReflection $classReflection, string $className): ?Class_
{
if ($classReflection->isBuiltin()) {
return null;
@ -59,8 +59,9 @@ final class ClassReflectionToAstResolver
/** @var Node[] $contentNodes */
$contentNodes = $this->parser->parse($this->smartFileSystem->readFile($fileName));
$classes = $this->betterNodeFinder->findInstanceOf($contentNodes, Class_::class);
/** @var Class_[] $classes */
$classes = $this->betterNodeFinder->findInstanceOf($contentNodes, Class_::class);
if ($classes === []) {
return null;
}

View File

@ -1,20 +0,0 @@
<?php
declare(strict_types=1);
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Symplify\SmartFileSystem\Finder\SmartFinder;
return static function (ContainerConfigurator $containerConfigurator): void {
$services = $containerConfigurator->services();
$services->defaults()
->public()
->autowire()
->autoconfigure();
$services->load('Rector\Utils\NodeDocumentationGenerator\\', __DIR__ . '/../src')
->exclude([__DIR__ . '/../src/ValueObject']);
$services->set(SmartFinder::class);
};

View File

@ -1,11 +0,0 @@
<?php
declare(strict_types=1);
use PhpParser\Node\Name\FullyQualified;
use PhpParser\Node\Stmt\Class_;
use PhpParser\Node\Stmt\TraitUseAdaptation\Alias;
$traitFullyQualified = new FullyQualified('TraitName');
return new Alias($traitFullyQualified, 'method', Class_::MODIFIER_PUBLIC, 'aliasedMethod');

View File

@ -1,15 +0,0 @@
<?php
declare(strict_types=1);
use PhpParser\Node\Expr\Array_;
use PhpParser\Node\Expr\ArrayItem;
use PhpParser\Node\Expr\Variable;
use PhpParser\Node\Scalar\String_;
$value = new Variable('Tom');
$key = new String_('name');
$arrayItem = new ArrayItem($value, $key);
return new Array_([$arrayItem]);

View File

@ -1,12 +0,0 @@
<?php
declare(strict_types=1);
use PhpParser\Node\Expr\ArrayDimFetch;
use PhpParser\Node\Expr\Variable;
use PhpParser\Node\Scalar\LNumber;
$variable = new Variable('variableName');
$dimension = new LNumber(0);
return new ArrayDimFetch($variable, $dimension);

View File

@ -1,12 +0,0 @@
<?php
declare(strict_types=1);
use PhpParser\Node\Expr\ArrayItem;
use PhpParser\Node\Expr\Variable;
use PhpParser\Node\Scalar\String_;
$value = new Variable('Tom');
$key = new String_('name');
return new ArrayItem($value, $key);

View File

@ -1,12 +0,0 @@
<?php
declare(strict_types=1);
use PhpParser\Node\Expr\Assign;
use PhpParser\Node\Expr\Variable;
use PhpParser\Node\Scalar\String_;
$variable = new Variable('variableName');
$value = new String_('some value');
return new Assign($variable, $value);

View File

@ -1,11 +0,0 @@
<?php
declare(strict_types=1);
use PhpParser\Node\Expr\AssignOp\Coalesce;
use PhpParser\Node\Scalar\LNumber;
$left = new LNumber(5);
$right = new LNumber(10);
return new Coalesce($left, $right);

View File

@ -1,11 +0,0 @@
<?php
declare(strict_types=1);
use PhpParser\Node\Expr\AssignOp\Concat;
use PhpParser\Node\Scalar\LNumber;
$left = new LNumber(5);
$right = new LNumber(10);
return new Concat($left, $right);

View File

@ -1,13 +0,0 @@
<?php
declare(strict_types=1);
use PhpParser\Node\Expr\Assign;
use PhpParser\Node\Expr\PropertyFetch;
use PhpParser\Node\Expr\Variable;
use PhpParser\Node\Scalar\String_;
$propertyFetch = new PropertyFetch(new Variable('someObject'), 'someProperty');
$value = new String_('some value');
return new Assign($propertyFetch, $value);

View File

@ -1,11 +0,0 @@
<?php
declare(strict_types=1);
use PhpParser\Node\Expr\BinaryOp\BooleanAnd;
use PhpParser\Node\Scalar\LNumber;
$left = new LNumber(5);
$right = new LNumber(10);
return new BooleanAnd($left, $right);

View File

@ -1,11 +0,0 @@
<?php
declare(strict_types=1);
use PhpParser\Node\Expr\BinaryOp\Coalesce;
use PhpParser\Node\Scalar\LNumber;
$left = new LNumber(5);
$right = new LNumber(10);
return new Coalesce($left, $right);

View File

@ -1,11 +0,0 @@
<?php
declare(strict_types=1);
use PhpParser\Node\Expr\BinaryOp\Concat;
use PhpParser\Node\Scalar\LNumber;
$left = new LNumber(5);
$right = new LNumber(10);
return new Concat($left, $right);

View File

@ -1,11 +0,0 @@
<?php
declare(strict_types=1);
use PhpParser\Node\Expr\BinaryOp\Equal;
use PhpParser\Node\Scalar\LNumber;
$left = new LNumber(5);
$right = new LNumber(10);
return new Equal($left, $right);

View File

@ -1,11 +0,0 @@
<?php
declare(strict_types=1);
use PhpParser\Node\Expr\BinaryOp\Identical;
use PhpParser\Node\Scalar\LNumber;
$left = new LNumber(5);
$right = new LNumber(10);
return new Identical($left, $right);

View File

@ -1,11 +0,0 @@
<?php
declare(strict_types=1);
use PhpParser\Node\Expr\BinaryOp\Minus;
use PhpParser\Node\Scalar\LNumber;
$left = new LNumber(5);
$right = new LNumber(10);
return new Minus($left, $right);

View File

@ -1,11 +0,0 @@
<?php
declare(strict_types=1);
use PhpParser\Node\Expr\BinaryOp\NotEqual;
use PhpParser\Node\Scalar\LNumber;
$left = new LNumber(5);
$right = new LNumber(10);
return new NotEqual($left, $right);

View File

@ -1,11 +0,0 @@
<?php
declare(strict_types=1);
use PhpParser\Node\Expr\BinaryOp\NotIdentical;
use PhpParser\Node\Scalar\LNumber;
$left = new LNumber(5);
$right = new LNumber(10);
return new NotIdentical($left, $right);

View File

@ -1,11 +0,0 @@
<?php
declare(strict_types=1);
use PhpParser\Node\Expr\BinaryOp\Spaceship;
use PhpParser\Node\Scalar\LNumber;
$left = new LNumber(5);
$right = new LNumber(10);
return new Spaceship($left, $right);

View File

@ -1,10 +0,0 @@
<?php
declare(strict_types=1);
use PhpParser\Node\Expr\BooleanNot;
use PhpParser\Node\Expr\Variable;
$variable = new Variable('isEligible');
return new BooleanNot($variable);

View File

@ -1,10 +0,0 @@
<?php
declare(strict_types=1);
use PhpParser\Node\Expr\Cast\Array_;
use PhpParser\Node\Expr\Variable;
$expr = new Variable('variableName');
return new Array_($expr);

View File

@ -1,10 +0,0 @@
<?php
declare(strict_types=1);
use PhpParser\Node\Expr\Cast\Bool_;
use PhpParser\Node\Expr\Variable;
$expr = new Variable('variableName');
return new Bool_($expr);

View File

@ -1,10 +0,0 @@
<?php
declare(strict_types=1);
use PhpParser\Node\Expr\Cast\Int_;
use PhpParser\Node\Expr\Variable;
$expr = new Variable('variableName');
return new Int_($expr);

View File

@ -1,10 +0,0 @@
<?php
declare(strict_types=1);
use PhpParser\Node\Expr\Cast\String_;
use PhpParser\Node\Expr\Variable;
$expr = new Variable('variableName');
return new String_($expr);

View File

@ -1,7 +0,0 @@
<?php
declare(strict_types=1);
use PhpParser\Node\Stmt\Class_;
return new Class_('ClassName');

View File

@ -1,13 +0,0 @@
<?php
declare(strict_types=1);
use PhpParser\Node\Const_;
use PhpParser\Node\Scalar\String_;
use PhpParser\Node\Stmt\Class_;
use PhpParser\Node\Stmt\ClassConst;
$defaultValue = new String_('default value');
$const = new Const_('SOME_CLASS_CONSTANT', $defaultValue);
return new ClassConst([$const], Class_::MODIFIER_PUBLIC);

View File

@ -1,10 +0,0 @@
<?php
declare(strict_types=1);
use PhpParser\Node\Expr\ClassConstFetch;
use PhpParser\Node\Name\FullyQualified;
$class = new FullyQualified('SomeClassName');
return new ClassConstFetch($class, 'SOME_CONSTANT');

View File

@ -1,10 +0,0 @@
<?php
declare(strict_types=1);
use PhpParser\Node\Stmt\Class_;
$class = new Class_('ClassName');
$class->flags |= Class_::MODIFIER_FINAL;
return $class;

View File

@ -1,11 +0,0 @@
<?php
declare(strict_types=1);
use PhpParser\Node\Stmt\Class_;
use PhpParser\Node\Stmt\ClassMethod;
$classMethod = new ClassMethod('methodName');
$classMethod->flags = Class_::MODIFIER_PUBLIC;
return $classMethod;

View File

@ -1,18 +0,0 @@
<?php
declare(strict_types=1);
use PhpParser\Node\Expr\Variable;
use PhpParser\Node\Identifier;
use PhpParser\Node\Param;
use PhpParser\Node\Stmt\Class_;
use PhpParser\Node\Stmt\ClassMethod;
$classMethod = new ClassMethod('methodName');
$classMethod->flags = Class_::MODIFIER_PRIVATE;
$param = new Param(new Variable('paramName'));
$classMethod->params = [$param];
$classMethod->returnType = new Identifier('string');
return $classMethod;

View File

@ -1,21 +0,0 @@
<?php
declare(strict_types=1);
use PhpParser\Node\Expr\Assign;
use PhpParser\Node\Expr\Variable;
use PhpParser\Node\Scalar\LNumber;
use PhpParser\Node\Stmt\Class_;
use PhpParser\Node\Stmt\ClassMethod;
use PhpParser\Node\Stmt\Expression;
$classMethod = new ClassMethod('methodName');
$classMethod->flags = Class_::MODIFIER_PUBLIC;
$variable = new Variable('some');
$number = new LNumber(10000);
$assign = new Assign($variable, $number);
$classMethod->stmts[] = new Expression($assign);
return $classMethod;

View File

@ -1,16 +0,0 @@
<?php
declare(strict_types=1);
use PhpParser\Node\Stmt\Class_;
use PhpParser\Node\Stmt\Property;
use PhpParser\Node\Stmt\PropertyProperty;
$class = new Class_('ClassName');
$propertyProperty = new PropertyProperty('someProperty');
$property = new Property(Class_::MODIFIER_PRIVATE, [$propertyProperty]);
$class->stmts[] = $property;
return $propertyProperty;

View File

@ -1,10 +0,0 @@
<?php
declare(strict_types=1);
use PhpParser\Node\Expr\ClosureUse;
use PhpParser\Node\Expr\Variable;
$variable = new Variable('variableName');
return new ClosureUse($variable);

View File

@ -1,8 +0,0 @@
<?php
declare(strict_types=1);
use PhpParser\Node\Const_;
use PhpParser\Node\Scalar\String_;
return new Const_('CONSTANT_NAME', new String_('default'));

View File

@ -1,10 +0,0 @@
<?php
declare(strict_types=1);
use PhpParser\Node\Expr\ConstFetch;
use PhpParser\Node\Name;
$name = new Name('true');
return new ConstFetch($name);

View File

@ -1,11 +0,0 @@
<?php
declare(strict_types=1);
use PhpParser\Node\Const_;
use PhpParser\Node\Scalar\String_;
use PhpParser\Node\Stmt\Const_ as ConstStmt;
$consts = [new Const_('CONSTANT_IN_CLASS', new String_('default value'))];
return new ConstStmt($consts);

View File

@ -1,7 +0,0 @@
<?php
declare(strict_types=1);
use PhpParser\Node\Scalar\DNumber;
return new DNumber(10.5);

View File

@ -1,11 +0,0 @@
<?php
declare(strict_types=1);
use PhpParser\Node\Scalar\LNumber;
use PhpParser\Node\Stmt\Declare_;
use PhpParser\Node\Stmt\DeclareDeclare;
$declareDeclare = new DeclareDeclare('strict_types', new LNumber(1));
return new Declare_([$declareDeclare]);

View File

@ -1,10 +0,0 @@
<?php
declare(strict_types=1);
use PhpParser\Node\Expr\Variable;
use PhpParser\Node\Stmt\Do_;
$variable = new Variable('variableName');
return new Do_($variable);

View File

@ -1,10 +0,0 @@
<?php
declare(strict_types=1);
use PhpParser\Node\Scalar\String_;
use PhpParser\Node\Stmt\Echo_;
$string = new String_('hello');
return new Echo_([$string]);

View File

@ -1,14 +0,0 @@
<?php
declare(strict_types=1);
use PhpParser\Node\Expr\ConstFetch;
use PhpParser\Node\Name;
use PhpParser\Node\Stmt\ElseIf_;
use PhpParser\Node\Stmt\Return_;
$name = new Name('true');
$constFetch = new ConstFetch($name);
$stmt = new Return_();
return new ElseIf_($constFetch, [$stmt]);

View File

@ -1,10 +0,0 @@
<?php
declare(strict_types=1);
use PhpParser\Node\Expr\Empty_;
use PhpParser\Node\Expr\Variable;
$variable = new Variable('variableName');
return new Empty_($variable);

View File

@ -1,8 +0,0 @@
<?php
declare(strict_types=1);
use PhpParser\Node\Expr\Variable;
use PhpParser\Node\Scalar\Encapsed;
return new Encapsed([new Variable('variableName')]);

View File

@ -1,10 +0,0 @@
<?php
declare(strict_types=1);
use PhpParser\Node\Expr\Eval_;
use PhpParser\Node\Scalar\String_;
$string = new String_('Some php code');
return new Eval_(new String_('Some php code'));

View File

@ -1,13 +0,0 @@
<?php
declare(strict_types=1);
use PhpParser\Node\Name\FullyQualified;
use PhpParser\Node\Stmt\Class_;
$class = new Class_('ClassName');
$class->flags = Class_::MODIFIER_FINAL;
$class->extends = new FullyQualified('ParentClass');
return $class;

View File

@ -1,11 +0,0 @@
<?php
declare(strict_types=1);
use PhpParser\Node\Expr\Variable;
use PhpParser\Node\Stmt\Foreach_;
$foreachedVariable = new Variable('foreachedVariableName');
$asVariable = new Variable('asVariable');
return new Foreach_($foreachedVariable, $asVariable);

View File

@ -1,7 +0,0 @@
<?php
declare(strict_types=1);
use PhpParser\Node\Name\FullyQualified;
return new FullyQualified('SomeNamespace\ShortName');

View File

@ -1,12 +0,0 @@
<?php
declare(strict_types=1);
use PhpParser\Node\Arg;
use PhpParser\Node\Expr\FuncCall;
use PhpParser\Node\Expr\Variable;
use PhpParser\Node\Name;
$args = [new Arg(new Variable('someVariable'))];
return new FuncCall(new Name('func_call'), $args);

View File

@ -1,7 +0,0 @@
<?php
declare(strict_types=1);
use PhpParser\Node\Stmt\Function_;
return new Function_('some_function');

View File

@ -1,11 +0,0 @@
<?php
declare(strict_types=1);
use PhpParser\Node\Expr\ConstFetch;
use PhpParser\Node\Name;
use PhpParser\Node\Stmt\If_;
$cond = new ConstFetch(new Name('true'));
return new If_($cond);

View File

@ -1,10 +0,0 @@
<?php
declare(strict_types=1);
use PhpParser\Node\Expr\Include_;
use PhpParser\Node\Expr\Variable;
$variable = new Variable('variableName');
return new Include_($variable, Include_::TYPE_INCLUDE);

View File

@ -1,7 +0,0 @@
<?php
declare(strict_types=1);
use PhpParser\Node\Stmt\InlineHTML;
return new InlineHTML('<strong>feel</strong>');

View File

@ -1,12 +0,0 @@
<?php
declare(strict_types=1);
use PhpParser\Node\Expr\Instanceof_;
use PhpParser\Node\Expr\Variable;
use PhpParser\Node\Name\FullyQualified;
$variable = new Variable('variableName');
$class = new FullyQualified('SomeClassName');
return new Instanceof_($variable, $class);

View File

@ -1,8 +0,0 @@
<?php
declare(strict_types=1);
use PhpParser\Node\Identifier;
use PhpParser\Node\Stmt\Interface_;
return new Interface_(new Identifier('InterfaceName'));

View File

@ -1,10 +0,0 @@
<?php
declare(strict_types=1);
use PhpParser\Node\Expr\Isset_;
use PhpParser\Node\Expr\Variable;
$variable = new Variable('variableName');
return new Isset_([$variable]);

View File

@ -1,7 +0,0 @@
<?php
declare(strict_types=1);
use PhpParser\Node\Scalar\LNumber;
return new LNumber(1000);

View File

@ -1,7 +0,0 @@
<?php
declare(strict_types=1);
use PhpParser\Node\Stmt\Label;
return new Label('labelName');

View File

@ -1,14 +0,0 @@
<?php
declare(strict_types=1);
use PhpParser\Node\Expr\ArrayItem;
use PhpParser\Node\Expr\List_;
use PhpParser\Node\Expr\Variable;
$variable = new Variable('variableName');
$anotherVariable = new Variable('anoterVariableName');
$arrayItems = [new ArrayItem($variable), new ArrayItem($anotherVariable)];
return new List_($arrayItems);

View File

@ -1,10 +0,0 @@
<?php
declare(strict_types=1);
use PhpParser\Node\Expr\MethodCall;
use PhpParser\Node\Expr\Variable;
$variable = new Variable('someObject');
return new MethodCall($variable, 'methodName');

View File

@ -1,12 +0,0 @@
<?php
declare(strict_types=1);
use PhpParser\Node\Expr\MethodCall;
use PhpParser\Node\Expr\PropertyFetch;
use PhpParser\Node\Expr\Variable;
$thisVariable = new Variable('this');
$propertyFetch = new PropertyFetch($thisVariable, 'someProperty');
return new MethodCall($propertyFetch, 'methodName');

View File

@ -1,16 +0,0 @@
<?php
declare(strict_types=1);
use PhpParser\Node\Arg;
use PhpParser\Node\Expr\MethodCall;
use PhpParser\Node\Expr\Variable;
use PhpParser\Node\Scalar\String_;
$variable = new Variable('someObject');
$args = [];
$args[] = new Arg(new String_('yes'));
$args[] = new Arg(new String_('maybe'));
return new MethodCall($variable, 'methodName', $args);

View File

@ -1,7 +0,0 @@
<?php
declare(strict_types=1);
use PhpParser\Node\Name;
return new Name('shortName');

View File

@ -1,12 +0,0 @@
<?php
declare(strict_types=1);
// anonymous class
use PhpParser\Node\Expr\New_;
use PhpParser\Node\Stmt\Class_;
$class = new Class_(null);
return new New_($class);

View File

@ -1,10 +0,0 @@
<?php
declare(strict_types=1);
use PhpParser\Node\Expr\New_;
use PhpParser\Node\Name;
$class = new Name('SomeClass');
return new New_($class);

View File

@ -1,7 +0,0 @@
<?php
declare(strict_types=1);
use PhpParser\Node\NullableType;
return new NullableType('SomeType');

View File

@ -1,10 +0,0 @@
<?php
declare(strict_types=1);
use PhpParser\Node\Expr\Variable;
use PhpParser\Node\Param;
$variable = new Variable('variableName');
return new Param($variable);

View File

@ -1,10 +0,0 @@
<?php
declare(strict_types=1);
use PhpParser\Node\Expr\ArrowFunction;
use PhpParser\Node\Scalar\LNumber;
$subNodes['expr'] = new LNumber(1);
return new ArrowFunction($subNodes);

View File

@ -1,12 +0,0 @@
<?php
declare(strict_types=1);
use PhpParser\Node\Stmt\Class_;
use PhpParser\Node\Stmt\Property;
use PhpParser\Node\Stmt\PropertyProperty;
use PhpParser\Node\VarLikeIdentifier;
$propertyProperty = new PropertyProperty(new VarLikeIdentifier('propertyName'));
return new Property(Class_::MODIFIER_PUBLIC, [$propertyProperty], [], 'string');

View File

@ -1,17 +0,0 @@
<?php
declare(strict_types=1);
use PhpParser\Node\Expr\Match_;
use PhpParser\Node\Expr\Variable;
use PhpParser\Node\MatchArm;
use PhpParser\Node\Scalar\LNumber;
use PhpParser\Node\Scalar\String_;
$variable = new Variable('variableName');
$body = new String_('yes');
$cond = new LNumber(1);
$matchArm = new MatchArm([$cond], $body);
return new Match_($variable, [$matchArm]);

View File

@ -1,12 +0,0 @@
<?php
declare(strict_types=1);
use PhpParser\Node\MatchArm;
use PhpParser\Node\Scalar\LNumber;
use PhpParser\Node\Scalar\String_;
$conds = [new LNumber(1)];
$body = new String_('yes');
return new MatchArm($conds, $body);

View File

@ -1,10 +0,0 @@
<?php
declare(strict_types=1);
use PhpParser\Node\Expr\NullsafeMethodCall;
use PhpParser\Node\Expr\Variable;
$variable = new Variable('variableName');
return new NullsafeMethodCall($variable, 'methodName');

View File

@ -1,10 +0,0 @@
<?php
declare(strict_types=1);
use PhpParser\Node\Expr\NullsafePropertyFetch;
use PhpParser\Node\Expr\Variable;
$variable = new Variable('variableName');
return new NullsafePropertyFetch($variable, 'someProperty');

View File

@ -1,12 +0,0 @@
<?php
declare(strict_types=1);
use PhpParser\Node\Stmt\Class_;
use PhpParser\Node\Stmt\Property;
use PhpParser\Node\Stmt\PropertyProperty;
use PhpParser\Node\VarLikeIdentifier;
$propertyProperty = new PropertyProperty(new VarLikeIdentifier('propertyName'));
return new Property(Class_::MODIFIER_PUBLIC, [$propertyProperty]);

View File

@ -1,11 +0,0 @@
<?php
declare(strict_types=1);
use PhpParser\Node\Stmt\Class_;
use PhpParser\Node\Stmt\Property;
use PhpParser\Node\Stmt\PropertyProperty;
$propertyProperties = [new PropertyProperty('firstProperty'), new PropertyProperty('secondProperty')];
return new Property(Class_::MODIFIER_STATIC | Class_::MODIFIER_PUBLIC, $propertyProperties);

View File

@ -1,10 +0,0 @@
<?php
declare(strict_types=1);
use PhpParser\Node\Expr\PropertyFetch;
use PhpParser\Node\Expr\Variable;
$variable = new Variable('variableName');
return new PropertyFetch($variable, 'propertyName');

View File

@ -1,10 +0,0 @@
<?php
declare(strict_types=1);
use PhpParser\Node\Expr\Include_;
use PhpParser\Node\Expr\Variable;
$variable = new Variable('variableName');
return new Include_($variable, Include_::TYPE_REQUIRE_ONCE);

View File

@ -1,11 +0,0 @@
<?php
declare(strict_types=1);
use PhpParser\Node\Expr\Variable;
use PhpParser\Node\Stmt\Static_;
use PhpParser\Node\Stmt\StaticVar;
$staticVars = [new StaticVar(new Variable('static'))];
return new Static_($staticVars);

View File

@ -1,10 +0,0 @@
<?php
declare(strict_types=1);
use PhpParser\Node\Expr\StaticCall;
use PhpParser\Node\Name\FullyQualified;
$fullyQualified = new FullyQualified('ClassName');
return new StaticCall($fullyQualified, 'methodName');

View File

@ -1,10 +0,0 @@
<?php
declare(strict_types=1);
use PhpParser\Node\Expr\StaticPropertyFetch;
use PhpParser\Node\Name\FullyQualified;
$class = new FullyQualified('StaticClassName');
return new StaticPropertyFetch($class, 'someProperty');

View File

@ -1,10 +0,0 @@
<?php
declare(strict_types=1);
use PhpParser\Node\Expr\Variable;
use PhpParser\Node\Stmt\StaticVar;
$variable = new Variable('variableName');
return new StaticVar($variable);

View File

@ -1,7 +0,0 @@
<?php
declare(strict_types=1);
use PhpParser\Node\Scalar\String_;
return new String_('some string');

View File

@ -1,13 +0,0 @@
<?php
declare(strict_types=1);
use PhpParser\Node\Expr\Variable;
use PhpParser\Node\Scalar\LNumber;
use PhpParser\Node\Stmt\Case_;
use PhpParser\Node\Stmt\Switch_;
$cond = new Variable('variableName');
$cases = [new Case_(new LNumber(1))];
return new Switch_($cond, $cases);

View File

@ -1,15 +0,0 @@
<?php
declare(strict_types=1);
use PhpParser\Node\Expr\ConstFetch;
use PhpParser\Node\Expr\Ternary;
use PhpParser\Node\Expr\Variable;
use PhpParser\Node\Name;
$variable = new Variable('variableName');
$trueConstFetch = new ConstFetch(new Name('true'));
$falseConstFetch = new ConstFetch(new Name('false'));
return new Ternary($variable, $trueConstFetch, $falseConstFetch);

View File

@ -1,10 +0,0 @@
<?php
declare(strict_types=1);
use PhpParser\Node\Expr\Throw_;
use PhpParser\Node\Scalar\String_;
$string = new String_('some string');
return new Throw_($string);

Some files were not shown because too many files have changed in this diff Show More