Skip to content

[Feature]: Report mode: collect violations instead of throwing #94

Closed

Description

@fdaviddpt

Proposed Feature / Syntax

A config option to collect violations instead of throwing:

  • 'on_violation' => 'throw' (default, today's behaviour)
  • 'on_violation' => 'report': no exception; each violation is recorded once (file, line, function, parameter or return, expected type, given value) and written to a JSON file at shutdown.

Motivation / Use Case

Adopting TypePHP on an existing codebase. The first run surfaces many wrong docblocks, and today each one throws. When a violation sits on the bootstrap path (code that runs before any test), it stops the whole test suite, so we found them one at a time: four CI runs for four violations. Violations inside a test also hide every later one in the same call path.

With a report mode, the first run gives the full list. Once it is cleaned up, we switch to throw and keep it as a gate.

Code Example

// typephp.php
return [
    'on_violation' => 'report',
    'report_file' => __DIR__ . '/var/typephp-report.json',
];
[
  {
    "file": "src/Command/GetEntities.php",
    "line": 133,
    "function": "App\\Command\\GetEntities::getOption",
    "contract": "param $default",
    "expected": "array<string, mixed>",
    "given": "bool (false)"
  }
]

Activity

  1. rcalicdan commented on Oct 3, 2026

    @rcalicdan
    Member

    @fdaviddpt Thank you this is a great idea, This is also a good feature for the next minor release so hold your buckle.. I won't be doing this in patch release but this feature will and the other request will be prioritized in the next v0.11.0 release..

  2. self-assigned this
    on Oct 3, 2026
  3. fdaviddpt commented on Oct 3, 2026

    @fdaviddpt
    Author

    Thanks a lot, looking forward to v0.11.0. Two details from our setup that may be worth designing in from the start:

    • Parallel runs: with ParaTest, each worker would write the same report_file. One file per worker (e.g. suffixed with TEST_TOKEN), or a merge at the end, would avoid lost or interleaved entries.
    • Exit status: an option to still fail the process at shutdown when the report is not empty (e.g. 'fail_on_report' => true) would let CI keep a gate without going back to throw.
  4. rcalicdan commented on Oct 3, 2026

    @rcalicdan
    Member

    Thank you, for the exit status addition.. This will come in handy..

  5. linked a pull request that will close this issueNext minor released #100on Oct 3, 2026
  6. rcalicdan commented on Oct 4, 2026

    @rcalicdan
    Member

    @fdaviddpt hi, I have fixed all of the bugs and also implemented all of the requested feature, I'm just adding more features and after this will be releasing the new minor 0.11 release.. In the meantime you can checkout #100 PR and use the branch in your composer dependency to see if everything is set..

  7. rcalicdan commented on Oct 4, 2026

    @rcalicdan
    Member

    Hello I had now release the minor version v0.11.0 and resolve all your submitted issues.. If you have more problem don't hesitate to submit more issues..

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

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions