Skip to content

[detector-report] DuplicateFunctionDetector #586

Description

@jessegall

Detector: DuplicateFunctionDetector

Report (why the flagged code is CORRECT and the detector is wrong):
BlueprintCanvas::picking and ConsolePlane::stepped are fluent setters on two different compositions, each writing the same two fields of its own State class (BlueprintCanvasState and ConsolePlaneState). A composition's setter writes through to its own state by project rule, so two components that accept the same inputs have two setters of the same shape; BlueprintCanvas then hands both values on to the ConsolePlane it composes. There is no shared behaviour to extract.

Cleanest design the reporter can conceive:
Each composition declares its own fluent setter writing its own State, and the outer one passes the values to the inner one in compose, which is the flagged code.

⚖️ 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/View/Scenes/Run/Components/Blueprint/BlueprintCanvas.php:67-76

Code (src/View/Scenes/Run/Components/Blueprint/BlueprintCanvas.php:67-76):

  64          return $this;
  65      }
  6667      /**
→ 68       * @param  Closure(string): mixed  $picking
→ 69       */70      public function picking(StateRef $step, Closure $picking): static71      {
→ 72          $this->state->step = $step;
→ 73          $this->state->picking = $picking;
→ 7475          return $this;
→ 76      }
  77  
  78      # ----------[ Factories ]----------
  79  

Where: src/View/Scenes/Run/Components/Console/ConsolePlane.php:42-51

Code (src/View/Scenes/Run/Components/Console/ConsolePlane.php:42-51):

  39          return $plane;
  40      }
  4142      /**
→ 43       * @param  Closure(string): mixed  $picking
→ 44       */45      public function stepped(StateRef $step, Closure $picking): static46      {
→ 47          $this->state->step = $step;
→ 48          $this->state->picking = $picking;
→ 4950          return $this;
→ 51      }
  52  
  53      /**
  54       * @param  array<string, Blueprint>  $blueprints

Filed via commandments report from a consumer project.

Activity

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

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions