Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use PHP_CodeSniffer\Files\File;
use PHP_CodeSniffer\Sniffs\AbstractVariableSniff;
use RuntimeException;

use function assert;
use function ltrim;
Expand Down Expand Up @@ -110,7 +111,13 @@ protected function processMemberVar(File $phpcsFile, $stackPtr): void
$tokens = $phpcsFile->getTokens();

$varName = ltrim($tokens[$stackPtr]['content'], '$');
$memberProps = $phpcsFile->getMemberProperties($stackPtr);

try {
$memberProps = $phpcsFile->getMemberProperties($stackPtr);
} catch (RuntimeException) {
return;
}

if ($memberProps === []) {
// Couldn't get any info about this variable, which
// generally means it is invalid or possibly has a parse
Expand Down
22 changes: 22 additions & 0 deletions tests/Sniffs/NamingConventions/data/ValidVariableNameSniffTest.inc
Original file line number Diff line number Diff line change
Expand Up @@ -146,3 +146,25 @@ $var_name . $var_name;
fn($_, $__, $_x) => true;

$var = Potato::new();

class PropertyHookClass
{
private string|null $resolved = null;
private bool $isResolved = false;

public function __construct(
private readonly Closure $provider,
) {
}

public string|null $hooked {
get {
if (! $this->isResolved) {
$this->resolved = ($this->provider)();
$this->isResolved = true;
}

return $this->resolved;
}
}
}
Loading