doctrine / orm

Doctrine Object Relational Mapper (ORM)
https://www.doctrine-project.org/projects/orm.html
MIT License
9.86k stars 2.5k forks source link

feat(ci): implement automated syntax and static analysers for code samples in docs #11495

Open SamMousa opened 2 weeks ago

SamMousa commented 2 weeks ago

This implements what was discussed in https://github.com/doctrine/orm/issues/11494.

It works roughly as follows:

  1. Iterate over all .rst files in the docs/ folder.
  2. For each of them look for a string containing whitespace and <?php.
  3. Extract the block by looking for the indentation from 2 to end.
  4. Check the content of each block against a list of ignored md5 hashes (think if this as a baseline for blocks that are too broken for PHPStan to be able to ignore them).
  5. Write each block to a file.
  6. Analyse the written files using PHPStan.

Locally you can improve existing blocks by looking for issues in the baseline. Alternatively you can edit the docs/extract.php and remove hashes from the $badBlocks array, this will lead to new errors for you to solve. Extract blocks locally by doing php docs/extract.php docs/extracted_blocks. Then run vendor/bin/phpstan -b phpstan-docs.neon.

Of course, before executing anything locally, read the source of docs/extract.php.

SamMousa commented 2 weeks ago

I guess this requires a bit more massaging:

Incremental examples

When looking at the getting started guide, an implementation of a Bug class is iterated over and extended several times. This is an issue for automatic analysis since we never have a proper full implementation of the Bug class.

One solution that is simple is to always number classes and reference the version explicitly. So we know if we're using Bug3. We then also need to make sure that we properly repeat code instead of using shorthands like:

    class Bug
    {
        // ... (previous code)

This is something I cannot decide on my own being new to the project. I'd love to hear what you think on how to standardize code samples that get iterated over in guides.

greg0ire commented 5 days ago

I think we should:

  1. Migrate doctrine/doctrine-website to phpDocumentor/guides rather than doctrine/rst-parser, which does not support literalinclude, at least not in a version that is released
  2. Migrate our docs to literalinclude

It should be way more robust.

If you want to help with that, please join us at https://app.slack.com/client/TA33F5Y6L/CERGRHPGD