Skip to content

Consider optional Ray.MediaQuery conformance checks #1

Description

@koriym

Problem

be-framework/psalm-plugin currently focuses on Be Framework runtime mistakes that can be found statically.

For applications that intentionally use Ray.MediaQuery, a small optional check could help catch simple MediaQuery wiring mistakes before runtime, without creating a standalone architecture checker or turning project-specific architecture policy into default Psalm errors.

Proposed scope

Add an opt-in Ray.MediaQuery conformance check profile, initially limited to the smallest useful rules:

BeMissingDbQueryAttribute

When the opt-in profile is enabled, interfaces in configured MediaQuery directories such as:

  • src/Reason/Media/Query
  • src/Reason/Media/Command
  • be/src/Reason/Media/Query
  • be/src/Reason/Media/Command

should declare #[DbQuery] on query/command methods.

BeMissingSqlFile

When a method has #[DbQuery('foo')], the plugin should optionally verify that a matching SQL file exists, e.g.:

  • var/sql/foo.sql

The SQL directory should be configurable.

Non-goals

This issue should not introduce broad architecture enforcement.

Out of scope:

  • banning PDO globally
  • banning Sql* classes by naming convention
  • enforcing BEAR Resource usage patterns
  • inferring whether MediaQueryModule is installed correctly
  • dependency-direction checks; those belong in Deptrac or a project-specific policy
  • creating a standalone CLI checker

Configuration sketch

The checks should be disabled by default and enabled explicitly in psalm.xml, for example:

<pluginClass class="Be\PsalmPlugin\Plugin">
  <mediaQueryConformance enabled="true">
    <mediaDirectories>
      <directory name="src/Reason/Media" />
      <directory name="be/src/Reason/Media" />
    </mediaDirectories>
    <sqlDirectory name="var/sql" />
  </mediaQueryConformance>
</pluginClass>

Exact XML shape can be decided during implementation.

Implementation notes

Follow the existing plugin pattern:

  • add src/Issue/*
  • add src/Handler/*
  • register handlers in src/Plugin.php
  • add invalid/valid fixtures under tests/Fixture
  • extend tests/PluginIntegrationTest.php
  • document issue types and suppression examples in README

Acceptance criteria

  • Checks are opt-in and disabled by default.
  • Psalm reports BeMissingDbQueryAttribute for configured MediaQuery interfaces missing #[DbQuery].
  • Psalm reports BeMissingSqlFile when a configured #[DbQuery('foo')] has no matching SQL file.
  • Valid fixtures remain clean.
  • Standard Psalm suppression/baseline/output mechanisms work unchanged.
  • composer tests passes on PHP 8.3 and 8.4.

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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions