documentation-developer icon indicating copy to clipboard operation
documentation-developer copied to clipboard

[POC] Added PHPStan to verify code samples

Open mnocon opened this issue 1 year ago • 1 comments

This PR adds PHPstan to verify code samples.

This is done only for ActivityLog for now, to see if it's useful.

The code is broken on purpose in https://github.com/ibexa/documentation-developer/commit/42998c6887c5a3e07313ff81b324ac2ea3cdc2d1

It requires two things from us:

  1. All code samples must be stored in code_samples and included from the doc - we cannot use ```php blocks, because they won't be validated
  2. Examples must be complete (they cannot reference classes that do not exist or are left as an exercise to the reader)

which I think we can live with

mnocon avatar Apr 24 '24 19:04 mnocon

2. Examples must be complete (they cannot reference classes that do not exist or are left as an exercise to the reader)

This can be circumvented by using stubs, which are basically small PHP code declarations. They also overwrite any existing declarations (that is their primary use), which is useful if you cannot modify 3rd party code, but still want to have PHPStan compliant annotations.

Steveb-p avatar Apr 24 '24 23:04 Steveb-p