Skip to content

Reduce per-class file I/O in SchematronCompilerService - #10

Merged
ezkimo merged 1 commit into
mainfrom
issue-4-reduce-per-class-file-io
Oct 16, 2026
Merged

ezkimo merged 1 commit into
mainfrom
issue-4-reduce-per-class-file-io

Conversation

@ezkimo

@ezkimo ezkimo commented Oct 16, 2026

Copy link
Copy Markdown
Owner

Summary

Generating one class runs clearstatcache(), is_dir(), file_exists() and unlink() once per generated rule class, which is wasteful for schemas with many rules. This PR removes that redundant per-class work.

Changes

  • src/Schematron/SchematronCompilerService.php
    • The directory setup (clearstatcache(), is_dir(), mkdir()) now runs once per compile() call instead of once per generated class.
    • Removed the per-class clearstatcache().
    • Removed the redundant file_exists() + unlink() pair before file_put_contents() — overwriting already works.
  • tests/Schematron/SchematronCompilerServiceTest.php (new) and tests/data/schematron/rules.sch (new fixture)
    • Verify that the output directory is created when missing.
    • Verify generated class files contain the expected validate(), message() and context() code.
    • Verify an existing rule-class file is overwritten.
    • Verify that a non-creatable output path throws a RuntimeException.

Testing

  • Full PHPUnit suite passes (composer test); Psalm reports no errors.
  • An end-to-end CLI smoke run confirmed class generation and overwrite-on-second-run still work.

@ezkimo
ezkimo merged commit 7809be3 into main Oct 16, 2026
1 check passed
@ezkimo ezkimo self-assigned this Oct 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant