Skip to content

[detector-report] KeyedLookupEnvyDetector #591

Description

@jessegall

Detector: KeyedLookupEnvyDetector

Report (why the flagged code is CORRECT and the detector is wrong):
OfferedModels resolves the provider's AgentConfiguration through the AgentConfigurations registry's get() and asks that resolved configuration for its models; the behaviour already lives on the data the key resolves to, and AgentRecord is an Eloquent model that cannot hold the container-built registry.

Cleanest design the reporter can conceive:
The registry resolves the configuration by the provider enum and AgentConfiguration::models(credentialStore) answers; that is the current 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/Orchestration/OfferedModels.php:16

Code (src/Orchestration/OfferedModels.php:16):

  13      /**
  14       * @return array<string, string>
  15       */16      public function of(AgentRecord $agent): array
  17      {
  18          if (! $agent->isBound())
  19          {
  20              return [];
  21          }
  22  
  23          return $this->configurations->get($agent->provider)->models($agent->boundLogin()->credentialStore());
  24      }
  25  }

Where: src/Orchestration/AgentConfigurations.php:11

Code (src/Orchestration/AgentConfigurations.php:11):

   8  /**
   9   * @extends Registry<AgentConfiguration>
  10   */11  final class AgentConfigurations extends Registry
  12  {
  13      protected function validate(mixed $item): void
  14      {
  15          if (! $item instanceof AgentConfiguration)
  16          {
  17              throw UnknownAgentConfiguration::notAConfiguration(get_debug_type($item));
  18          }
  19      }
  20  }

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