Skip to content

Format-preserving bug for multipes NodeVisitors #400

@TomasVotruba

Description

@TomasVotruba

With format-perserving printer [#344] I came across weird bug.

I have 2 visitor modifying the code:

This is error output from Travis Report:

  • I make property private - doesn't work 👎
  • I add argument to constructor - works 👍
  • I add assignment in constuctor method - 👎
  • declare (strict_types=1);\n is added instead of it
-    private $property;\n
+    public $property;\n
     /**\n
      * @var DateTimeInterface\n
      */\n
-    private $otherProperty;\n
+    public $otherProperty;\n
     public function __construct(stdClass $property, DateTimeInterface $otherProperty)\n
     {\n
-        $this->property = $property;\n
-        $this->otherProperty = $otherProperty;\n
+        declare (strict_types=1);\n
+        declare (strict_types=1);\n
     }\n
 }\n
return $this->codeStyledPrinter->printToString($newStmts, $oldStmts, $oldTokens);

This would be understandable from some point, but...

But when I switch first 2 arguments, this NodeVisitor works but the other doesn't.

return $this->codeStyledPrinter->printToString($oldStmts, $newStmts, $oldTokens);

In this case, afterTraverse() isn't taken into account.

 class ClassWithNamedService extends Controller\n
 {\n
-    /**\n
-     * @var stdClass\n
-     */\n
-    private $stdClass;\n
-    public function __construct(stdClass $stdClass)\n
-    {\n
-        $this->stdClass = $stdClass;\n
-    }\n
     public function render()\n
     {\n
         $this->stdClass->render();\n
     }\n
 }\n

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions