Skip to content

gate-3 caller-identity-ignored synthesises a body for BODILESS interface declarations, defeating its own interface-skip #291

Open

Description

@rubenvdlinde

Summary

gate-3's caller-identity-ignored rule flags interface method declarations, which have no body at all. The rule's own comment says it means to skip them:

# A legitimate ≥3-line method that accepts a caller-identity
# param and never references it is a stub. Skip very short
# methods (likely abstract/interface forwards).
[ "${_body_lines}" -lt 4 ] && continue

The skip never fires for an interface, because the body extraction has nothing to stop at.

Mechanism

_body=$(awk -v start="${_line_no}" 'NR >= start { print; if (NR > start && /^    \}/) exit }' "$f")

The terminator is a line matching ^ \}. An interface file contains no such line — its methods end in ; and the interface's own closing brace is at column 0. So for any interface method the awk runs from the declaration to EOF and calls the result "the body".

Then:

_count=$(echo "${_body}" | grep -cF "${_param}")
if [ "${_count}" -lt 2 ]; then   # signature line counts as 1

The synthesised body contains the parameter exactly once (the signature), so every interface method declaring $uid/$callerUid/$userId/$caller is reported — provided it sits ≥4 lines from EOF, which is the common case.

Measured on pipelinq

lib/Service/Cti/CtiAdapterInterface.php:78

public function subscribeToPresence(string $userId, string $extension): void;
  • File is 92 lines; the declaration is at line 78.
  • grep -nE '^ \}' lib/Service/Cti/CtiAdapterInterface.php → no matches.
  • Simulated extraction from line 78 → 15 lines, i.e. _body_lines=15, comfortably past the < 4 skip.
  • Reported as rule=caller-identity-ignored param=$userId.

There is no correct fix available to the app author. The parameter is part of the interface contract and is genuinely used by an implementor (RingCentralAdapter::subscribeToPresence references $userId); a declaration cannot "reference" anything. The only ways to silence it are to delete the parameter (breaking the contract) or to move the method away from the end of the file, which is obviously not a fix.

Suggested fix

Skip declarations that terminate in ; before the brace search, e.g. treat a signature line ending in ; as bodiless and continue. Alternatively make the terminator brace-matched rather than a fixed-indent regex, which would also make the rule robust against non-4-space indentation.

A regression test would be an interface file whose last method declares $userId, asserting zero findings.

Related

Same family as the gate-50 literal-app-id blind spot and the gate-9 [^)]* admin rule: a heuristic whose scope silently mismatches the construct it is judging. This one fails toward a false positive, so it is visible — but it is unclosable by the app, which is the shape #269 was created to avoid.

Activity

  1. rubenvdlinde commented on Aug 10, 2026

    @rubenvdlinde
    ContributorAuthor

    Fixed, and the < 4 skip was never the safety net it was taken for.

    Reproduced exactly: lib/Service/Cti/CtiAdapterInterface.php:78, 92-line file, grep -cE '^ \}' → 0, extraction 15 lines, reported.

    The fix keys on the property that actually distinguishes the two constructs — the signature terminator: ; = declaration, { = body. Checked on the signature region rather than the line, so a multi-line signature is handled too.

    The < 4 skip does not do what its comment says

    Its comment claims it skips "abstract/interface forwards". Measured against the unfixed runner with a two-method interface:

    interface OtherInterface
    {
        public function subscribeToPresence(string $userId, string $extension): void;
    
        public function dial(string $extension): void;
    }

    extraction from the declaration to EOF is exactly 4 lines, so < 4 does not fire and this reports too. The bug was never about being last in the file — only about there being no ^ \} to stop at. That arm is in the suite.

    Not changed: the fixed-indent terminator

    This issue also suggests making the terminator brace-matched. I measured before touching it: across openregister/pipelinq/decidesk/procest, lib/Service + lib/Controller have 0 files closing methods with a tab and 150–240 closing with four spaces. So the fixed indent is not currently mis-firing, and rewriting the extraction would change behaviour well beyond this false positive. Left alone deliberately.

    Measured

    Fleet 7 → 6, and the one removed is exactly this issue's finding:

    pipelinq: lib/Service/Cti/CtiAdapterInterface.php:78 method=subscribeToPresence param=$userId
    

    The remaining 6 were each re-read: all are real class methods with real bodies (AsteriskAdapter/CallVoipAdapter::subscribeToPresence, procest's three transition guards, openregister's DenialFinaliseGuard::check) — i.e. the rule's genuine subject, untouched.

    Verification (4 arms, test_gate_3_bodiless_declaration.sh, driven by the real runner)

    interface declaration → 0 · a real body that ignores $userId → still 1 · a real body that uses it → 0 · short interface → 0. Arms 1 and 4 fail on origin/main.


    Fixed in #329.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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