From 225fa50952ab7d8c715d9d70593318d98f2da9fd Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Thu, 2 Jan 2025 17:31:33 +0100 Subject: [PATCH] Update php-cs-fixer config The existing configuration is not compatible with current php-cs-fixer anymore. Explicitly specify a version and use the @PSR12 config, which has a reasonably small diff. --- .php-cs-fixer.php | 157 ++---------------- demo.php | 2 +- lib/PHPCfg/Assertion.php | 6 +- lib/PHPCfg/AstVisitor/LoopResolver.php | 4 +- lib/PHPCfg/AstVisitor/MagicStringResolver.php | 10 +- lib/PHPCfg/AstVisitor/NameResolver.php | 16 +- lib/PHPCfg/Func.php | 18 +- lib/PHPCfg/Op.php | 9 +- lib/PHPCfg/Op/Expr.php | 1 - lib/PHPCfg/Op/Expr/ArrayDimFetch.php | 2 +- lib/PHPCfg/Op/Expr/Closure.php | 3 +- lib/PHPCfg/Op/Expr/Include_.php | 8 +- lib/PHPCfg/Op/Expr/Param.php | 17 +- lib/PHPCfg/Op/Stmt.php | 1 - lib/PHPCfg/Op/Stmt/ClassMethod.php | 14 +- lib/PHPCfg/Op/Stmt/Property.php | 12 +- lib/PHPCfg/Op/Stmt/TraitUse.php | 6 +- lib/PHPCfg/Op/Terminal.php | 1 - lib/PHPCfg/Op/Terminal/Const_.php | 1 - lib/PHPCfg/Op/Terminal/GlobalVar.php | 2 +- lib/PHPCfg/Op/TraitUseAdaptation.php | 6 +- lib/PHPCfg/Op/TraitUseAdaptation/Alias.php | 14 +- .../Op/TraitUseAdaptation/Precedence.php | 6 +- lib/PHPCfg/Op/Type.php | 38 ++--- lib/PHPCfg/Op/Type/Literal.php | 53 +++--- lib/PHPCfg/Op/Type/Mixed_.php | 38 ++--- lib/PHPCfg/Op/Type/Nullable.php | 61 +++---- lib/PHPCfg/Op/Type/Reference.php | 63 +++---- lib/PHPCfg/Op/Type/Union.php | 5 +- lib/PHPCfg/Op/Type/Void_.php | 38 ++--- lib/PHPCfg/Operand.php | 4 +- lib/PHPCfg/Operand/BoundVariable.php | 8 +- lib/PHPCfg/Operand/NullOperand.php | 42 ++--- lib/PHPCfg/Parser.php | 151 +++++++++-------- lib/PHPCfg/Printer.php | 87 +++++----- lib/PHPCfg/Printer/GraphViz.php | 25 +-- lib/PHPCfg/Printer/Text.php | 16 +- lib/PHPCfg/Traverser.php | 4 +- lib/PHPCfg/Visitor.php | 4 +- lib/PHPCfg/Visitor/DebugVisitor.php | 14 +- test/PHPCfg/ParserTest.php | 8 +- 41 files changed, 422 insertions(+), 553 deletions(-) diff --git a/.php-cs-fixer.php b/.php-cs-fixer.php index b9f7620..64ea9d5 100755 --- a/.php-cs-fixer.php +++ b/.php-cs-fixer.php @@ -8,154 +8,19 @@ EOF; $finder = PhpCsFixer\Finder::create() - ->name('.php_cs') - ->exclude('vendor') - ->exclude('.git') + ->name('.php_cs') + ->exclude('vendor') + ->exclude('.git') ->in(__DIR__); -return PhpCsFixer\Config::create() - ->setIndent(' ') - ->setLineEnding("\n") +return (new PhpCsFixer\Config()) + ->setIndent(' ') + ->setLineEnding("\n") ->setRules([ - 'header_comment' => [ - 'comment_type' => 'PHPDoc', - 'header' => $header, - ], - 'align_multiline_comment' => true, - 'array_indentation' => true, - 'array_syntax' => ['syntax' => 'short'], - 'binary_operator_spaces' => true, - 'blank_line_after_namespace' => true, - 'blank_line_after_opening_tag' => true, - 'blank_line_before_return' => true, - 'blank_line_before_statement' => true, - 'braces' => true, - 'cast_spaces' => true, - 'class_attributes_separation' => true, - 'class_definition' => true, - 'compact_nullable_typehint' => true, - 'concat_space' => true, - 'declare_strict_types' => true, - 'elseif' => true, - 'encoding' => true, - 'escape_implicit_backslashes' => true, - 'explicit_indirect_variable' => true, - 'explicit_string_variable' => true, - 'final_internal_class' => true, - 'fully_qualified_strict_types' => true, - 'full_opening_tag' => true, - 'function_declaration' => true, - 'function_typehint_space' => true, - 'hash_to_slash_comment' => true, - 'implode_call' => true, - 'include' => true, - 'increment_style' => true, - 'indentation_type' => true, - 'is_null' => true, - 'line_ending' => true, - 'linebreak_after_opening_tag' => true, - 'list_syntax' => ['syntax' => 'short'], - 'logical_operators' => true, - 'lowercase_cast' => true, - 'lowercase_constants' => true, - 'lowercase_keywords' => true, - 'lowercase_static_reference' => true, - 'magic_constant_casing' => true, - 'magic_method_casing' => true, - 'method_argument_space' => true, - 'method_chaining_indentation' => true, - 'modernize_types_casting' => true, - 'multiline_comment_opening_closing' => true, - 'multiline_whitespace_before_semicolons' => true, - 'native_constant_invocation' => true, - 'native_function_casing' => true, - 'new_with_braces' => true, - 'no_alternative_syntax' => true, - 'no_binary_string' => true, - 'no_blank_lines_after_class_opening' => true, - 'no_blank_lines_after_phpdoc' => true, - 'no_blank_lines_before_namespace' => true, - 'no_break_comment' => true, - 'no_closing_tag' => true, - 'no_empty_comment' => true, - 'no_empty_phpdoc' => true, - 'no_empty_statement' => true, - 'no_extra_blank_lines' => true, - 'no_leading_import_slash' => true, - 'no_leading_namespace_whitespace' => true, - 'no_mixed_echo_print' => true, - 'no_multiline_whitespace_around_double_arrow' => true, - 'no_multiline_whitespace_before_semicolons' => true, - 'no_short_bool_cast' => true, - 'no_short_echo_tag' => true, - 'no_singleline_whitespace_before_semicolons' => true, - 'no_spaces_around_offset' => true, - 'no_spaces_inside_parenthesis' => true, - 'no_superfluous_elseif' => true, - 'no_superfluous_phpdoc_tags' => true, - 'no_trailing_comma_in_list_call' => true, - 'no_trailing_comma_in_singleline_array' => true, - 'no_trailing_whitespace' => true, - 'no_trailing_whitespace_in_comment' => true, - 'no_unneeded_control_parentheses' => true, - 'no_unneeded_curly_braces' => true, - 'no_unneeded_final_method' => true, - 'no_unreachable_default_argument_value' => true, - 'no_unset_on_property' => true, - 'no_unused_imports' => true, - 'no_useless_else' => true, - 'no_useless_return' => true, - 'no_whitespace_before_comma_in_array' => true, - 'no_whitespace_in_blank_line' => true, - 'non_printable_character' => true, - 'normalize_index_brace' => true, - 'not_operator_with_successor_space' => true, - 'object_operator_without_whitespace' => true, - 'ordered_class_elements' => true, - 'ordered_imports' => true, - 'php_unit_construct' => true, - 'phpdoc_add_missing_param_annotation' => true, - 'phpdoc_align' => true, - 'phpdoc_indent' => true, - 'phpdoc_inline_tag' => true, - 'phpdoc_no_access' => true, - 'phpdoc_no_package' => true, - 'phpdoc_order' => true, - 'phpdoc_return_self_reference' => true, - 'phpdoc_scalar' => true, - 'phpdoc_separation' => true, - 'phpdoc_single_line_var_spacing' => true, - 'phpdoc_to_return_type' => true, - 'phpdoc_trim' => true, - 'phpdoc_types' => true, - 'return_assignment' => true, - 'return_type_declaration' => true, - 'self_accessor' => true, - 'semicolon_after_instruction' => true, - 'set_type_to_cast' => true, - 'short_scalar_cast' => true, - 'simplified_null_return' => true, - 'single_blank_line_at_eof' => true, - 'single_class_element_per_statement' => true, - 'single_import_per_statement' => true, - 'single_line_after_imports' => true, - 'single_quote' => true, - 'space_after_semicolon' => true, - 'standardize_increment' => true, - 'standardize_not_equals' => true, - 'static_lambda' => true, - 'strict_comparison' => true, - 'strict_param' => true, - 'string_line_ending' => true, - 'switch_case_semicolon_to_colon' => true, - 'switch_case_space' => true, - 'ternary_operator_spaces' => true, - 'ternary_to_null_coalescing' => true, - 'trailing_comma_in_multiline_array' => true, - 'trim_array_spaces' => true, - 'unary_operator_spaces' => true, - 'visibility_required' => true, - 'void_return' => true, - 'whitespace_after_comma_in_array' => true, + '@PSR12' => true, + 'header_comment' => [ + 'comment_type' => 'PHPDoc', + 'header' => $header, + ], ]) ->setFinder($finder); diff --git a/demo.php b/demo.php index a87aead..95c458e 100755 --- a/demo.php +++ b/demo.php @@ -11,7 +11,7 @@ use PhpParser\ParserFactory; -require __DIR__.'/vendor/autoload.php'; +require __DIR__ . '/vendor/autoload.php'; $graphviz = false; list($fileName, $code) = getCode($argc, $argv); diff --git a/lib/PHPCfg/Assertion.php b/lib/PHPCfg/Assertion.php index bd0c20e..e661280 100644 --- a/lib/PHPCfg/Assertion.php +++ b/lib/PHPCfg/Assertion.php @@ -13,11 +13,11 @@ class Assertion { - const MODE_NONE = 0; + public const MODE_NONE = 0; - const MODE_UNION = 1; + public const MODE_UNION = 1; - const MODE_INTERSECTION = 2; + public const MODE_INTERSECTION = 2; public $mode = self::MODE_NONE; diff --git a/lib/PHPCfg/AstVisitor/LoopResolver.php b/lib/PHPCfg/AstVisitor/LoopResolver.php index f5a7538..c37b3e9 100755 --- a/lib/PHPCfg/AstVisitor/LoopResolver.php +++ b/lib/PHPCfg/AstVisitor/LoopResolver.php @@ -74,7 +74,7 @@ protected function resolveStack(Node $node, array $stack) if ($node->num instanceof LNumber) { $num = $node->num->value - 1; if ($num >= count($stack)) { - throw new \LogicException('Too high of a count for '.$node->getType()); + throw new \LogicException('Too high of a count for ' . $node->getType()); } $loc = array_slice($stack, -1 * $num, 1); @@ -86,6 +86,6 @@ protected function resolveStack(Node $node, array $stack) protected function makeLabel() { - return 'compiled_label_'.mt_rand(0, mt_getrandmax()).'_'.self::$labelCounter++; + return 'compiled_label_' . mt_rand(0, mt_getrandmax()) . '_' . self::$labelCounter++; } } diff --git a/lib/PHPCfg/AstVisitor/MagicStringResolver.php b/lib/PHPCfg/AstVisitor/MagicStringResolver.php index be1617a..f48b774 100644 --- a/lib/PHPCfg/AstVisitor/MagicStringResolver.php +++ b/lib/PHPCfg/AstVisitor/MagicStringResolver.php @@ -41,7 +41,7 @@ public function enterNode(Node $node) if ($node instanceof Node\Stmt\Function_) { $this->functionStack[] = $node->namespacedName->toString(); } elseif ($node instanceof Node\Stmt\ClassMethod) { - $this->methodStack[] = end($this->classStack).'::'.$node->name; + $this->methodStack[] = end($this->classStack) . '::' . $node->name; } elseif ($node instanceof Node\Name) { switch (strtolower($node->toString())) { case 'self': @@ -91,7 +91,7 @@ public function leaveNode(Node $node) assert(end($this->functionStack) === $node->namespacedName->toString()); array_pop($this->functionStack); } elseif ($node instanceof Node\Stmt\ClassMethod) { - assert(end($this->methodStack) === end($this->classStack).'::'.$node->name); + assert(end($this->methodStack) === end($this->classStack) . '::' . $node->name); array_pop($this->methodStack); } } @@ -117,12 +117,12 @@ function ($match) { $type = $match[2]; $type = preg_replace('((?<=^|\|)((?i:self)|\$this)(?=\[|$|\|))', end($this->classStack), $type); - return '@'.$match[1].' '.$type; + return '@' . $match[1] . ' ' . $type; }, - $comment->getText() + $comment->getText(), ), $comment->getLine(), - $comment->getFilePos() + $comment->getFilePos(), ); $node->setDocComment($comment); diff --git a/lib/PHPCfg/AstVisitor/NameResolver.php b/lib/PHPCfg/AstVisitor/NameResolver.php index 91c7e81..6c15f59 100644 --- a/lib/PHPCfg/AstVisitor/NameResolver.php +++ b/lib/PHPCfg/AstVisitor/NameResolver.php @@ -42,19 +42,19 @@ class NameResolver extends NameResolverParent 'resource', 'callable', ]; - + protected $anonymousClasses = 0; public function enterNode(Node $node) { parent::enterNode($node); - + if ($node instanceof Node\Stmt\Class_ && is_null($node->name)) { - $anonymousName = "{anonymousClass}#".++$this->anonymousClasses; + $anonymousName = "{anonymousClass}#" . ++$this->anonymousClasses; $node->name = new \PhpParser\Node\Identifier($anonymousName); $node->namespacedName = new \PhpParser\Node\Name($anonymousName); } - + $comment = $node->getDocComment(); if ($comment) { $regex = '(@(param|return|var|type)\\h+(\\S+))'; @@ -67,10 +67,10 @@ function ($match) { return "@{$match[1]} {$type}"; }, - $comment->getText() + $comment->getText(), ), $comment->getStartLine(), - $comment->getStartFilePos() + $comment->getStartFilePos(), ); $node->setDocComment($comment); @@ -86,10 +86,10 @@ protected function parseTypeDecl($type) return implode('&', array_map([$this, 'parseTypeDecl'], explode('&', $type))); } if (substr($type, 0, 1) === '?') { - return '?'.$this->parseTypeDecl(substr($type, 1)); + return '?' . $this->parseTypeDecl(substr($type, 1)); } if (substr($type, -2) === '[]') { - return $this->parseTypeDecl(substr($type, 0, -2)).'[]'; + return $this->parseTypeDecl(substr($type, 0, -2)) . '[]'; } if (substr($type, 0, 1) === '$') { // Variables aren't types diff --git a/lib/PHPCfg/Func.php b/lib/PHPCfg/Func.php index 17e9d7b..29a6357 100755 --- a/lib/PHPCfg/Func.php +++ b/lib/PHPCfg/Func.php @@ -17,21 +17,21 @@ class Func extends Op { /* Constants for the $flags property. * The first six flags match PhpParser Class_ flags. */ - const FLAG_PUBLIC = 0x01; + public const FLAG_PUBLIC = 0x01; - const FLAG_PROTECTED = 0x02; + public const FLAG_PROTECTED = 0x02; - const FLAG_PRIVATE = 0x04; + public const FLAG_PRIVATE = 0x04; - const FLAG_STATIC = 0x08; + public const FLAG_STATIC = 0x08; - const FLAG_ABSTRACT = 0x10; + public const FLAG_ABSTRACT = 0x10; - const FLAG_FINAL = 0x20; + public const FLAG_FINAL = 0x20; - const FLAG_RETURNS_REF = 0x40; + public const FLAG_RETURNS_REF = 0x40; - const FLAG_CLOSURE = 0x80; + public const FLAG_CLOSURE = 0x80; /** @var string */ public $name; @@ -68,7 +68,7 @@ public function __construct(string $name, int $flags, Op\Type $returnType, ?Oper public function getScopedName() { if (null !== $this->class) { - return $this->class->value.'::'.$this->name; + return $this->class->value . '::' . $this->name; } return $this->name; diff --git a/lib/PHPCfg/Op.php b/lib/PHPCfg/Op.php index 85c2ca0..8a2df26 100755 --- a/lib/PHPCfg/Op.php +++ b/lib/PHPCfg/Op.php @@ -61,11 +61,13 @@ public function getAttributes(): array return $this->attributes; } - public function getVariableNames(): array { + public function getVariableNames(): array + { return []; } - public function getSubBlocks(): array { + public function getSubBlocks(): array + { return []; } @@ -84,7 +86,8 @@ protected function addReadRefs(Operand ...$op): array return $result; } - protected function addReadRef(Operand $op): Operand { + protected function addReadRef(Operand $op): Operand + { return $op->addUsage($this); } diff --git a/lib/PHPCfg/Op/Expr.php b/lib/PHPCfg/Op/Expr.php index da6b108..11810e7 100755 --- a/lib/PHPCfg/Op/Expr.php +++ b/lib/PHPCfg/Op/Expr.php @@ -17,7 +17,6 @@ abstract class Expr extends Op { - public Operand $result; protected array $writeVariables = ['result']; diff --git a/lib/PHPCfg/Op/Expr/ArrayDimFetch.php b/lib/PHPCfg/Op/Expr/ArrayDimFetch.php index 14f6537..2b75673 100755 --- a/lib/PHPCfg/Op/Expr/ArrayDimFetch.php +++ b/lib/PHPCfg/Op/Expr/ArrayDimFetch.php @@ -29,7 +29,7 @@ public function __construct(Operand $var, ?Operand $dim = null, array $attribute } else { $this->dim = null; } - + } public function getVariableNames(): array diff --git a/lib/PHPCfg/Op/Expr/Closure.php b/lib/PHPCfg/Op/Expr/Closure.php index b8d04ff..2761e5e 100755 --- a/lib/PHPCfg/Op/Expr/Closure.php +++ b/lib/PHPCfg/Op/Expr/Closure.php @@ -33,7 +33,8 @@ public function getVariableNames(): array return ['useVars', 'result']; } - public function getFunc(): Func { + public function getFunc(): Func + { return $this->func; } } diff --git a/lib/PHPCfg/Op/Expr/Include_.php b/lib/PHPCfg/Op/Expr/Include_.php index 8f40866..154ceff 100755 --- a/lib/PHPCfg/Op/Expr/Include_.php +++ b/lib/PHPCfg/Op/Expr/Include_.php @@ -16,13 +16,13 @@ class Include_ extends Expr { - const TYPE_INCLUDE = 1; + public const TYPE_INCLUDE = 1; - const TYPE_INCLUDE_ONCE = 2; + public const TYPE_INCLUDE_ONCE = 2; - const TYPE_REQUIRE = 3; + public const TYPE_REQUIRE = 3; - const TYPE_REQUIRE_ONCE = 4; + public const TYPE_REQUIRE_ONCE = 4; public int $type; diff --git a/lib/PHPCfg/Op/Expr/Param.php b/lib/PHPCfg/Op/Expr/Param.php index ac2149c..e30e951 100755 --- a/lib/PHPCfg/Op/Expr/Param.php +++ b/lib/PHPCfg/Op/Expr/Param.php @@ -12,7 +12,6 @@ namespace PHPCfg\Op\Expr; use PHPCfg\Block; - use PHPCfg\Op; use PHPCfg\Op\Expr; use PhpCfg\Operand; @@ -24,7 +23,7 @@ class Param extends Expr public bool $byRef; public bool $variadic; - + public array $attrGroups; public ?Operand $defaultVar = null; @@ -37,14 +36,14 @@ class Param extends Expr public $function; public function __construct( - Operand $name, - Op\Type $type, - bool $byRef, - bool $variadic, + Operand $name, + Op\Type $type, + bool $byRef, + bool $variadic, array $attrGroups, - ?Operand $defaultVar = null, - ?Block $defaultBlock = null, - array $attributes = [] + ?Operand $defaultVar = null, + ?Block $defaultBlock = null, + array $attributes = [], ) { parent::__construct($attributes); $this->result->original = $name; diff --git a/lib/PHPCfg/Op/Stmt.php b/lib/PHPCfg/Op/Stmt.php index 6b09280..2ecfd37 100755 --- a/lib/PHPCfg/Op/Stmt.php +++ b/lib/PHPCfg/Op/Stmt.php @@ -15,5 +15,4 @@ abstract class Stmt extends Op { - } diff --git a/lib/PHPCfg/Op/Stmt/ClassMethod.php b/lib/PHPCfg/Op/Stmt/ClassMethod.php index c448141..40aa564 100644 --- a/lib/PHPCfg/Op/Stmt/ClassMethod.php +++ b/lib/PHPCfg/Op/Stmt/ClassMethod.php @@ -32,33 +32,33 @@ public function __construct(Func $func, int $visiblity, bool $static, bool $fina $this->final = $final; $this->abstract = $abstract; } - - public function isPublic() : bool + + public function isPublic(): bool { return (bool) ($this->visibility & Node\Stmt\Class_::MODIFIER_PUBLIC); } - public function isProtected() : bool + public function isProtected(): bool { return (bool) ($this->visibility & Node\Stmt\Class_::MODIFIER_PROTECTED); } - public function isPrivate() : bool + public function isPrivate(): bool { return (bool) ($this->visibility & Node\Stmt\Class_::MODIFIER_PRIVATE); } - public function isAbstract() : bool + public function isAbstract(): bool { return $this->abstract; } - public function isFinal() : bool + public function isFinal(): bool { return $this->final; } - public function isStatic() : bool + public function isStatic(): bool { return $this->static; } diff --git a/lib/PHPCfg/Op/Stmt/Property.php b/lib/PHPCfg/Op/Stmt/Property.php index 623ebff..6063d17 100755 --- a/lib/PHPCfg/Op/Stmt/Property.php +++ b/lib/PHPCfg/Op/Stmt/Property.php @@ -26,7 +26,7 @@ class Property extends Stmt public bool $static; public bool $readonly; - + public array $attrGroups; public ?Operand $defaultVar = null; @@ -50,27 +50,27 @@ public function __construct(Operand $name, int $visiblity, bool $static, bool $r $this->defaultBlock = $defaultBlock; } - public function isPublic() : bool + public function isPublic(): bool { return (bool) ($this->visibility & Node\Stmt\Class_::MODIFIER_PUBLIC); } - public function isProtected() : bool + public function isProtected(): bool { return (bool) ($this->visibility & Node\Stmt\Class_::MODIFIER_PROTECTED); } - public function isPrivate() : bool + public function isPrivate(): bool { return (bool) ($this->visibility & Node\Stmt\Class_::MODIFIER_PRIVATE); } - public function isStatic() : bool + public function isStatic(): bool { return $this->static; } - public function isReadonly() : bool + public function isReadonly(): bool { return $this->readonly; } diff --git a/lib/PHPCfg/Op/Stmt/TraitUse.php b/lib/PHPCfg/Op/Stmt/TraitUse.php index 266bd91..68520fe 100644 --- a/lib/PHPCfg/Op/Stmt/TraitUse.php +++ b/lib/PHPCfg/Op/Stmt/TraitUse.php @@ -15,7 +15,7 @@ use PhpCfg\Operand; use PHPCfg\TraitUseAdaptation; -class TraitUse extends Stmt +class TraitUse extends Stmt { /** * @var Operand[] @@ -27,10 +27,10 @@ class TraitUse extends Stmt */ public array $adaptations; - public function __construct(array $traits,array $adaptations, array $attributes = []) + public function __construct(array $traits, array $adaptations, array $attributes = []) { parent::__construct($attributes); $this->traits = $traits; $this->adaptations = $adaptations; } -} \ No newline at end of file +} diff --git a/lib/PHPCfg/Op/Terminal.php b/lib/PHPCfg/Op/Terminal.php index 1a79dac..8aba487 100755 --- a/lib/PHPCfg/Op/Terminal.php +++ b/lib/PHPCfg/Op/Terminal.php @@ -15,5 +15,4 @@ abstract class Terminal extends Op { - } diff --git a/lib/PHPCfg/Op/Terminal/Const_.php b/lib/PHPCfg/Op/Terminal/Const_.php index 300538c..01f46ac 100755 --- a/lib/PHPCfg/Op/Terminal/Const_.php +++ b/lib/PHPCfg/Op/Terminal/Const_.php @@ -17,7 +17,6 @@ class Const_ extends Terminal { - public Operand $name; public Operand $value; diff --git a/lib/PHPCfg/Op/Terminal/GlobalVar.php b/lib/PHPCfg/Op/Terminal/GlobalVar.php index 527e0a5..b5f671b 100755 --- a/lib/PHPCfg/Op/Terminal/GlobalVar.php +++ b/lib/PHPCfg/Op/Terminal/GlobalVar.php @@ -28,5 +28,5 @@ public function getVariableNames(): array { return ['var']; } - + } diff --git a/lib/PHPCfg/Op/TraitUseAdaptation.php b/lib/PHPCfg/Op/TraitUseAdaptation.php index 3886e31..6933c0c 100644 --- a/lib/PHPCfg/Op/TraitUseAdaptation.php +++ b/lib/PHPCfg/Op/TraitUseAdaptation.php @@ -21,10 +21,10 @@ abstract class TraitUseAdaptation extends Op public Operand $method; - public function __construct(?Operand $trait,Operand $method,array $attributes = []) + public function __construct(?Operand $trait, Operand $method, array $attributes = []) { parent::__construct($attributes); $this->trait = $trait; - $this->method = $method; + $this->method = $method; } -} \ No newline at end of file +} diff --git a/lib/PHPCfg/Op/TraitUseAdaptation/Alias.php b/lib/PHPCfg/Op/TraitUseAdaptation/Alias.php index 2bd617d..13ca265 100644 --- a/lib/PHPCfg/Op/TraitUseAdaptation/Alias.php +++ b/lib/PHPCfg/Op/TraitUseAdaptation/Alias.php @@ -15,31 +15,31 @@ use PHPCfg\Operand; use PHPCfg\Op\TraitUseAdaptation; -class Alias extends TraitUseAdaptation +class Alias extends TraitUseAdaptation { public ?Operand $newName; public ?int $newModifier; - public function __construct(?Operand $trait,Operand $method,?Operand $newName,?int $newModifier,array $attributes = []) + public function __construct(?Operand $trait, Operand $method, ?Operand $newName, ?int $newModifier, array $attributes = []) { - parent::__construct($trait,$method,$attributes); + parent::__construct($trait, $method, $attributes); $this->newName = $newName; $this->newModifier = $newModifier; } - public function isPublic() : bool + public function isPublic(): bool { return (bool) ($this->newModifier & Node\Stmt\Class_::MODIFIER_PUBLIC); } - public function isProtected() : bool + public function isProtected(): bool { return (bool) ($this->newModifier & Node\Stmt\Class_::MODIFIER_PROTECTED); } - public function isPrivate() : bool + public function isPrivate(): bool { return (bool) ($this->newModifier & Node\Stmt\Class_::MODIFIER_PRIVATE); } -} \ No newline at end of file +} diff --git a/lib/PHPCfg/Op/TraitUseAdaptation/Precedence.php b/lib/PHPCfg/Op/TraitUseAdaptation/Precedence.php index a0acb8c..d0733c6 100644 --- a/lib/PHPCfg/Op/TraitUseAdaptation/Precedence.php +++ b/lib/PHPCfg/Op/TraitUseAdaptation/Precedence.php @@ -18,9 +18,9 @@ class Precedence extends TraitUseAdaptation { public array $insteadof; - public function __construct(?Operand $trait,Operand $method,array $insteadof,array $attributes = []) + public function __construct(?Operand $trait, Operand $method, array $insteadof, array $attributes = []) { - parent::__construct($trait,$method,$attributes); + parent::__construct($trait, $method, $attributes); $this->insteadof = $insteadof; } -} \ No newline at end of file +} diff --git a/lib/PHPCfg/Op/Type.php b/lib/PHPCfg/Op/Type.php index 94d14d7..fa68663 100755 --- a/lib/PHPCfg/Op/Type.php +++ b/lib/PHPCfg/Op/Type.php @@ -1,19 +1,19 @@ -name = $name; - } - -} \ No newline at end of file +name = $name; + } + +} diff --git a/lib/PHPCfg/Op/Type/Mixed_.php b/lib/PHPCfg/Op/Type/Mixed_.php index b61b33e..f42a3e1 100755 --- a/lib/PHPCfg/Op/Type/Mixed_.php +++ b/lib/PHPCfg/Op/Type/Mixed_.php @@ -1,19 +1,19 @@ -subtype = $subtype; - } - - public function getVariableNames(): array - { - return ['subtype']; - } - -} \ No newline at end of file +subtype = $subtype; + } + + public function getVariableNames(): array + { + return ['subtype']; + } + +} diff --git a/lib/PHPCfg/Op/Type/Reference.php b/lib/PHPCfg/Op/Type/Reference.php index 27835a4..b3ab937 100755 --- a/lib/PHPCfg/Op/Type/Reference.php +++ b/lib/PHPCfg/Op/Type/Reference.php @@ -1,31 +1,32 @@ -declaration = $declaration; - } - - public function getVariableNames(): array - { - return ['declaration']; - } - -} \ No newline at end of file +declaration = $declaration; + } + + public function getVariableNames(): array + { + return ['declaration']; + } + +} diff --git a/lib/PHPCfg/Op/Type/Union.php b/lib/PHPCfg/Op/Type/Union.php index 17ffe86..b0c3463 100644 --- a/lib/PHPCfg/Op/Type/Union.php +++ b/lib/PHPCfg/Op/Type/Union.php @@ -18,7 +18,8 @@ class Union extends Type { public array $subtypes; - public function __construct(array $subtypes, array $attributes = []) { + public function __construct(array $subtypes, array $attributes = []) + { $this->subtypes = $subtypes; } @@ -26,4 +27,4 @@ public function getVariableNames(): array { return ['subtypes']; } -} +} diff --git a/lib/PHPCfg/Op/Type/Void_.php b/lib/PHPCfg/Op/Type/Void_.php index 667a8fa..137b3ad 100755 --- a/lib/PHPCfg/Op/Type/Void_.php +++ b/lib/PHPCfg/Op/Type/Void_.php @@ -1,19 +1,19 @@ -assertions[$key]['assertion'] = new Assertion( [$orig['assertion'], $assert], - $mode + $mode, ); return; @@ -88,7 +88,7 @@ public function addAssertion(self $op, Assertion $assert, $mode = Assertion::MOD // merge $this->assertions[$key]['assertion'] = new Assertion( [$orig['assertion'], $assert], - $mode + $mode, ); return; diff --git a/lib/PHPCfg/Operand/BoundVariable.php b/lib/PHPCfg/Operand/BoundVariable.php index 23cb752..c4b1b17 100644 --- a/lib/PHPCfg/Operand/BoundVariable.php +++ b/lib/PHPCfg/Operand/BoundVariable.php @@ -13,13 +13,13 @@ class BoundVariable extends Variable { - const SCOPE_GLOBAL = 1; + public const SCOPE_GLOBAL = 1; - const SCOPE_LOCAL = 2; + public const SCOPE_LOCAL = 2; - const SCOPE_OBJECT = 3; + public const SCOPE_OBJECT = 3; - const SCOPE_FUNCTION = 4; + public const SCOPE_FUNCTION = 4; public $byRef; diff --git a/lib/PHPCfg/Operand/NullOperand.php b/lib/PHPCfg/Operand/NullOperand.php index ce0a24b..e9a9fa7 100755 --- a/lib/PHPCfg/Operand/NullOperand.php +++ b/lib/PHPCfg/Operand/NullOperand.php @@ -1,21 +1,21 @@ -script = $script = new Script(); $script->functions = []; - $script->main = new Func('{main}', 0, new Op\Type\Void_, null); + $script->main = new Func('{main}', 0, new Op\Type\Void_(), null); $this->parseFunc($script->main, [], $ast); // Reset script specific state @@ -129,13 +129,13 @@ protected function parseFunc(Func $func, array $params, array $stmts) $this->writeVariableName($param->name->value, $param->result, $start); $start->children[] = $param; } - + $this->block = $tmp; $end = $this->parseNodes($stmts, $start); if (!$end->dead) { - $end->children[] = new Return_; + $end->children[] = new Return_(); } if ($this->ctx->unresolvedGotos) { @@ -170,30 +170,30 @@ protected function parseNode(Node $node) } $type = $node->getType(); - if (method_exists($this, 'parse'.$type)) { - $this->{'parse'.$type}($node); + if (method_exists($this, 'parse' . $type)) { + $this->{'parse' . $type}($node); return; } - throw new \RuntimeException('Unknown Node Encountered : '.$type); + throw new \RuntimeException('Unknown Node Encountered : ' . $type); } protected function parseTypeNode(?Node $node): Op\Type { if (is_null($node)) { - return new Op\Type\Mixed_; + return new Op\Type\Mixed_(); } if ($node instanceof Node\Name) { return new Op\Type\Reference( $this->readVariable($this->parseExprNode($node)), - $this->mapAttributes($node) + $this->mapAttributes($node), ); } if ($node instanceof Node\NullableType) { return new Op\Type\Nullable( $this->parseTypeNode($node->type), - $this->mapAttributes($node) + $this->mapAttributes($node), ); } if ($node instanceof Node\UnionType) { @@ -201,16 +201,16 @@ protected function parseTypeNode(?Node $node): Op\Type foreach ($node->types as $type) { $parsedTypes[] = $this->parseTypeNode($type); } - + return new Op\Type\Union( $parsedTypes, - $this->mapAttributes($node) + $this->mapAttributes($node), ); } if ($node instanceof Node\Identifier) { return new Op\Type\Literal( $node->name, - $this->mapAttributes($node) + $this->mapAttributes($node), ); } throw new \LogicException("Unknown type node: " . $node->getType()); @@ -233,7 +233,7 @@ protected function parseStmt_Class(Stmt\Class_ $node) $this->parseExprList($node->implements), $this->parseNodes($node->stmts, new Block()), $this->parseAttributeGroups($node->attrGroups), - $this->mapAttributes($node) + $this->mapAttributes($node), ); $this->currentClass = $old; } @@ -253,7 +253,7 @@ protected function parseStmt_ClassConst(Stmt\ClassConst $node) $this->parseExprNode($const->name), $value, $valueBlock, - $this->mapAttributes($node) + $this->mapAttributes($node), ); } } @@ -268,7 +268,7 @@ protected function parseStmt_ClassMethod(Stmt\ClassMethod $node) $node->name->toString(), $node->flags | ($node->byRef ? Func::FLAG_RETURNS_REF : 0), $this->parseTypeNode($node->returnType), - $this->currentClass + $this->currentClass, ); if ($node->stmts !== null) { @@ -290,7 +290,7 @@ protected function parseStmt_ClassMethod(Stmt\ClassMethod $node) (bool) $final, (bool) $abstract, $this->parseAttributeGroups($node->attrGroups), - $this->mapAttributes($node) + $this->mapAttributes($node), ); $func->callableOp = $class_method; } @@ -307,7 +307,7 @@ protected function parseStmt_Const(Stmt\Const_ $node) $this->parseExprNode($const->namespacedName), $value, $valueBlock, - $this->mapAttributes($node) + $this->mapAttributes($node), ); } } @@ -340,7 +340,7 @@ protected function parseStmt_Echo(Stmt\Echo_ $node) foreach ($node->exprs as $expr) { $this->block->children[] = new Op\Terminal\Echo_( $this->readVariable($this->parseExprNode($expr)), - $this->mapAttributes($expr) + $this->mapAttributes($expr), ); } } @@ -434,7 +434,7 @@ protected function parseStmt_Global(Stmt\Global_ $node) // TODO $var is not necessarily a Variable node $this->block->children[] = new Op\Terminal\GlobalVar( $this->writeVariable($this->parseExprNode($var->name)), - $this->mapAttributes($node) + $this->mapAttributes($node), ); } } @@ -452,17 +452,17 @@ protected function parseStmt_Goto(Stmt\Goto_ $node) $this->block = new Block(); $this->block->dead = true; } - + protected function parseStmt_GroupUse(Stmt\GroupUse $node) { // ignore use statements, since names are already resolved } - + protected function parseStmt_HaltCompiler(Stmt\HaltCompiler $node) { $this->block->children[] = new Op\Terminal\Echo_( $this->readVariable(new Operand\Literal($node->remaining)), - $this->mapAttributes($node) + $this->mapAttributes($node), ); } @@ -519,7 +519,7 @@ protected function parseStmt_Interface(Stmt\Interface_ $node) $name, $this->parseExprList($node->extends), $this->parseNodes($node->stmts, new Block()), - $this->mapAttributes($node) + $this->mapAttributes($node), ); $this->currentClass = $old; } @@ -584,7 +584,7 @@ protected function parseStmt_Property(Stmt\Property $node) $this->parseTypeNode($node->type), $defaultVar, $defaultBlock, - $this->mapAttributes($node) + $this->mapAttributes($node), ); } } @@ -616,7 +616,7 @@ protected function parseStmt_Static(Stmt\Static_ $node) $this->writeVariable(new Operand\BoundVariable($this->parseExprNode($var->var->name), true, Operand\BoundVariable::SCOPE_FUNCTION)), $defaultBlock, $defaultVar, - $this->mapAttributes($node) + $this->mapAttributes($node), ); } } @@ -647,7 +647,7 @@ protected function parseStmt_Switch(Stmt\Switch_ $node) $this->block->children[] = $cmp = new Op\Expr\BinaryOp\Equal( $this->readVariable($cond), $this->readVariable($caseExpr), - $this->mapAttributes($case) + $this->mapAttributes($case), ); $elseBlock = new Block(); @@ -676,7 +676,7 @@ protected function parseStmt_Throw(Stmt\Throw_ $node) { $this->block->children[] = new Op\Terminal\Throw_( $this->readVariable($this->parseExprNode($node->expr)), - $this->mapAttributes($node) + $this->mapAttributes($node), ); $this->block = new Block(); // dead code $this->block->dead = true; @@ -690,7 +690,7 @@ protected function parseStmt_Trait(Stmt\Trait_ $node) $this->block->children[] = new Op\Stmt\Trait_( $name, $this->parseNodes($node->stmts, new Block()), - $this->mapAttributes($node) + $this->mapAttributes($node), ); $this->currentClass = $old; } @@ -699,33 +699,32 @@ protected function parseStmt_TraitUse(Stmt\TraitUse $node) { $traits = []; $adaptations = []; - foreach($node->traits as $trait_) { - $traits[] = new Literal($trait_->toCodeString()); + foreach ($node->traits as $trait_) { + $traits[] = new Literal($trait_->toCodeString()); } - foreach($node->adaptations as $adaptation) { - if($adaptation instanceof Stmt\TraitUseAdaptation\Alias) { + foreach ($node->adaptations as $adaptation) { + if ($adaptation instanceof Stmt\TraitUseAdaptation\Alias) { $adaptations[] = new Alias( $adaptation->trait != null ? new Literal($adaptation->trait->toCodeString()) : null, new Literal($adaptation->method->name), $adaptation->newName != null ? new Literal($adaptation->newName->name) : null, $adaptation->newModifier, - $this->mapAttributes($adaptation) + $this->mapAttributes($adaptation), ); - } - else if($adaptation instanceof Stmt\TraitUseAdaptation\Precedence) { + } elseif ($adaptation instanceof Stmt\TraitUseAdaptation\Precedence) { $insteadofs = []; - foreach($adaptation->insteadof as $insteadof) { + foreach ($adaptation->insteadof as $insteadof) { $insteadofs[] = new Literal($insteadof->toCodeString()); } $adaptations[] = new Precedence( $adaptation->trait != null ? new Literal($adaptation->trait->toCodeString()) : null, new Literal($adaptation->method->name), $insteadofs, - $this->mapAttributes($adaptation) + $this->mapAttributes($adaptation), ); } } - $this->block->children[] = new TraitUse($traits,$adaptations,$this->mapAttributes($node)); + $this->block->children[] = new TraitUse($traits, $adaptations, $this->mapAttributes($node)); } protected function parseStmt_TryCatch(Stmt\TryCatch $node) @@ -737,7 +736,7 @@ protected function parseStmt_Unset(Stmt\Unset_ $node) { $this->block->children[] = new Op\Terminal\Unset_( $this->parseExprList($node->vars, self::MODE_WRITE), - $this->mapAttributes($node) + $this->mapAttributes($node), ); } @@ -807,7 +806,7 @@ protected function parseExprNode($expr) $this->parseExprNode($expr->name), false, Operand\BoundVariable::SCOPE_OBJECT, - $this->currentClass + $this->currentClass, ); } @@ -848,7 +847,7 @@ protected function parseExprNode($expr) 'Expr_AssignOp_ShiftRight' => Op\Expr\BinaryOp\ShiftRight::class, ][$expr->getType()]; if (empty($class)) { - throw new \RuntimeException('AssignOp Not Found: '.$expr->getType()); + throw new \RuntimeException('AssignOp Not Found: ' . $expr->getType()); } $attrs = $this->mapAttributes($expr); $this->block->children[] = $op = new $class($read, $e, $attrs); @@ -892,7 +891,7 @@ protected function parseExprNode($expr) 'Expr_BinaryOp_Spaceship' => Op\Expr\BinaryOp\Spaceship::class, ][$expr->getType()]; if (empty($class)) { - throw new \RuntimeException('BinaryOp Not Found: '.$expr->getType()); + throw new \RuntimeException('BinaryOp Not Found: ' . $expr->getType()); } $this->block->children[] = $op = new $class($left, $right, $this->mapAttributes($expr)); @@ -911,14 +910,14 @@ protected function parseExprNode($expr) ][$expr->getType()]; if (empty($class)) { - throw new \RuntimeException('Cast Not Found: '.$expr->getType()); + throw new \RuntimeException('Cast Not Found: ' . $expr->getType()); } $this->block->children[] = $op = new $class($e, $this->mapAttributes($expr)); return $op->result; } - $method = 'parse'.$expr->getType(); + $method = 'parse' . $expr->getType(); if (method_exists($this, $method)) { $op = $this->{$method}($expr); if ($op instanceof Op) { @@ -930,7 +929,7 @@ protected function parseExprNode($expr) return $op; } } else { - throw new \RuntimeException('Unknown Expr Type '.$expr->getType()); + throw new \RuntimeException('Unknown Expr Type ' . $expr->getType()); } throw new \RuntimeException('Invalid state, should never happen'); @@ -951,7 +950,7 @@ protected function parseAttribute(Node\Attribute $attr) protected function parseAttributeGroup(Node\AttributeGroup $attrGroup) { $attrs = array_map([$this, 'parseAttribute'], $attrGroup->attrs); - + return new Op\Attributes\AttributeGroup($attrs, $this->mapAttributes($attrGroup)); } @@ -970,7 +969,7 @@ protected function parseExpr_Array(Expr\Array_ $expr) if ($item->key) { $keys[] = $this->readVariable($this->parseExprNode($item->key)); } else { - $keys[] = new Operand\NullOperand; + $keys[] = new Operand\NullOperand(); } $values[] = $this->readVariable($this->parseExprNode($item->value)); $byRef[] = $item->byRef; @@ -986,7 +985,7 @@ protected function parseExpr_ArrayDimFetch(Expr\ArrayDimFetch $expr) if (null !== $expr->dim) { $d = $this->readVariable($this->parseExprNode($expr->dim)); } else { - $d = new Operand\NullOperand; + $d = new Operand\NullOperand(); } return new Op\Expr\ArrayDimFetch($v, $d, $this->mapAttributes($expr)); @@ -1017,7 +1016,7 @@ protected function parseExpr_BitwiseNot(Expr\BitwiseNot $expr) { return new Op\Expr\BitwiseNot( $this->readVariable($this->parseExprNode($expr->expr)), - $this->mapAttributes($expr) + $this->mapAttributes($expr), ); } @@ -1039,7 +1038,7 @@ protected function parseExpr_Closure(Expr\Closure $expr) $uses[] = new Operand\BoundVariable( $this->readVariable(new Literal($use->var->name)), $use->byRef, - Operand\BoundVariable::SCOPE_LOCAL + Operand\BoundVariable::SCOPE_LOCAL, ); } @@ -1048,10 +1047,10 @@ protected function parseExpr_Closure(Expr\Closure $expr) $flags |= $expr->static ? Func::FLAG_STATIC : 0; $this->script->functions[] = $func = new Func( - '{anonymous}#'.++$this->anonId, + '{anonymous}#' . ++$this->anonId, $flags, $this->parseTypeNode($expr->returnType), - null + null, ); $this->parseFunc($func, $expr->params, $expr->stmts, null); @@ -1146,7 +1145,7 @@ protected function parseExpr_FuncCall(Expr\FuncCall $expr) $name, $this->parseExprNode(Node\Name::concat($this->currentNamespace, $expr->name)), $args, - $this->mapAttributes($expr) + $this->mapAttributes($expr), ); } else { $op = new Op\Expr\FuncCall($name, $args, $this->mapAttributes($expr)); @@ -1173,7 +1172,7 @@ protected function parseExpr_FuncCall(Expr\FuncCall $expr) if (isset($assertionFunctions[$lname])) { $op->result->addAssertion( $args[0], - new Assertion\TypeAssertion(new Operand\Literal($assertionFunctions[$lname])) + new Assertion\TypeAssertion(new Operand\Literal($assertionFunctions[$lname])), ); } } @@ -1193,7 +1192,7 @@ protected function parseExpr_Instanceof(Expr\Instanceof_ $expr) $op = new Op\Expr\InstanceOf_( $var, $class, - $this->mapAttributes($expr) + $this->mapAttributes($expr), ); $op->result->addAssertion($var, new Assertion\TypeAssertion($class)); @@ -1204,7 +1203,7 @@ protected function parseExpr_Isset(Expr\Isset_ $expr) { return new Op\Expr\Isset_( $this->parseExprList($expr->vars, self::MODE_READ), - $this->mapAttributes($expr) + $this->mapAttributes($expr), ); } @@ -1237,7 +1236,7 @@ protected function parseListAssignment($expr, Operand $rhs) $assign = new Op\Expr\Assign( $this->writeVariable($this->parseExprNode($var)), $fetch->result, - $attributes + $attributes, ); $this->block->children[] = $assign; } @@ -1249,7 +1248,7 @@ protected function parseExpr_MethodCall(Expr\MethodCall $expr) $this->readVariable($this->parseExprNode($expr->var)), $this->readVariable($this->parseExprNode($expr->name)), $this->parseExprList($expr->args, self::MODE_READ), - $this->mapAttributes($expr) + $this->mapAttributes($expr), ); } @@ -1261,11 +1260,11 @@ protected function parseExpr_New(Expr\New_ $expr) } else { $classExpr = $expr->class; } - + return new Op\Expr\New_( $this->readVariable($this->parseExprNode($classExpr)), $this->parseExprList($expr->args, self::MODE_READ), - $this->mapAttributes($expr) + $this->mapAttributes($expr), ); } @@ -1323,7 +1322,7 @@ protected function parseExpr_PropertyFetch(Expr\PropertyFetch $expr) return new Op\Expr\PropertyFetch( $this->readVariable($this->parseExprNode($expr->var)), $this->readVariable($this->parseExprNode($expr->name)), - $this->mapAttributes($expr) + $this->mapAttributes($expr), ); } @@ -1333,7 +1332,7 @@ protected function parseExpr_StaticCall(Expr\StaticCall $expr) $this->readVariable($this->parseExprNode($expr->class)), $this->readVariable($this->parseExprNode($expr->name)), $this->parseExprList($expr->args, self::MODE_READ), - $this->mapAttributes($expr) + $this->mapAttributes($expr), ); } @@ -1342,7 +1341,7 @@ protected function parseExpr_StaticPropertyFetch(Expr\StaticPropertyFetch $expr) return new Op\Expr\StaticPropertyFetch( $this->readVariable($this->parseExprNode($expr->class)), $this->readVariable($this->parseExprNode($expr->name)), - $this->mapAttributes($expr) + $this->mapAttributes($expr), ); } @@ -1364,7 +1363,7 @@ protected function parseExpr_Ternary(Expr\Ternary $expr) $this->block->children[] = new Op\Expr\Assign( $ifVar, $this->readVariable($this->parseExprNode($expr->if)), - $attrs + $attrs, ); } else { $this->block->children[] = new Op\Expr\Assign($ifVar, $cond, $attrs); @@ -1377,7 +1376,7 @@ protected function parseExpr_Ternary(Expr\Ternary $expr) $this->block->children[] = new Op\Expr\Assign( $elseVar, $this->readVariable($this->parseExprNode($expr->else)), - $attrs + $attrs, ); $this->block->children[] = new Jump($endBlock, $attrs); $endBlock->addParent($this->block); @@ -1420,13 +1419,13 @@ protected function parseExpr_ShellExec(Expr\ShellExec $expr) { $this->block->children[] = $arg = new Op\Expr\ConcatList( $this->parseExprList($expr->parts, self::MODE_READ), - $this->mapAttributes($expr) + $this->mapAttributes($expr), ); return new Op\Expr\FuncCall( new Operand\Literal('shell_exec'), [$arg->result], - $this->mapAttributes($expr) + $this->mapAttributes($expr), ); } @@ -1438,13 +1437,13 @@ protected function processAssertions(Operand $op, Block $if, Block $else) array_unshift($this->block->children, new Op\Expr\Assertion( $this->readVariable($assert['var']), $this->writeVariable($assert['var']), - $this->readAssertion($assert['assertion']) + $this->readAssertion($assert['assertion']), )); $this->block = $else; array_unshift($this->block->children, new Op\Expr\Assertion( $this->readVariable($assert['var']), $this->writeVariable($assert['var']), - new Assertion\NegatedAssertion([$this->readAssertion($assert['assertion'])]) + new Assertion\NegatedAssertion([$this->readAssertion($assert['assertion'])]), )); } $this->block = $block; @@ -1514,7 +1513,7 @@ private function compileJumptableSwitch(Stmt\Switch_ $node) $cases, $targets, $defaultBlock, - $this->mapAttributes($node) + $this->mapAttributes($node), ); if ($block && ! $block->dead) { // wire end of block to endblock @@ -1553,7 +1552,7 @@ private function parseScalarNode(Node\Scalar $scalar) // TODO return new Literal('__FUNCTION__'); default: - throw new \RuntimeException('Unknown how to deal with scalar type '.$scalar->getType()); + throw new \RuntimeException('Unknown how to deal with scalar type ' . $scalar->getType()); } } @@ -1581,7 +1580,7 @@ private function parseParameterList(Func $func, array $params) $this->parseAttributeGroups($param->attrGroups), $defaultVar, $defaultBlock, - $this->mapAttributes($param) + $this->mapAttributes($param), ); $p->result->original = new Operand\Variable(new Operand\Literal($p->name->value)); $p->function = $func; @@ -1634,7 +1633,7 @@ private function mapAttributes(Node $expr) [ 'filename' => $this->fileName, ], - $expr->getAttributes() + $expr->getAttributes(), ); } diff --git a/lib/PHPCfg/Printer.php b/lib/PHPCfg/Printer.php index 82a5d7d..88e6c2e 100755 --- a/lib/PHPCfg/Printer.php +++ b/lib/PHPCfg/Printer.php @@ -57,7 +57,7 @@ protected function renderOperand(Operand $var) { $type = isset($var->type) ? 'type->toString() . '>' : ''; if ($var instanceof Literal) { - return "LITERAL{$type}(".var_export($var->value, true).')'; + return "LITERAL{$type}(" . var_export($var->value, true) . ')'; } if ($var instanceof Variable) { assert($var->name instanceof Literal); @@ -80,23 +80,23 @@ protected function renderOperand(Operand $var) } } - return $prefix.$var->name->value.$type; + return $prefix . $var->name->value . $type; } if ($var instanceof Temporary) { $id = $this->getVarId($var); if ($var->original) { - return "Var{$type}#{$id}".'<'.$this->renderOperand($var->original).'>'; + return "Var{$type}#{$id}" . '<' . $this->renderOperand($var->original) . '>'; } - return "Var{$type}#".$this->getVarId($var); + return "Var{$type}#" . $this->getVarId($var); } if ($var instanceof NullOperand) { return "NULL"; } if (is_array($var)) { - $result = 'array'.$type; + $result = 'array' . $type; foreach ($var as $k => $v) { - $result .= "\n {$k}: ".$this->indent($this->renderOperand($v)); + $result .= "\n {$k}: " . $this->indent($this->renderOperand($v)); } return $result; @@ -111,10 +111,10 @@ protected function renderOp(Op $op) if ($op instanceof Op\CallableOp) { $func = $op->getFunc(); - $result .= '<'.var_export($func->name, true).'>'; + $result .= '<' . var_export($func->name, true) . '>'; } if ($op instanceof Op\Expr\Assertion) { - $result .= '<'.$this->renderAssertion($op->assertion).'>'; + $result .= '<' . $this->renderAssertion($op->assertion) . '>'; } $result .= $this->renderAttributes($op->getAttributes()); @@ -128,42 +128,41 @@ protected function renderOp(Op $op) $result .= "\n flags: " . $this->indent($this->renderFlags($op)); $result .= "\n declaredType: " . $this->indent($this->renderType($op->declaredType)); } - if($op instanceof Op\Stmt\TraitUse) { - foreach($op->traits as $index => $trait_) { + if ($op instanceof Op\Stmt\TraitUse) { + foreach ($op->traits as $index => $trait_) { $result .= "\n use[$index]: " . $this->indent($this->renderOperand($trait_)); } - foreach($op->adaptations as $index => $adaptation) { - if($adaptation instanceof Op\TraitUseAdaptation\Alias) { + foreach ($op->adaptations as $index => $adaptation) { + if ($adaptation instanceof Op\TraitUseAdaptation\Alias) { $result .= "\n adaptation[$index]: Alias"; - if($adaptation->trait != null) { - $result .= "\n trait:".$this->indent($this->renderOperand($adaptation->trait)); + if ($adaptation->trait != null) { + $result .= "\n trait:" . $this->indent($this->renderOperand($adaptation->trait)); } - $result .= "\n method:".$this->indent($this->renderOperand($adaptation->method)); - if($adaptation->newName != null) { - $result .= "\n newName:".$this->indent($this->renderOperand($adaptation->newName)); + $result .= "\n method:" . $this->indent($this->renderOperand($adaptation->method)); + if ($adaptation->newName != null) { + $result .= "\n newName:" . $this->indent($this->renderOperand($adaptation->newName)); } - if($adaptation->newModifier != null) { + if ($adaptation->newModifier != null) { $result .= "\n newModifier:"; - if($adaptation->isPublic()) { + if ($adaptation->isPublic()) { $result .= "public"; } - if($adaptation->isPrivate()) { + if ($adaptation->isPrivate()) { $result .= "private"; } - if($adaptation->isProtected()) { + if ($adaptation->isProtected()) { $result .= "protected"; } } - } - else if($adaptation instanceof Op\TraitUseAdaptation\Precedence) { + } elseif ($adaptation instanceof Op\TraitUseAdaptation\Precedence) { $result .= "\n adaptation[$index]: Insteadof"; - if($adaptation->trait != null) { - $result .= "\n trait:".$this->indent($this->renderOperand($adaptation->trait)); + if ($adaptation->trait != null) { + $result .= "\n trait:" . $this->indent($this->renderOperand($adaptation->trait)); } - $result .= "\n method:".$this->indent($this->renderOperand($adaptation->method)); - foreach($adaptation->insteadof as $index2 => $insteadof) { + $result .= "\n method:" . $this->indent($this->renderOperand($adaptation->method)); + foreach ($adaptation->insteadof as $index2 => $insteadof) { $result .= "\n insteadof[$index2]: " . $this->indent($this->renderOperand($insteadof)); - } + } } } } @@ -205,7 +204,7 @@ protected function renderOp(Op $op) $this->enqueueBlock($subBlock); $childBlocks[] = [ 'block' => $subBlock, - 'name' => $blockName.'['.$key.']', + 'name' => $blockName . '[' . $key . ']', ]; } } elseif ($sub) { @@ -225,7 +224,7 @@ protected function renderAssertion(Assertion $assert) { $kind = $assert->getKind(); if ($assert->value instanceof Operand) { - return $kind.'('.$this->renderOperand($assert->value).')'; + return $kind . '(' . $this->renderOperand($assert->value) . ')'; } $combinator = $assert->mode === Assertion::MODE_UNION ? '|' : '&'; $results = []; @@ -233,7 +232,7 @@ protected function renderAssertion(Assertion $assert) $results[] = $this->renderAssertion($child); } - return $kind.'('.implode($combinator, $results).')'; + return $kind . '(' . implode($combinator, $results) . ')'; } protected function indent($str, $levels = 1) @@ -274,7 +273,7 @@ protected function render(Func $func) $block = $this->blockQueue->dequeue(); $ops = []; foreach ($block->phi as $phi) { - $result = $this->indent($this->renderOperand($phi->result).' = Phi('); + $result = $this->indent($this->renderOperand($phi->result) . ' = Phi('); $result .= implode(', ', array_map([$this, 'renderOperand'], $phi->vars)); $result .= ')'; $renderedOps[$phi] = $ops[] = [ @@ -319,7 +318,7 @@ protected function renderType(?Op\Type $type): string if ($i < count($type->subtypes)) { $strTypes .= "|"; } - $i ++; + $i++; } return $strTypes; } @@ -337,7 +336,7 @@ protected function renderType(?Op\Type $type): string protected function renderIncludeType(int $type): string { - switch($type) { + switch ($type) { case 1: return "include"; case 2: @@ -347,14 +346,14 @@ protected function renderIncludeType(int $type): string case 4: return "require_once"; default: - throw new \LogicException("Unknown include type rendering: " .$type); + throw new \LogicException("Unknown include type rendering: " . $type); } } protected function renderFlags(Op\Stmt $stmt): string { $result = ''; - + if ($stmt instanceof Op\Stmt\Property) { if ($stmt->isReadOnly()) { $result .= "readonly|"; @@ -371,7 +370,7 @@ protected function renderFlags(Op\Stmt $stmt): string if ($stmt->isStatic()) { $result .= "static|"; } - + if ($stmt->isProtected()) { $result .= "protected"; } elseif ($stmt->isPrivate()) { @@ -389,7 +388,7 @@ public function renderAttributes(array $attributes): string if ($this->renderAttributes) { foreach ($attributes as $key => $value) { if (is_string($value) || is_numeric($value)) { - $result .= "\n attribute['".$key."']: ".$value; + $result .= "\n attribute['" . $key . "']: " . $value; } } } @@ -400,16 +399,16 @@ public function renderAttributes(array $attributes): string public function renderAttrGroups(array $attrGroups): string { $result = ''; - - foreach($attrGroups as $indexGroup => $attrGroup) { + + foreach ($attrGroups as $indexGroup => $attrGroup) { $result .= "\n attrGroup[$indexGroup]: "; $result .= $this->indent($this->renderAttributes($attrGroup->getAttributes())); - foreach($attrGroup->attrs as $indexAttr => $attr) { + foreach ($attrGroup->attrs as $indexAttr => $attr) { $result .= "\n attr[$indexAttr]: "; $result .= $this->indent($this->renderAttributes($attr->getAttributes()), 2); - $result .= "\n name: ".$this->renderOperand($attr->name); - foreach($attr->args as $indexArg => $arg) { - $result .= "\n args[$indexArg]: ".$this->renderOperand($arg); + $result .= "\n name: " . $this->renderOperand($attr->name); + foreach ($attr->args as $indexArg => $arg) { + $result .= "\n args[$indexArg]: " . $this->renderOperand($arg); } } } diff --git a/lib/PHPCfg/Printer/GraphViz.php b/lib/PHPCfg/Printer/GraphViz.php index 2b89ab2..d9546dc 100644 --- a/lib/PHPCfg/Printer/GraphViz.php +++ b/lib/PHPCfg/Printer/GraphViz.php @@ -40,9 +40,9 @@ public function printScript(Script $script) { $i = 0; $graph = $this->createGraph(); - $this->printFuncWithHeader($script->main, $graph, 'func_'.++$i.'_'); + $this->printFuncWithHeader($script->main, $graph, 'func_' . ++$i . '_'); foreach ($script->functions as $func) { - $this->printFuncWithHeader($func, $graph, 'func_'.++$i.'_'); + $this->printFuncWithHeader($func, $graph, 'func_' . ++$i . '_'); } return $graph; @@ -60,7 +60,7 @@ public function printVars(Func $func) { $graph = Graph::create('vars'); foreach ($this->options['graph'] as $name => $value) { - $setter = 'set'.$name; + $setter = 'set' . $name; $graph->{$setter}($value); } $rendered = $this->render($func->cfg); @@ -71,7 +71,7 @@ public function printVars(Func $func) } $id = $rendered['varIds'][$var]; $output = $this->renderOperand($var); - $nodes[$var] = $this->createNode('var_'.$id, $output); + $nodes[$var] = $this->createNode('var_' . $id, $output); $graph->setNode($nodes[$var]); } foreach ($rendered['varIds'] as $var) { @@ -88,9 +88,9 @@ public function printVars(Func $func) } $edge = $this->createEdge($nodes[$v], $nodes[$var]); if ($b) { - $edge->setlabel('Block<'.$rendered['blockIds'][$b].'>'.$write->getType().':'.$varName); + $edge->setlabel('Block<' . $rendered['blockIds'][$b] . '>' . $write->getType() . ':' . $varName); } else { - $edge->setlabel($write->getType().':'.$varName); + $edge->setlabel($write->getType() . ':' . $varName); } $graph->link($edge); } @@ -105,7 +105,8 @@ protected function printFuncWithHeader(Func $func, Graph $graph, $prefix) { $name = $func->getScopedName(); $header = $this->createNode( - $prefix.'header', "Function {$name}():" + $prefix . 'header', + "Function {$name}():", ); $graph->setNode($header); @@ -123,9 +124,9 @@ protected function printFuncInto(Func $func, Graph $graph, $prefix) $ops = $rendered['blocks'][$block]; $output = ''; foreach ($ops as $op) { - $output .= $this->indent("\n".$op['label']); + $output .= $this->indent("\n" . $op['label']); } - $nodes[$block] = $this->createNode($prefix.'block_'.$blockId, $output); + $nodes[$block] = $this->createNode($prefix . 'block_' . $blockId, $output); $graph->setNode($nodes[$block]); } @@ -158,7 +159,7 @@ private function createGraph() { $graph = Graph::create('cfg'); foreach ($this->options['graph'] as $name => $value) { - $setter = 'set'.$name; + $setter = 'set' . $name; $graph->{$setter}($value); } @@ -169,7 +170,7 @@ private function createNode($id, $content) { $node = new Node($id, $content); foreach ($this->options['node'] as $name => $value) { - $node->{'set'.$name}($value); + $node->{'set' . $name}($value); } return $node; @@ -179,7 +180,7 @@ private function createEdge(Node $from, Node $to) { $edge = new Edge($from, $to); foreach ($this->options['edge'] as $name => $value) { - $edge->{'set'.$name}($value); + $edge->{'set' . $name}($value); } return $edge; diff --git a/lib/PHPCfg/Printer/Text.php b/lib/PHPCfg/Printer/Text.php index 221b21e..03fb175 100755 --- a/lib/PHPCfg/Printer/Text.php +++ b/lib/PHPCfg/Printer/Text.php @@ -37,16 +37,16 @@ public function printFunc(Func $func) $output = ''; foreach ($rendered['blocks'] as $block) { $ops = $rendered['blocks'][$block]; - $output .= "\nBlock#".$rendered['blockIds'][$block]; + $output .= "\nBlock#" . $rendered['blockIds'][$block]; foreach ($block->parents as $prev) { if ($rendered['blockIds']->contains($prev)) { - $output .= $this->indent("\nParent: Block#".$rendered['blockIds'][$prev]); + $output .= $this->indent("\nParent: Block#" . $rendered['blockIds'][$prev]); } } foreach ($ops as $op) { - $output .= $this->indent("\n".$op['label']); + $output .= $this->indent("\n" . $op['label']); foreach ($op['childBlocks'] as $child) { - $output .= $this->indent("\n".$child['name'].': Block#'.$rendered['blockIds'][$child['block']], 2); + $output .= $this->indent("\n" . $child['name'] . ': Block#' . $rendered['blockIds'][$child['block']], 2); } } $output .= "\n"; @@ -62,16 +62,16 @@ public function printVars(Func $func) foreach ($rendered['varIds'] as $var) { $id = $rendered['varIds'][$var]; $output .= "\nVar#{$id}"; - $output .= $this->indent("\n".'WriteOps:'); + $output .= $this->indent("\n" . 'WriteOps:'); foreach ($var->ops as $writeOp) { if ($rendered['ops']->contains($writeOp)) { - $output .= $this->indent("\n".$rendered['ops'][$writeOp]['label'], 2); + $output .= $this->indent("\n" . $rendered['ops'][$writeOp]['label'], 2); } } - $output .= $this->indent("\n".'ReadOps:'); + $output .= $this->indent("\n" . 'ReadOps:'); foreach ($var->usages as $usage) { if ($rendered['ops']->contains($usage)) { - $output .= $this->indent("\n".$rendered['ops'][$usage]['label'], 2); + $output .= $this->indent("\n" . $rendered['ops'][$usage]['label'], 2); } } $output .= "\n"; diff --git a/lib/PHPCfg/Traverser.php b/lib/PHPCfg/Traverser.php index 4ecfe21..31a6331 100755 --- a/lib/PHPCfg/Traverser.php +++ b/lib/PHPCfg/Traverser.php @@ -84,7 +84,7 @@ private function traverseBlock(Block $block, ?Block $prior = null) // Revisit the ith block again --$j; } elseif (null !== $result) { - throw new \RuntimeException('Unknown return from visitor: '.gettype($result)); + throw new \RuntimeException('Unknown return from visitor: ' . gettype($result)); } } if (is_array($op->{$subblock})) { @@ -103,7 +103,7 @@ private function traverseBlock(Block $block, ?Block $prior = null) // Revisit the ith node again --$i; } elseif (null !== $result && $result !== $op) { - throw new \RuntimeException('Unknown return from visitor: '.gettype($result)); + throw new \RuntimeException('Unknown return from visitor: ' . gettype($result)); } } $block->children = $children; diff --git a/lib/PHPCfg/Visitor.php b/lib/PHPCfg/Visitor.php index 728bbc8..d19af3d 100755 --- a/lib/PHPCfg/Visitor.php +++ b/lib/PHPCfg/Visitor.php @@ -13,9 +13,9 @@ interface Visitor { - const REMOVE_OP = -1; + public const REMOVE_OP = -1; - const REMOVE_BLOCK = -2; + public const REMOVE_BLOCK = -2; public function enterScript(Script $script); diff --git a/lib/PHPCfg/Visitor/DebugVisitor.php b/lib/PHPCfg/Visitor/DebugVisitor.php index a2735c8..90ef2d2 100644 --- a/lib/PHPCfg/Visitor/DebugVisitor.php +++ b/lib/PHPCfg/Visitor/DebugVisitor.php @@ -34,38 +34,38 @@ public function leaveScript(Script $script) public function enterBlock(Block $block, ?Block $prior = null) { - echo 'Enter Block #'.$this->getBlockId($block)."\n"; + echo 'Enter Block #' . $this->getBlockId($block) . "\n"; } public function enterOp(Op $op, Block $block) { - echo 'Enter Op '.$op->getType()."\n"; + echo 'Enter Op ' . $op->getType() . "\n"; } public function leaveOp(Op $op, Block $block) { - echo 'Leave Op '.$op->getType()."\n"; + echo 'Leave Op ' . $op->getType() . "\n"; } public function leaveBlock(Block $block, ?Block $prior = null) { - echo 'Leave Block #'.$this->getBlockId($block)."\n"; + echo 'Leave Block #' . $this->getBlockId($block) . "\n"; } public function skipBlock(Block $block, ?Block $prior = null) { - echo 'Skip Block #'.$this->getBlockId($block)."\n"; + echo 'Skip Block #' . $this->getBlockId($block) . "\n"; } public function enterFunc(Func $func) { $this->blocks = new \SplObjectStorage(); - echo 'Enter Func '.$func->getScopedName()."\n"; + echo 'Enter Func ' . $func->getScopedName() . "\n"; } public function leaveFunc(Func $func) { - echo 'Leave Func '.$func->getScopedName()."\n"; + echo 'Leave Func ' . $func->getScopedName() . "\n"; $this->blocks = null; } diff --git a/test/PHPCfg/ParserTest.php b/test/PHPCfg/ParserTest.php index 19ddc1f..e0e98bc 100755 --- a/test/PHPCfg/ParserTest.php +++ b/test/PHPCfg/ParserTest.php @@ -37,15 +37,17 @@ public function testParseAndDump($code, $expectedDump) $this->assertEquals( $this->canonicalize($expectedDump), - $this->canonicalize($result) + $this->canonicalize($result), ); } public function provideTestParseAndDump() { - $dir = __DIR__.'/../code'; + $dir = __DIR__ . '/../code'; $iter = new \RecursiveIteratorIterator( - new \RecursiveDirectoryIterator($dir), \RecursiveIteratorIterator::LEAVES_ONLY); + new \RecursiveDirectoryIterator($dir), + \RecursiveIteratorIterator::LEAVES_ONLY, + ); foreach ($iter as $file) { if (! $file->isFile()) {