goaop / framework

:gem: Go! AOP PHP - modern aspect-oriented framework for the new level of software development
go.aopphp.com
MIT License
1.66k stars 163 forks source link

SelfValueTransformer breaks Code in PHP 7.4 #469

Closed AnnaDamm closed 3 years ago

AnnaDamm commented 3 years ago

Given the input code:

<?php

declare(strict_types=1);

namespace Common\Mvc\Router\Http;

final class Environment
{
    public static function foo(): self {
        return new self();
    }
}

The SelfValueTransformer outputs this code:

<?php

declare(strict_types=1);

namespace Common\Mvc\Router\Http;

final class Environment
{
    public static function\Common\Mvc\Router\Http\Environmentfoo(): self \Common\Mvc\Router\Http\Environment
        return new self();
    }
}

It replaces seemingly random places in the code. In the above example it is pretty much random that the name is actually next to the "self". If i had other code above (like an if statement), it would replace something else.

I have found that the the startTokenPos on nodes withing $replacedNodes does not actually contain the position within $metadata->tokenStream. So the token that is replaced is random indeed.

AnnaDamm commented 3 years ago

Update: Okay I suppose it is fixed within the newer reflection-parser version in dev-master. But with that version I cannot use nullable return types :-(

lisachenko commented 3 years ago

Hello! Initial fail was indeed related to changes inside PhpParser and reflection-parser libraries. This was fixed already, so I can guess that this issue can be closed.

Sorry for late reply, because I wasn't able to dedicate my time for OSS project previously, thus very limited support, but if you want - you can contribute by sending a PR for missing functionality.