php-mode icon indicating copy to clipboard operation
php-mode copied to clipboard

PSR2 indentation inside a method

Open ahonnecke opened this issue 7 years ago • 5 comments

    if ($productData->getVendorId()) {
        $vendorVariant->setVendor(
            $this->entityManager
            ->getReference(Vendor::class, $productData->getVendorId())
        );
    }

Should be:

    if ($productData->getVendorId()) {
        $vendorVariant->setVendor(
            $this->entityManager
                ->getReference(Vendor::class, $productData->getVendorId())
        );
    }

ahonnecke avatar Sep 01 '17 14:09 ahonnecke

@ahonnecke There is now a branch called fix-psr2-indent-inside-methods. Could you please do me the favor of fetching the latest code and testing out that change? I do not have a large codebase on hand that is meant to adhere to the PSR2 style, and so I do not want to merge that change into master without first making sure it doesn't break anything else---God knows that wouldn't be the first time that happened in a patch fixing an indentation problem, heh.

If everything seems to work ok with the version on that branch then I will further document the patch and merge it. But again, I would greatly appreciate you (or anyone) first testing it on a large set of PHP code meant to adhere to PSR2, to see if anything else is now incorrectly indented as a result.

Thanks for the bug report and thank you in advanced for any help with testing.

ejmr avatar Sep 02 '17 04:09 ejmr

Thanks! It looks like it fixed the code I pasted, but had the side effect of indenting other code that should not be indented.

protected function resetEntityManager()
    {
        $this->entityManager = $this->getEntityManager()->create(
            $this->getEntityManager()->getConnection(),
                $this->getEntityManager()->getConfiguration()
        );
    }

Should be:

protected function resetEntityManager()
    {
        $this->entityManager = $this->getEntityManager()->create(
            $this->getEntityManager()->getConnection(),
            $this->getEntityManager()->getConfiguration()
        );
    }

ahonnecke avatar Sep 04 '17 17:09 ahonnecke

...but had the side effect of indenting other code that should not be indented.

Yeah, that's exactly what I was worried would happen, heh. Thank you for testing it and posting the new code that now does not indent correctly; that will help me figure out a better solution. I am sorry this is causing you problems and apologize that I (probably) will not have a quick fix, and will want your help testing again, but thank you again for both being patient and providing very helpful examples I can use for testing purposes.

ejmr avatar Sep 05 '17 00:09 ejmr

Absolutely regarding helping. No worries :) I'm happy to help any way I can my lisp is pretty rusty but if there's a spot where it would be helpful for me to iterate on something I'd be happy to give it a shot.

ahonnecke avatar Sep 05 '17 14:09 ahonnecke

Just to provide a simple update, I am going to attempt to fix this simultaneously along with the recently reported #371 issue, since there is a reasonable chance they are related in one way or another.

ejmr avatar Sep 06 '17 22:09 ejmr

Resolved in https://github.com/emacs-php/php-mode/pull/703

zonuexe avatar Sep 17 '22 19:09 zonuexe