Problem/Motivation

It looks like property hooks (a PHP 8.4 feature) are not supported by coder.

An error occurred during processing; checking has been aborted. The error message was: $stackPtr is not a class member var

The error originated in the Drupal.NamingConventions.ValidVariableName sniff on line 41.

Note that property hooks are also not supported upstream by squizlabs/php_codesniffer, see https://github.com/PHPCSStandards/PHP_CodeSniffer/issues/734

Steps to reproduce

You can reproduce this on the example code at https://www.php.net/manual/en/language.oop5.property-hooks.php

class Example
{
    private bool $modified = false;

    public string $foo = 'default value' {
        get {
            if ($this->modified) {
                return $this->foo . ' (modified)';
            }
            return $this->foo;
        }
        set(string $value) {
            $this->foo = strtolower($value);
            $this->modified = true;
        }
    }
}

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

Issue fork coder-3569083

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

mfb created an issue. See original summary.

mfb’s picture

nickolaj made their first commit to this issue’s fork.

nickolaj’s picture

Status: Active » Needs review

Catch RuntimeException thrown by getMemberProperties() when processing PHP 8.4 property hook variables that are not actual class member declarations.

mondrake’s picture

Priority: Normal » Major

I think this is at least major given that D12 will require PHP 8.5 and therefore use of property hooks as a language feature will be unlocked.

mondrake’s picture

klausi’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests

Thanks, approach makes sense!

Please add a test case so that we cover this exception handling with tests.

claudiu.cristea’s picture

Component: Coder Sniffer » Code

Hooks might contain a return statement. I'm getting also

Code after the RETURN statement on line 32 cannot be executed (Squiz.PHP.NonExecutableCode.Unreachable)

See https://git.drupalcode.org/issue/drupal-3581014/-/jobs/9054715