Skip to content

False positive: Unreachable statement #2835

@dereuromark

Description

@dereuromark

Bug report

phpstan 0.12 latest

Code snippet that reproduces the problem

	protected function propertyInUse(array $tokens, int $closeTagIndex, string $variable): bool {
		/** @var string $property */
		$property = substr($variable, 1);

		$i = $closeTagIndex + 1;
		while (isset($tokens[$i])) {
			if ($tokens[$i]['code'] !== T_VARIABLE || $tokens[$i]['content'] !== '$this') {
				$i++;
				continue;
			}
			$i++;
			if ($tokens[$i]['code'] !== T_OBJECT_OPERATOR) {
				$i++;
				continue;
			}
			$i++;
			$token = $tokens[$i];
			if ($token['code'] !== T_STRING || $token['content'] !== $property) {
				$i++;
				continue;
			}
			$i++; // 520
			if ($tokens[$i]['code'] !== T_OBJECT_OPERATOR) {
				$i++;
				continue;
			}

			return true;
		}

		return false;
	}

Expected output

  520    Unreachable statement - code above always terminates.  

This is not true.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions