Skip to content

[detector-report] ParamResolvedFromParamDetector #523

Description

@jessegall

Detector: ParamResolvedFromParamDetector

Report (why the flagged code is CORRECT and the detector is wrong):
Document is the browser a client script runs against, not a container the caller indexes into. JsonView::node(Document, string tag, string class) CREATES an element rather than resolving a key, and Template::referred(Document, string named) is a resolver that turns a template name into its tree or throws UnknownTemplate. In both, every caller already holds the Document and passes it to reach the DOM at all, so there is no resolved object for a caller to hand over instead.

Cleanest design the reporter can conceive:
A client script takes the Document it runs against as an ordinary collaborator, exactly as commandments-client-side-takes-no-node prescribes, and a name-to-thing lookup with a named failure lives in one resolver method that owns the refusal. That is what these two already are.

⚖️ Maintainer litmus: a valid detector-report needs the flagged code to ALREADY BE the
cleanest design. If the design above differs from the flagged code at all, THAT design is
the owed fix — close this report; the fix is still owed.

Where: src/Ui/Client/Scripts/JsonView.php:119

Code (src/Ui/Client/Scripts/JsonView.php:119):

  116          return $span;
  117      }
  118119      private function node(Document $page, string $tag, string $className): Element
  120      {
  121          $made = $page->createElement($tag);
  122  
  123          $made->className = $className;
  124  
  125          return $made;
  126      }
  127  
  128      /**
  129       * Whether a value has an inside worth opening. Nothing empty does.
  130       */
  131      private function holds(mixed $value): bool
  132      {
  133          return is_array($value) && count($value) > 0;
  134      }
  135  
  136      private function textOf(mixed $value): string
  137      {
  138          if (is_array($value))
  139          {
  140              return count($value) === 0 ? self::EMPTY : '['.count($value).' items]';
  141          }
  142  
  143          if (is_null($value))

Where: src/Ui/Client/Scripts/Template.php:376

Code (src/Ui/Client/Scripts/Template.php:376):

  373       * The tree a name refers to. A name nothing resolves is a missing template, and it is better
  374       * reported here than drawn as nothing.
  375       */
→ 376      private function referred(Document $page, string $named): Tree
  377      {
  378          $tree = $page->templateTree($named);
  379  
  380          if ($tree === null)
  381          {
  382              throw new UnknownTemplate('['.$named.'] is not a template this page was given.');
  383          }
  384  
  385          return $tree;
  386      }
  387  }

Filed via commandments report from a consumer project.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions